# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
395736 | peuch | Red-blue table (IZhO19_stones) | C++17 | 129 ms | 2244 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
int t;
int n, m;
int k, l;
int ans;
int in[MAXN];
char grid[MAXN][MAXN];
bool inv;
set<pair<int, int> > s;
int main(){
scanf("%d", &t);
while(t--){
s.clear();
scanf("%d %d", &n, &m);
if(n < m) swap(n, m), inv = true;
else inv = false;
k = n / 2 + 1;
l = m / 2 + 1;
ans = n;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++)
grid[i][j] = (inv) ? '-' : '+';
s.insert(make_pair(-m, i));
in[i] = m;
}
for(int j = 1; j <= m; j++){
vector<int> ids;
bool flag = false;
for(int _ = 0; _ < k; _++){
ids.push_back(s.begin()->second);
if(s.begin()->first == -l) flag = true;
s.erase(s.begin());
}
if(flag) break;
ans++;
for(int i = 0; i < ids.size(); i++){
int cur = ids[i];
in[cur]--;
s.insert(make_pair(-in[cur], cur));
grid[cur][j] = (inv) ? '+' : '-';
}
}
printf("%d\n", ans);
if(inv) swap(n, m);
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
printf("%c", (inv) ? grid[j][i] : grid[i][j]);
}
printf("\n");
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |