Submission #167225

#TimeUsernameProblemLanguageResultExecution timeMemory
167225apostoldaniel854Red-blue table (IZhO19_stones)C++14
100 / 100
83 ms5240 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define dbg(x) cerr << #x << " " << x << "\n" typedef long long ll; const int N = 1000; int row[1 + N], col[1 + N], grid[1 + N][1 + N]; void upd (int l, int c, int x) { grid[l][c] = max (0, x); row[l] += x; col[c] += x; } int main () { ios::sync_with_stdio (false); cin.tie (0); cout.tie (0); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) grid[i][j] = row[i] = col[j] = 0; if (n <= m) { for (int i = 1; i <= n; i++) { vector <pair <int, int>> v; for (int j = 1; j <= m; j++) { if (2 * (col[j] + 1) < n) v.pb ({col[j], j}); } if (v.size () <= m / 2) break; sort (v.begin (), v.end ()); for (int j = 0; j <= m / 2; j++) upd (i, v[j].second, 1); } } else { for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) upd (i, j, 1); for (int i = 1; i <= m; i++) { vector <pair <int, int>> v; for (int j = 1; j <= n; j++) { if (2 * (row[j] - 1) > m) v.pb ({row[j], j}); } if (v.size () <= n / 2) break; sort (v.begin (), v.end ()); reverse (v.begin (), v.end ()); for (int j = 0; j <= n / 2; j++) upd (v[j].second, i, -1); } } int ans = 0; for (int i = 1; i <= n; i++) if (row[i] * 2 >= m) ans++; for (int i = 1; i <= m; i++) if (col[i] * 2 < n) ans++; cout << ans << "\n"; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) if (grid[i][j]) cout << "+"; else cout << "-"; cout << "\n"; } } return 0; }

Compilation message (stderr)

stones.cpp: In function 'int main()':
stones.cpp:35:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if (v.size () <= m / 2)
                     ~~~~~~~~~~^~~~~~~~
stones.cpp:53:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if (v.size () <= n / 2)
                     ~~~~~~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...