Submission #992741

#TimeUsernameProblemLanguageResultExecution timeMemory
992741NValchanovRed-blue table (IZhO19_stones)C++17
17 / 100
2065 ms600 KiB
#include <bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; const int MAXN = 1e3 + 10; int n, m; bool table[MAXN][MAXN]; bool ans_table[MAXN][MAXN]; int ans; void read() { cin >> n >> m; } void check() { int a = 0; for(int i = 1; i <= n; i++) { int cntr = 0; int cntb = 0; for(int j = 1; j <= m; j++) { cntr += (table[i][j]); cntb += (!table[i][j]); } assert(cntr + cntb == m); if(cntr > cntb) a++; } int b = 0; for(int j = 1; j <= m; j++) { int cntr = 0; int cntb = 0; for(int i = 1; i <= n; i++) { cntr += (table[i][j]); cntb += (!table[i][j]); } assert(cntr + cntb == n); if(cntb > cntr) b++; } if(ans < a + b) { ans = a + b; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { ans_table[i][j] = table[i][j]; } } } } void solve(int row, int col) { if(row == n + 1 && col == 1) { check(); return; } ///cout << "State : " << row << " : " << col << endl; table[row][col] = false; if(col == m) solve(row + 1, 1); else solve(row, col + 1); table[row][col] = true; if(col == m) solve(row + 1, 1); else solve(row, col + 1); } void print() { cout << ans << endl; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { cout << (ans_table[i][j] ? '+' : '-'); } cout << endl; } } int main() { // #ifdef ONLINE_JUDGE // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); // #endif ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t; cin >> t; while(t--) { read(); ans = 0; solve(1, 1); print(); } 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...