cf round 658 C2 貪心+亂搞 46ms
阿新 • • 發佈:2020-07-25
1 #include<stdio.h> 2 3 char s[100005]; 4 char s1[100005]; 5 char s3[100005]; 6 int st[500005], tp; 7 8 int main() 9 { 10 int t; 11 scanf("%d",&t); 12 while(t--) 13 { 14 int n; 15 scanf("%d",&n); 16 scanf("%s",s); 17 scanf("%s",s1); 18 for(int i = 0; i < n; i++) s[i] -= '0',s1[i] -= '0'; 19 s[n] = s1[n] = s3[n] = 0; 20 int cnt = 0; 21 do 22 { 23 tp = 0; 24 st[++tp] = n-cnt; 25 for(int i = 0; i < n; i++) s3[i] = ((i<n-cnt)?(s[i]^1):s[i]); 26 for(int i = 0; i < (n-cnt)/2; i++) s3[i] ^= s3[n-cnt-i-1] ^= s3[i] ^= s3[n-cnt-i-1]; 27 for(int i = 0; i < n; i++) 28 { 29 if(s3[i]^s1[i]) 30 { 31 int j = i+1; 32 while(s3[j]^s1[j] && s3[j] == s3[i]) j++; 33 st[++tp] = j;34 if(!i) {i=j-1;continue;} 35 st[++tp] = j-i; 36 st[++tp] = j; 37 i = j-1; 38 } 39 } 40 cnt = (cnt * cnt + cnt+1) % n; 41 }while(tp > 2*n); 42 printf("%d",tp); 43 for(int i = 1; i <= tp; i++) printf(" %d%s",st[i],i==tp?"\n":""); 44 if(!tp) puts(""); 45 } 46 return 0; 47 }