fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. //#pragma GCC optimize("Ofast")
  4. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  5.  
  6. #define ms(s, n) memset(s, n, sizeof(s))
  7. #define FOR(i, a, b) for (int i = (a); i < (b); ++i)
  8. #define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
  9. #define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
  10. #define sz(a) int((a).size())
  11. #define present(t, x) (t.find(x) != t.end())
  12. #define all(a) (a).begin(), (a).end()
  13. #define uni(a) (a).erase(unique(all(a)), (a).end())
  14. #define pb push_back
  15. #define pf push_front
  16. #define mp make_pair
  17. #define fi first
  18. #define se second
  19. #define prec(n) fixed<<setprecision(n)
  20. #define bit(n, i) (((n) >> (i)) & 1)
  21. #define bitcount(n) __builtin_popcountll(n)
  22. typedef long long ll;
  23. typedef unsigned long long ull;
  24. typedef long double ld;
  25. typedef pair<int, int> pi;
  26. typedef vector<int> vi;
  27. typedef vector<pi> vii;
  28. const int MOD = (int) 1e9 + 7;
  29. const int FFTMOD = 119 << 23 | 1;
  30. const int INF = (int) 1e9 + 23111992;
  31. const ll LINF = (ll) 1e18 + 23111992;
  32. const ld PI = acos((ld) -1);
  33. const ld EPS = 1e-9;
  34. inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
  35. inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
  36. inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
  37. template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
  38. template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
  39. inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;}
  40. inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
  41. inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
  42. inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
  43. inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
  44. inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
  45. inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
  46. inline int sign(ld x, ld y) {return sign(x - y);}
  47. mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
  48. inline int mrand() {return abs((int) mt());}
  49. inline int mrand(int k) {return abs((int) mt()) % k;}
  50. #define db(x) cerr << "[" << #x << ": " << (x) << "] ";
  51. #define endln cerr << "\n";
  52.  
  53. void chemthan() {
  54. int test; cin >> test;
  55. FOR(it, 1, test + 1) {
  56. db(it) endln;
  57. cout << "Case #" << it << ": ";
  58. int n, m, k, l; cin >> n >> m >> k >> l, k--;
  59. vector<string> s(n);
  60. FOR(i, 0, n) cin >> s[i];
  61. vii changes(l);
  62. FOR(i, 0, l) {
  63. int u, v; cin >> u >> v; u--, v--;
  64. changes[i] = mp(u, v);
  65. }
  66. {
  67. vector<string> ss = vector<string>(m);
  68. FOR(i, 0, m) {
  69. FOR(j, 0, n) ss[i] += s[j][i];
  70. }
  71. s = ss;
  72. }
  73. auto solve = [&] () {
  74. int C = min(n, m) + 5;
  75. vector<vi> fen(m, vi(n + 5));
  76. auto upd = [&] (vi& fen, int p, int v) {
  77. p++;
  78. for (; p < sz(fen); p += p & -p) {
  79. fen[p] += v;
  80. }
  81. };
  82. auto query = [&] (vi& fen, int p) {
  83. p++;
  84. chkmin(p, sz(fen) - 1);
  85. int res = 0;
  86. for (; 0 < p; p -= p & -p) {
  87. res += fen[p];
  88. }
  89. return res;
  90. };
  91. FOR(i, 0, m) FOR(j, 0, n) {
  92. if (s[i][j] == 'X') {
  93. upd(fen[i], j, 1);
  94. }
  95. }
  96. vi f(C);
  97. auto ss = s;
  98. auto upd_col = [&] (int col, int s) {
  99. int sum = query(fen[col], k - 1);
  100. FOR(i, 0, C) {
  101. if (k + i < n) {
  102. sum += ss[col][k + i] == 'X';
  103. }
  104. if (k + i < n && ss[col][k + i] == 'X') {
  105. f[i] += s;
  106. }
  107. else {
  108. if (k + 1 <= sum) {
  109. f[i] += s;
  110. }
  111. }
  112. }
  113. };
  114. FOR(i, 0, m) upd_col(i, 1);
  115. vi res;
  116. for (auto [u, v] : changes) {
  117. upd_col(v, -1);
  118. if (ss[v][u] == '.') {
  119. ss[v][u] = 'X';
  120. upd(fen[v], u, 1);
  121. }
  122. else {
  123. ss[v][u] = '.';
  124. upd(fen[v], u, -1);
  125. }
  126. upd_col(v, +1);
  127. res.pb(INF);
  128. FOR(i, 0, C) chkmin(res.back(), f[i] + i);
  129. }
  130. return res;
  131. };
  132. vi res(l, INF);
  133. FOR(it, 0, 2) {
  134. auto tmp = solve();
  135. FOR(i, 0, l) chkmin(res[i], tmp[i]);
  136. FOR(i, 0, m) reverse(all(s[i]));
  137. for (auto& [u, v] : changes) {
  138. u = n - u - 1;
  139. }
  140. k = n - k - 1;
  141. }
  142. cout << accumulate(all(res), 0LL) << "\n";
  143. }
  144. }
  145.  
  146. int32_t main(int32_t argc, char* argv[]) {
  147. ios_base::sync_with_stdio(0), cin.tie(0);
  148. if (argc > 1) {
  149. assert(freopen(argv[1], "r", stdin));
  150. }
  151. if (argc > 2) {
  152. assert(freopen(argv[2], "wb", stdout));
  153. }
  154. chemthan();
  155. cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  156. return 0;
  157. }
  158.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
         ^
Main.java:6: error: illegal character: '#'
#define ms(s, n) memset(s, n, sizeof(s))
^
Main.java:6: error: class, interface, or enum expected
#define ms(s, n) memset(s, n, sizeof(s))
        ^
Main.java:7: error: illegal character: '#'
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
^
Main.java:7: error: class, interface, or enum expected
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
                                       ^
Main.java:7: error: class, interface, or enum expected
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
                                                ^
Main.java:8: error: illegal character: '#'
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
^
Main.java:8: error: class, interface, or enum expected
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
                                            ^
Main.java:8: error: class, interface, or enum expected
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
                                                      ^
Main.java:9: error: illegal character: '#'
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
^
Main.java:9: error: class, interface, or enum expected
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
                                                                   ^
Main.java:9: error: class, interface, or enum expected
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
                                                                                    ^
Main.java:10: error: illegal character: '#'
#define sz(a) int((a).size())
^
Main.java:11: error: illegal character: '#'
#define present(t, x) (t.find(x) != t.end())
^
Main.java:12: error: illegal character: '#'
#define all(a) (a).begin(), (a).end()
^
Main.java:13: error: illegal character: '#'
#define uni(a) (a).erase(unique(all(a)), (a).end())
^
Main.java:14: error: illegal character: '#'
#define pb push_back
^
Main.java:15: error: illegal character: '#'
#define pf push_front
^
Main.java:16: error: illegal character: '#'
#define mp make_pair
^
Main.java:17: error: illegal character: '#'
#define fi first
^
Main.java:18: error: illegal character: '#'
#define se second
^
Main.java:19: error: illegal character: '#'
#define prec(n) fixed<<setprecision(n)
^
Main.java:20: error: illegal character: '#'
#define bit(n, i) (((n) >> (i)) & 1)
^
Main.java:21: error: illegal character: '#'
#define bitcount(n) __builtin_popcountll(n)
^
Main.java:23: error: class, interface, or enum expected
typedef unsigned long long ull;
^
Main.java:24: error: class, interface, or enum expected
typedef long double ld;
^
Main.java:25: error: class, interface, or enum expected
typedef pair<int, int> pi;
^
Main.java:26: error: class, interface, or enum expected
typedef vector<int> vi;
^
Main.java:27: error: class, interface, or enum expected
typedef vector<pi> vii;
^
Main.java:28: error: class, interface, or enum expected
const int MOD = (int) 1e9 + 7;
^
Main.java:29: error: class, interface, or enum expected
const int FFTMOD = 119 << 23 | 1;
^
Main.java:30: error: class, interface, or enum expected
const int INF = (int) 1e9 + 23111992;
^
Main.java:31: error: class, interface, or enum expected
const ll LINF = (ll) 1e18 + 23111992;
^
Main.java:32: error: class, interface, or enum expected
const ld PI = acos((ld) -1);
^
Main.java:33: error: class, interface, or enum expected
const ld EPS = 1e-9;
^
Main.java:34: error: class, interface, or enum expected
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
^
Main.java:34: error: class, interface, or enum expected
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
                                 ^
Main.java:34: error: class, interface, or enum expected
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
                                                       ^
Main.java:34: error: class, interface, or enum expected
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
                                                              ^
Main.java:34: error: class, interface, or enum expected
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
                                                                    ^
Main.java:34: error: class, interface, or enum expected
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
                                                                               ^
Main.java:35: error: class, interface, or enum expected
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
                                                    ^
Main.java:36: error: class, interface, or enum expected
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
                                                   ^
