Submission #269786

#TimeUsernameProblemLanguageResultExecution timeMemory
269786aZvezdaRed-blue table (IZhO19_stones)C++14
0 / 100
40 ms1472 KiB
#include <bits/stdc++.h> using namespace std; #define endl "\n" typedef long long ll; typedef unsigned long long ull; template<class T, class T2> bool chkmax(T &a, const T2 &b) {return (a < b) ? a = b, 1 : 0;} const int MAX_N = 1e1 + 10; int tab[MAX_N][MAX_N]; int get(int n, int m) { int total = n * m; int ret = 0, retmask; for(int mask = 0; mask < (1 << total); mask ++) { for(int j = 0; j < total; j ++) { tab[j / m][j % m] = (bool)(mask & (1 << j)); } int a = 0; for(int i = 0; i < n; i ++) { int curr = 0; for(int j = 0; j < m; j ++) { if(tab[i][j]) { curr ++; } else { curr --; } } if(curr > 0) { a ++; } } for(int j = 0; j < m; j ++) { int curr = 0; for(int i = 0; i < n; i ++) { if(tab[i][j]) { curr --; } else { curr ++; } } if(curr > 0) { a ++; } } if(chkmax(ret, a)) { retmask = mask; } } for(int j = 0; j < total; j ++) { tab[j / m][j % m] = (bool)(retmask & (1 << j)); } cout << n << " " << m << " " << ret << endl; for(int i = 0; i < n; i ++) { for(int j = 0; j < m; j ++) { cout << tab[i][j] << " "; } cout << endl; } cout << "!" << endl; return ret; } int cnt[MAX_N]; char ans[MAX_N][MAX_N]; int getFast(int n, int m) { for(int i = 0; i < m; i ++) { cnt[i] = n; } bool rev = 0; if(n > m) { rev = true; swap(n, m); } int ret = max(n, m); int halfCnt = (m / 2) + 1; int gotten = 0, opti = 0; for(int i = 0; i < n; i ++) { //sort(cnt, cnt + m); //reverse(cnt, cnt + m); for(int j = 0; j < halfCnt; j ++) { cnt[j] --; } gotten ++; int curr = gotten; for(int j = 0; j < m; j ++) { if(cnt[j] * 2 > n) { curr ++; } } if(chkmax(ret, curr)) { opti = i + 1; } } for(int i = 0; i < n; i ++) { for(int j = 0; j < m; j ++) { ans[i][j] = '-'; } } for(int i = 0; i < opti; i ++) { for(int j = 0; j < halfCnt; j ++) { ans[i][j] = '+'; } } if(rev) { for(int i = 0; i < n; i ++) { for(int j = 0; j < m; j ++) { if(ans[i][j] == '-') { ans[i][j] = '+'; } else { ans[i][j] = '-'; } } } } if(rev) { for(int i = 0; i < n; i ++) { for(int j = 0; j < m; j ++) { if(i < j) { swap(ans[i][j], ans[j][i]); } } } swap(n, m); } int a = 0; for(int i = 0; i < n; i ++) { int curr = 0; for(int j = 0; j < m; j ++) { if(ans[i][j] == '+') { curr ++; } else { curr --; } } if(curr > 0) { a ++; } } for(int j = 0; j < m; j ++) { int curr = 0; for(int i = 0; i < n; i ++) { if(ans[i][j] == '+') { curr --; } else { curr ++; } } if(curr > 0) { a ++; } } //cout << a << " " << ret << endl; cout << ret << endl; for(int i = 0; i < n; i ++) { for(int j = 0; j < m; j ++) { cout << ans[i][j]; } cout << endl; } //assert(a == ret); return ret; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while(t --) { int n, m; cin >> n >> m; getFast(n, m); } }

Compilation message (stderr)

stones.cpp: In function 'int get(int, int)':
stones.cpp:49:23: warning: 'retmask' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |   tab[j / m][j % m] = (bool)(retmask & (1 << j));
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...