Advertisement
ec1117

Untitled

Jan 7th, 2021
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1.  
  2. int n,m, bes = MOD;
  3. string t[300000], ans[300000], tmp[300000];
  4. string z = "ACGT";
  5.  
  6. string gen(vi v, int m) {
  7.     string Z;
  8.     F0R(i,m) Z += z[v[i&1]];
  9.     return Z;
  10. }
  11.  
  12. int dif(string a, string b) {
  13.     int d = 0;
  14.     F0R(i,sz(a)) if (a[i] != b[i]) d ++;
  15.     return d;
  16. }
  17.  
  18. void tri(int a, int b) {
  19.     vi v[2];
  20.     v[0] = {a,b};
  21.     F0R(i,4) if (find(all(v[0]),i) == v[0].end()) v[1].pb(i);
  22.    
  23.     int cur = 0;
  24.     F0R(i,n) {
  25.         int x = dif(gen(v[i&1],m),t[i]);
  26.         auto V = v[i&1]; swap(V[0],V[1]);
  27.         int y = dif(gen(V,m),t[i]);
  28.         if (x < y) {
  29.             cur += x;
  30.             tmp[i] = gen(v[i&1],m);
  31.         } else {
  32.             cur += y;
  33.             tmp[i] = gen(V,m);
  34.         }
  35.     }
  36.    
  37.     if (cur < bes) {
  38.         bes = cur;
  39.         F0R(i,n) ans[i] = tmp[i];
  40.     }
  41. }
  42.  
  43. void tri2(int a, int b) {
  44.     vi v[2];
  45.     v[0] = {a,b};
  46.     F0R(i,4) if (find(all(v[0]),i) == v[0].end()) v[1].pb(i);
  47.    
  48.     int cur = 0;
  49.     F0R(i,m) {
  50.         string tt; F0R(j,n) tt += t[j][i];
  51.         int x = dif(gen(v[i&1],n),tt);
  52.         auto V = v[i&1]; swap(V[0],V[1]);
  53.         int y = dif(gen(V,n),tt);
  54.         if (x < y) {
  55.             cur += x;
  56.             string zz = gen(v[i&1],n);
  57.             F0R(j,n) tmp[j][i] = zz[j];
  58.         } else {
  59.             cur += y;
  60.             string zz = gen(V,n);
  61.             F0R(j,n) tmp[j][i] = zz[j];
  62.         }
  63.     }
  64.     /*pr("AH",v[0],cur);
  65.     F0R(i,n) pr(tmp[i]);
  66.     pr("");*/
  67.    
  68.     if (cur < bes) {
  69.         bes = cur;
  70.         F0R(i,n) ans[i] = tmp[i];
  71.     }
  72. }
  73.  
  74. int main() {
  75.     // you should actually read the stuff at the bottom
  76.     setIO(); re(n,m);
  77.     F0R(i,n) re(t[i]);
  78.     F0R(i,4) FOR(j,i+1,4) {
  79.         tri(i,j);
  80.         tri2(i,j);
  81.     }
  82.     F0R(i,n) pr(ans[i]);
  83.     // pr(bes);
  84.     // you should actually read the stuff at the bottom
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement