제출 #335189

#제출 시각아이디문제언어결과실행 시간메모리
335189GurbanRed-blue table (IZhO19_stones)C++17
27 / 100
37 ms1900 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn=1e3+5; int tt,ans,ps,need; int n,m,tr,a[maxn][maxn]; int cnt[maxn],num[maxn]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> tt; while(tt--){ cin >> n >> m; tr = 0; if(n % 2 == 0) swap(n,m),tr=1; for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) a[i][j]=1; if(min(n,m) <= 2){ ans = max(n,m); for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++){ if(n > m) a[i][j]=1; else a[i][j]=0; } } else{ ans = n - 2,ps = m/2+1,need = n/2+1; for(int i = n - 1;i <= n;i++) for(int j = 1;j <= m;j++) a[i][j]=0; for(int i = 1;i <= m;i++) cnt[i] = 2; for(int i = 1;i <= n-2;i++) num[i] = m; for(int i = 1;i <= m;i++){ for(int j = 1;j <= n-2;j++){ if(cnt[i]==need) break; if(num[j] > ps){ a[j][i] = 0; num[j]--,cnt[i]++; } } if(cnt[i]==need) ans++; } } if(ans < n+(m-1)/2){ tr = 0,ans=n+(m-1)/2; for(int i = 1;i <= n;i++){ for(int j = 1;j <= m/2+1;j++) a[i][j]=1; for(int j = m/2+2;j <= m;j++) a[i][j]=0; } } if(ans < m+(n-1)/2){ tr = 0,ans=m+(n-1)/2; for(int i = 1;i <= m;i++){ for(int j = 1;j <= n/2+1;j++) a[j][i]=0; for(int j = n/2+2;j <= n;j++) a[j][i]=1; } } cout<<ans<<'\n'; if(tr) swap(n,m); for(int i = 1;i <= n;i++){ for(int j = 1;j <= m;j++){ char nw = '+'; if((tr and a[j][i]==1) or (tr==0 and a[i][j]==0)) nw = '-'; cout<<nw; } 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...