Main.java:36: error: class, interface, or enum expected
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
                                                          ^
Main.java:36: error: class, interface, or enum expected
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
                                                             ^
Main.java:36: error: class, interface, or enum expected
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
                                                                                                 ^
Main.java:36: error: class, interface, or enum expected
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
                                                                                                               ^
Main.java:36: error: class, interface, or enum expected
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
                                                                                                                          ^
Main.java:37: error: '{' expected
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
                ^
Main.java:37: error: <identifier> expected
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
                                     ^
Main.java:37: error: : expected
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
                                                                                 ^
Main.java:38: error: illegal start of type
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
         ^
Main.java:38: error: '{' expected
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
                ^
Main.java:38: error: <identifier> expected
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
                                     ^
Main.java:38: error: : expected
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
                                                                                 ^
Main.java:39: error: ';' expected
inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;}
          ^
Main.java:39: error: invalid method declaration; return type required
inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;}
           ^
Main.java:40: error: ';' expected
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
         ^
Main.java:40: error: invalid method declaration; return type required
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
          ^
Main.java:41: error: <identifier> expected
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
      ^
Main.java:41: error: <identifier> expected
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
                      ^
Main.java:41: error: <identifier> expected
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
                                   ^
Main.java:41: error: ';' expected
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
                                               ^
Main.java:42: error: <identifier> expected
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
      ^
Main.java:42: error: <identifier> expected
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
                      ^
Main.java:42: error: <identifier> expected
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
                                   ^
Main.java:42: error: ';' expected
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
                                               ^
Main.java:43: error: <identifier> expected
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
      ^
Main.java:43: error: ',', ')', or '[' expected
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
                                   ^
Main.java:44: error: <identifier> expected
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
      ^
Main.java:44: error: ',', ')', or '[' expected
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
                           ^
Main.java:45: error: <identifier> expected
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
      ^
Main.java:46: error: <identifier> expected
inline int sign(ld x, ld y) {return sign(x - y);}
      ^
Main.java:47: error: <identifier> expected
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
                 ^
Main.java:48: error: <identifier> expected
inline int mrand() {return abs((int) mt());}
      ^
Main.java:49: error: <identifier> expected
inline int mrand(int k) {return abs((int) mt()) % k;}
      ^
Main.java:50: error: illegal character: '#'
#define db(x) cerr << "[" << #x << ": " << (x) << "] ";
^
Main.java:50: error: invalid method declaration; return type required
#define db(x) cerr << "[" << #x << ": " << (x) << "] ";
        ^
Main.java:50: error: <identifier> expected
#define db(x) cerr << "[" << #x << ": " << (x) << "] ";
            ^
Main.java:50: error: ';' expected
#define db(x) cerr << "[" << #x << ": " << (x) << "] ";
             ^
Main.java:50: error: illegal character: '#'
#define db(x) cerr << "[" << #x << ": " << (x) << "] ";
                             ^
Main.java:51: error: illegal character: '#'
#define endln cerr << "\n"; 
^
Main.java:51: error: ';' expected
#define endln cerr << "\n"; 
                  ^
Main.java:54: error: not a statement
    int test; cin >> test;
                  ^
Main.java:55: error: ';' expected
    FOR(it, 1, test + 1) {
                        ^
Main.java:56: error: ';' expected
        db(it) endln;
              ^
Main.java:56: error: not a statement
        db(it) endln;
               ^
Main.java:57: error: not a statement
        cout << "Case #" << it << ": ";
                               ^
Main.java:58: error: not a statement
        int n, m, k, l; cin >> n >> m >> k >> l, k--;
                                           ^
Main.java:58: error: ';' expected
        int n, m, k, l; cin >> n >> m >> k >> l, k--;
                                               ^
Main.java:59: error: ';' expected
        vector<string> s(n);
                        ^
Main.java:59: error: not a statement
        vector<string> s(n);
                         ^
Main.java:59: error: ';' expected
        vector<string> s(n);
                          ^
Main.java:60: error: ';' expected
        FOR(i, 0, n) cin >> s[i];
                    ^
Main.java:60: error: not a statement
        FOR(i, 0, n) cin >> s[i];
                         ^
Main.java:61: error: ';' expected
        vii changes(l);
                   ^
Main.java:61: error: not a statement
        vii changes(l);
                    ^
Main.java:61: error: ';' expected
        vii changes(l);
                     ^
Main.java:62: error: ';' expected
        FOR(i, 0, l) {
                    ^
100 errors
stdout
Standard output is empty