제출 #689305

#제출 시각아이디문제언어결과실행 시간메모리
689305OrazBRed-blue table (IZhO19_stones)C++14
43 / 100
2055 ms980 KiB
#include <bits/stdc++.h> #define N 1005 #define wr cout << "Continue debugging\n"; #define all(x) (x).begin(), (x).end() #define ll long long int #define pii pair <int, int> #define pb push_back #define ff first #define ss second using namespace std; int t, c[N], mx, n, m, a[N][N], b[N][N]; void bit(int x, int cur){ if (x == cur+1){ int cnt = 0; if (n == cur and m != cur){ for (int i = 1; i <= n; i++){ for (int j = 1; j <= m; j++){ a[i][j] = 0; } } priority_queue<pii> q; for (int i = 1; i <= m; i++){ q.push({0, i}); } for (int i = 1; i <= n; i++){ if (!c[i]) continue; cnt++; int x = m/2+1; while(x--){ int val = q.top().ff; int j = q.top().ss; q.pop(); a[i][j] = 1; q.push({val-1, j}); } } for (int i = 1; i <= m; i++){ int num = 0; for (int j = 1; j <= n; j++){ if (!a[j][i]) num++; } if (num >= n/2+1) cnt++; } }else{ for (int i = 1; i <= n; i++){ for (int j = 1; j <= m; j++){ a[i][j] = 1; } } priority_queue<pii> q; for (int i = 1; i <= n; i++){ q.push({0, i}); } for (int i = 1; i <= m; i++){ if (!c[i]) continue; cnt++; int x = n/2+1; while(x--){ int val = q.top().ff; int j = q.top().ss; q.pop(); a[j][i] = 0; q.push({val-1, j}); } } for (int i = 1; i <= n; i++){ int num = 0; for (int j = 1; j <= m; j++){ if (a[i][j]) num++; } if (num >= m/2+1) cnt++; } } if (mx < cnt){ mx = cnt; for (int i = 1; i <= n; i++){ for (int j = 1; j <= m; j++){ b[i][j] = a[i][j]; } } } return; } for (int i = 0; i < 2; i++){ c[x] = i; bit(x+1, cur); } } int main () { ios::sync_with_stdio(false); cin.tie(0); cin >> t; while (t--){ mx = 0; cin >> n >> m; bit(1, min(n, m)); cout << mx << '\n'; for (int i = 1; i <= n; i++){ for (int j = 1; j <= m; j++){ if (b[i][j]) cout << '+'; else cout << '-'; } cout << '\n'; } } }
#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...