fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long int;
  4. #define inf 1000000000000000LL
  5. #define mod 1000000007LL
  6. #define FOR(i,a,b) for(int i = a; i < b; i++)
  7. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  8. void solve() {
  9. uniform_int_distribution <ll> dist(1, 1000000000LL);
  10. ll n,m,k;
  11. cin >> n >> m >> k;
  12. vector <string> l1(n);
  13. vector <ll> val(n);
  14. for (int i = 0; i < n; i++){
  15. val[i] = dist(rng);
  16. }
  17. for (int i = 0; i < n; i++) cin >> l1[i];
  18. auto num = [](char a){
  19. if (a == 'A'){
  20. return 0;
  21. }
  22. if (a == 'T'){
  23. return 1;
  24. }
  25. if (a == 'G'){
  26. return 2;
  27. }
  28. return 3;
  29. };
  30. vector <vector <__int128_t>> cnt(m, vector <__int128_t>(4, 0));
  31. for (int i =0; i < n; i++){
  32. for (int j= 0; j < m; j++){
  33. cnt[j][num(l1[i][j])] += val[i];
  34. }
  35. }
  36. __int128_t v = 0;
  37. __int128_t k2 = k;
  38. for (int i = 0; i < n; i++){
  39. v += val[i];
  40. }
  41. for (int i = 0; i < n; i++){
  42. __int128_t ves = 0;
  43. for (int j = 0; j < m; j++){
  44. for (int x = 0; x < 4; x++){
  45. if (x != num(l1[i][j])){
  46. ves += cnt[j][x];
  47. }
  48. }
  49. }
  50. if ((v - val[i]) * k2 == ves){
  51. cout << i + 1 << "\n";
  52. return;
  53. }
  54. }
  55. }
  56.  
  57. int main() {
  58. ios::sync_with_stdio(false);
  59. cin.tie(nullptr);
  60.  
  61. ll t = 1;
  62. while (t--) {
  63. solve();
  64. }
  65.  
  66. return 0;
  67. }
Runtime error #stdin #stdout #stderr 0.01s 5272KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc