Submission #154514

#TimeUsernameProblemLanguageResultExecution timeMemory
154514PankinRed-blue table (IZhO19_stones)C++14
15 / 100
70 ms1528 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); int n, m; inline int getAns(vector<vector<bool>> &a) { int ans = 0; for (int i = 0; i < n; i++) { int diff = 0; for (int j = 0; j < m; j++) { if (a[i][j]) diff++; else diff--; } if (diff > 0) ans++; } for (int j = 0; j < m; j++) { int diff = 0; for (int i = 0; i < n; i++) { if (a[i][j]) diff--; else diff++; } if (diff > 0) ans++; } return ans; } signed main() { fast_io; int tests; cin >> tests; while(tests--) { cin >> n >> 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--; } 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; }
#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...