제출 #1230735

#제출 시각아이디문제언어결과실행 시간메모리
1230735ByeWorldRed-blue table (IZhO19_stones)C++20
100 / 100
55 ms3396 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define int long long #define ll long long #define se second #define fi first #define pb push_back #define lf (id<<1) #define rg ((id<<1)|1) #define md ((l+r)>>1) using namespace std; typedef pair<int,int> pii; typedef pair<pii,pii> ipii; const int MAXN = 2e5+10; const int SQRT = 450; const int INF = 2e9; const int MOD = 998244353; const int LOG = 20; int sum(int a, int b){ return (a+MOD+b)%MOD; } void chsum(int &a, int b){ a = (a+MOD+b)%MOD; } int mul(int a, int b){ return (a*b)%MOD; } void chmul(int &a, int b){ a = (a*b)%MOD; } void chmn(auto &a, auto b){ a = min(a, b); } void chmx(auto &a, auto b){ a = max(a, b); } int n, m; bool sw; bool ans[1010][1010], b[1010][1010]; // 0 blue col -, 1 red row + signed main(){ // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int T; cin>>T; while(T--){ cin>>n>>m; if(n > m) sw = 1, swap(n, m); else sw = 0; for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) ans[i][j] = b[i][j] = 0; int p = n/2, q = m/2+1, idx = -1, mx = -1; if(n%2==0) p--; for(int x=0; x<=m; x++){ int row = n; if(q-m+x > 0) row = min(n, p*x/(q-m+x) ); if(mx <= x + row){ mx = x+row; idx = x; } // cout << x << ' ' << x+row << " x\n"; } assert(idx == m); // cout << idx << " mx\n"; if(mx > m){ for(int i=1; i<=n; i++) // jadiin + semua, buat row for(int j=idx+1; j<=m; j++) ans[i][j] = 1; if(q-m+idx > 0){ // gk lgsng menang // idx awal - yg menang col int take = q-m+idx; // cout << take << " take\n"; priority_queue <pii> pq; // per column jatah segini for(int i=1; i<=idx; i++) pq.push({p, i}); for(int i=1; i<=n; i++){ // build row // ambil take vector<pii> vec; for(int t=1; t<=take; t++){ if(pq.empty()) break; auto [tp, id] = pq.top(); pq.pop(); ans[i][id] = 1; if(tp-1 > 0) vec.pb({tp-1, id}); } for(auto in : vec) pq.push(in); } } } if(sw){ for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) b[j][i] = 1-ans[i][j]; for(int i=1; i<=m; i++) for(int j=1; j<=n; j++) ans[i][j] = b[i][j]; swap(n, m); } int all = 0; for(int i=1; i<=n; i++){ int tot = 0; for(int j=1; j<=m; j++){ if(ans[i][j]) tot++; } if(tot > m/2) all++; } for(int j=1; j<=m; j++){ int tot = 0; for(int i=1; i<=n; i++){ if(ans[i][j]==0) tot++; } if(tot > n/2) all++; } cout << all << '\n'; for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ cout << (ans[i][j] ? '+' : '-'); } cout << '\n'; } 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...