二次联通门 : cogs 998. [東方S2] 帕秋莉·诺蕾姬
交上去后发现自己没上榜
就想着加点黑科技
把循环展开一下
结果WA了。。
万恶的姆Q
/* cogs 998. [東方S2] 帕秋莉·诺蕾姬 模拟 预先处理出原序列的总和 枚举要交换的两个位置, 加加减减判一判就好了 */ #include <cstdio> #include <cstring> #define _L 26 #define Online #define Max 200000 char line[Max]; int Mod; long long number[Max], key[Max]; long long Total; int main (int argc, char *argv[]) { #ifdef Online freopen ("patchouli.in", "r", stdin); freopen ("patchouli.out", "w", stdout); #endif scanf ("%s", line); scanf ("%d", &Mod); int Len = strlen (line); Total = line[Len - 1] - 'A'; for (register int i = 0; i < Len; i ++) number[i] = line[Len - i - 1] - 'A'; key[0] = 1; for (register int i = 1; i < Len; key[i] = (key[i - 1] * _L) % Mod, Total += key[i] * number[i], i ++); if (Total % Mod == 0) { printf ("0 0"); return 0; } long long res; for (register int i = Len - 1, j; i >= 0; i --) for (j = i - 1; j >= 0; j --) { res = Total - key[i] * number[i] - key[j] * number[j]; res += key[i] * number[j] + key[j] * number[i]; if (res % Mod == 0) { printf ("%d %d", Len - i, Len - j); return 0; } } printf ("-1 -1"); return 0; }