Submission #201553

#TimeUsernameProblemLanguageResultExecution timeMemory
201553my04Red-blue table (IZhO19_stones)C++17
0 / 100
2087 ms376 KiB
/* И пусть меня погубит, то к чему я Бегу, не жалея ног. И если мне суждено сгореть на восходе, Я буду идти вперёд. */ #include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define sz(x) (int)(x).size() #define S second #define F first #define all(x) (x).begin(), (x).end() using namespace std; const bool dbg_flg = 0; #define debug(x) if (dbg_flg) cerr << #x << ' ' << x << '\n' #define debug_pair(x) if (dbg_flg) cerr << #x << ' ' << x.F << ' ' << x.S << '\n' const int inf = 1e9 + 7; const int MAXN = 1e5 + 5; int n, m; char x[55][55]; int res; char y[55][55]; void rec(int v) { if (v == n) { int a = 0, b = 0; for (int i = 1; i <= n; i++) { int red = 0; int blue = 0; for (int j = 1; j <= m; j++) { if (x[i][j] == '+') red++; else blue++; } if (red > blue) a++; } for (int i = 1; i <= m; i++) { int red = 0; int blue = 0; for (int j = 1; j <= n; j++) { if (x[j][i] == '+') red++; else blue++; } if (blue > red) b++; } if (a + b > res) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { y[i][j] = x[i][j]; } } res = a + b; } return; } for (int i = 0; i < (1 << m); i++) { for (int j = 0; j < m; j++) { if (i & (1 << j)) x[v + 1][j + 1] = '+'; else x[v + 1][j + 1] = '-'; } rec(v + 1); } } void solve() { cin >> n >> m; res = 0; rec(0); cout << res << '\n'; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cout << y[i][j] << ' '; } cout << '\n'; } } int main() { //~ freopen(".in", "r", stdin); //~ freopen(".out", "w", stdout); //ios_base::sync_with_stdio(NULL); //cin.tie(NULL); //cout.tie(NULL); int tt = 1; cin >> tt; while (tt--) { solve(); } 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...