Submission #154516

#TimeUsernameProblemLanguageResultExecution timeMemory
154516PankinRed-blue table (IZhO19_stones)C++14
100 / 100
80 ms1680 KiB
#include <bits/stdc++.h> /* #pragma GCC optimize("unroll-loops") #pragma GCC optimize("Ofast") #pragma GCC optimize("-O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") */ #define mp make_pair #define ll long long #define ld long double #define pb push_back #define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define fs first #define sc second #define getfiles ifstream cin("input.txt"); ofstream cout("output.txt"); #define endl '\n' #define con continue #define pii pair<int, int> #define all(x) x.begin(), x.end() const int INF = 2000000005; const ll BIG_INF = 2000000000000000005; const int mod = 1000000007; const int P = 31; const ld PI = 3.141592653589793238462643; const double eps = 1e-9; using namespace std; vector< pair<int, int> > dir = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } }; bool valid(int x, int y, int n, int m) { return x >= 0 && y >= 0 && x < n && y < m; } mt19937 rng(1999999973); inline int getAns(vector<vector<bool>> &a) { int ans = 0; for (int i = 0; i < a.size(); i++) { int diff = 0; for (int j = 0; j < a[0].size(); j++) { if (a[i][j]) diff++; else diff--; } if (diff > 0) ans++; } for (int j = 0; j < a[0].size(); j++) { int diff = 0; for (int i = 0; i < a.size(); i++) { if (a[i][j]) diff--; else diff++; } if (diff > 0) ans++; } return ans; } vector< vector<bool> > solve(int n, int m) { vector< vector<bool> > a(n, vector<bool>(m, true)); int mxad = (m + 1) / 2 - 1, req = n - ((n + 1) / 2 - 1); priority_queue<pii> q; for (int i = 0; i < n; i++) q.push(mp(mxad, i)); int cur_column = m - 1; while(true) { vector<pii> cur; cur.reserve(req); bool good = true; for (int i = 0; i < req; i++) { pii v = q.top(); if (v.fs == 0) { good = false; break; } cur.pb(v); q.pop(); } if (!good) break; for (int i = 0; i < req; i++) { a[cur[i].sc][cur_column] = false; q.push(mp(cur[i].fs - 1, cur[i].sc)); } cur_column--; } return a; } signed main() { fast_io; int tests; cin >> tests; while(tests--) { int n, m; cin >> n >> m; vector<vector<bool>> a(n, vector<bool>(m, true)); if (n >= m) a = solve(n, m); else { vector< vector<bool> > b(m, vector<bool>(n, true)); b = solve(m, n); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[i][j] = !b[j][i]; } } } cout << getAns(a) << endl; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cout << (a[i][j] ? '+' : '-'); } cout << endl; } } return 0; }

Compilation message (stderr)

stones.cpp: In function 'int getAns(std::vector<std::vector<bool> >&)':
stones.cpp:55:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.size(); i++) {
                     ~~^~~~~~~~~~
stones.cpp:57:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < a[0].size(); j++) {
                         ~~^~~~~~~~~~~~~
stones.cpp:66:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < a[0].size(); j++) {
                     ~~^~~~~~~~~~~~~
stones.cpp:68:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < a.size(); i++) {
                         ~~^~~~~~~~~~
#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...