제출 #1149889

#제출 시각아이디문제언어결과실행 시간메모리
114988912345678Red-blue table (IZhO19_stones)C++20
27 / 100
172 ms2416 KiB
#include <bits/stdc++.h> using namespace std; const int nx=1e3+5; int n, m, ans[nx][nx], s, cnt[nx], res[nx][nx], cur, thm, thn; void solve() { cin>>n>>m; cur=0; thn=(n+2)/2; thm=(m+2)/2; //cout<<"th "<<thn<<' '<<thm<<'\n'; for (int t=0; t<=n; t++) { int cs=t+(m-thm); for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) ans[i][j]=0; for (int i=1; i<=thm; i++) cnt[i]=n-t; for (int i=thm+1; i<=m; i++) cnt[i]=n-thn; for (int i=1; i<=t; i++) for (int j=1; j<=thm; j++) ans[i][j]=1; int idx=thm+1, lst=1; for (int i=1; i<=thm; i++) { while (cnt[i]<thn&&idx<=m) { //cout<<"here "<<t<<' '<<i<<' '<<cnt[idx]<<'\n'; if (cnt[idx]==0) idx++, lst=1; else if (lst>t) { lst=1; } else if (ans[lst][idx]) idx++, lst=1; else { for (int k=1; k<=t; k++) { if (ans[k][i]&&!ans[k][idx]) { swap(ans[k][i], ans[k][idx]); cnt[idx]--; cnt[i]++; break; } } } } if (cnt[i]>=thn) cs++; } if (t==0) cs=m; if (cs>cur) { cur=cs; for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) res[i][j]=ans[i][j]; } } cout<<cur<<'\n'; for (int i=1; i<=n; i++) { for (int j=1; j<=m; j++) cout<<(res[i][j]?'+':'-'); cout<<'\n'; } } int main() { cin.tie(NULL)->sync_with_stdio(false); int _t; cin>>_t; while (_t--) solve(); }
#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...