Submission #1132268

#TimeUsernameProblemLanguageResultExecution timeMemory
1132268AgageldiRed-blue table (IZhO19_stones)C++17
100 / 100
17 ms6216 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define N 400005 #define ff first #define ss second #define pb push_back #define sz(s) (int)s.size() #define rep(c, a, b) for(c = a; c <= b; c++) ll n, t, c[N], m, T, r[N]; char a[5000][5000]; void solve() { for(int i = 1; i <= n; i++){ r[i] = 0; } for(int i = 1; i <= m; i++) { c[i] = n; } int cnt = 1; for(int i = 1; i <= n; i++) { t = cnt; for(int j = cnt; j <= m; j++) { if(r[i] == m/2 + 1 || c[j] == (n/2) + 1) break; a[i][j] = '+'; r[i]++; c[j]--; if(j == m) j = 0; t = j + 1; } cnt = t; } } void find() { for(int i = 1; i <= n; i++){ r[i] = m; } for(int i = 1; i <= m; i++) { c[i] = 0; } int cnt = 1; for(int i =1;i<=m;i++) { t = cnt; for(int j = cnt; j <= n; j++) { if(r[j] == m/2 + 1 || c[i] == n / 2 + 1) break; a[j][i] = '-'; r[j]--; c[i]++; if(j == n) j = 0; t = j + 1; } cnt = t; } } int main () { ios::sync_with_stdio(0);cin.tie(0); cin >> T; while(T--) { cin >> n >> m; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { if(m >= n)a[i][j] = '-'; else a[i][j] = '+'; } } if(m >= n) { solve(); } else { find(); } int ans = 0; for(int i= 1;i<=n;i++) { t = 0; for(int j = 1; j <= m; j++) { if(a[i][j] == '+') t++; else t--; } if(t > 0) ans++; } for(int i = 1; i <= m; i++) { t = 0; for(int j = 1; j <= n; j++) { if(a[j][i] == '-') t++; else t--; } if(t > 0) ans++; } cout << ans << '\n'; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { cout << a[i][j]; } 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...