Submission #1209655

#TimeUsernameProblemLanguageResultExecution timeMemory
1209655garam1732여왕벌 (KOI15_queen)C++20
68 / 100
5076 ms231956 KiB
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define bl ' ' #define endl '\n' #define all(v) (v).begin(), (v).end() #define comp(v) (v).erase(unique(all(v)), (v).end()) #define lbd(v,x) lower_bound(all(v), (x))-(v).begin() #define ubd(v,x) upper_bound(all(v), (x))-(v).begin() typedef long long ll; typedef pair<int, int> pi; typedef pair<pi, int> pii; typedef pair<int, pi> ipi; typedef pair<pi, pi> pipi; typedef pair<ll, ll> pll; const int MAXN = 100100*10; const ll MOD = 998244353; const ll INF = 1e16; const int MAXM = 770; string info[MAXM][MAXM]; typedef array<int,3> Bee; int sz=0; int res[MAXM][MAXM]; void dnc(int sx, int ex, int sy, int ey, map<Bee, int>& mp0, map<Bee, Bee>& dp0) { // cout<<sx<<bl<<ex<<bl<<sy<<bl<<ey<<" mp : "<<endl; // for(auto [x,cnt] : mp[t]) { // cout<<x[0]<<bl<<x[1]<<bl<<x[2]<<bl<<cnt<<endl; // } if(sx==ex || sy==ey) { for(auto [x,cnt] : mp0) { dp0[x] = x; } return; } if(sx+1==ex && sy+1==ey) { for(auto [x,cnt] : mp0) { int idx; if(x[0]==3) idx=0; else if(x[0]==2 && x[1]==1) idx=1; else if(x[0]==2) idx=2; else if(x[0]==1 && x[1]==2) idx=4; else if(x[0]==1 && x[2]==2) idx=8; else if(x[0]==1) idx=5; else if(x[1]==3) idx=13; else if(x[1]==2) idx=14; else if(x[1]==1) idx=17; else idx=26; int col; if(info[ex][ey][idx] == 'L') col=idx/9; else if(info[ex][ey][idx] == 'D') col=idx/3%3; else col=idx%3; res[ex][ey] += col*cnt; dp0[x][col]++; dp0[x][idx/9]++; dp0[x][idx%3]++; } // cout<<sx<<bl<<ex<<bl<<sy<<bl<<ey<<" dp : "<<endl; // for(auto [x,y] : dp[sz]) { // cout<<x.a<<bl<<x.b<<bl<<x.c<<bl<<y.a<<bl<<y.b<<bl<<y.c<<endl; // } return; } map<Bee, int> mp[4]; map<Bee, Bee> dp[4]; map<Bee, Bee> w[4]; int mx=sx+ex>>1, my=sy+ey>>1; for(auto [x, cnt] : mp0) { int tot = mx-sx+my-sy+1; int a = min(tot, max(0, x[0]-(ex-mx))); int c = min(tot, max(0, x[2]-(ey-my))); int b = tot-a-c; mp[0][{a,b,c}] += cnt; w[0][x] = {a,b,c}; } dnc(sx, mx, sy, my, mp[0], dp[0]); for(auto [x, cnt] : mp0) {//if(sx==0&&mx==0&&my==2&&ey==3)cout<<"YEE"<<endl; int tot1 = mx-sx+1, tot2 = ey-my; int a = min(tot1, max(0, dp[0][w[0][x]][0]-(my-sy))) + min(tot2, max(0, x[0]-(ex-sx+my-sy+1))); int c = min(tot1, dp[0][w[0][x]][2]) + min(tot2, x[2]); int b = tot1+tot2-a-c; mp[1][{a,b,c}] += cnt; w[1][x] = {a,b,c}; } dnc(sx, mx, my, ey, mp[1], dp[1]); for(auto [x, cnt] : mp0) {//if(mx+1==2&&ex==2&&sy==3&&my==3)cout<<"Yee"<<dp[mx1][w[t][0][x]].c<<endl; int tot1 = ex-mx, tot2 = my-sy+1; int a = min(tot1, x[0]) + min(tot2, dp[0][w[0][x]][0]); int c = min(tot1, max(0, x[2]-(ey-sy+mx-sx+1))) + min(tot2, max(0, dp[0][w[0][x]][2]-(mx-sx))); int b = tot1+tot2-a-c; mp[2][{a,b,c}] += cnt; w[2][x] = {a,b,c}; } dnc(mx, ex, sy, my, mp[2], dp[2]); for(auto [x, cnt] : mp0) { int tot1 = ex-mx+1, tot2 = ey-my; int a = min(tot1, max(0, dp[2][w[2][x]][0]-(my-sy))) + min(tot2, max(0, dp[1][w[1][x]][0]-1)); int c = min(tot1, dp[2][w[2][x]][2]) + min(tot2, max(0, dp[1][w[1][x]][2]-(mx-sx))); int b = tot1+tot2-a-c; mp[3][{a,b,c}] += cnt; w[3][x] = {a,b,c}; } dnc(mx, ex, my, ey, mp[3], dp[3]); for(auto [x, cnt] : mp0) {//if(sx==1&&ex==2&&sy==3&&ey==3) cout<<"YEE"<<dp[mx2][w[t][1][x]].a-(ey-my-1)<<endl; int tot1 = my-sy, tot2 = mx-sx, tot3 = ex-mx+ey-my+1; int a = min(tot1, dp[2][w[2][x]][0]) + min(tot2, max(0, dp[1][w[1][x]][0]-(ey-my+1))) + dp[3][w[3][x]][0]; int c = min(tot1, max(0, dp[2][w[2][x]][2]-(ex-mx+1))) + min(tot2, dp[1][w[1][x]][2]) + dp[3][w[3][x]][2]; int b = tot1+tot2+tot3-a-c; dp0[x] = {a,b,c}; } for(int x=0; x<4; x++) { mp[x].clear(); dp[x].clear(); w[x].clear(); } // cout<<sx<<bl<<ex<<bl<<sy<<bl<<ey<<" dp : "<<endl; // for(auto [x,y] : dp[sz-1]) { // cout<<x.a<<bl<<x.b<<bl<<x.c<<bl<<y.a<<bl<<y.b<<bl<<y.c<<endl; // } } vector<pi> v; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int m, n; cin>>m>>n; for(int i=1; i<m; i++) { for(int j=1; j<m; j++) { cin >> info[i][j]; } } for(int i=m-1; i; i--) v.push_back(pi(i, 0)); for(int j=0; j<m; j++) v.push_back(pi(0, j)); assert(v.size() == 2*m-1); map<Bee, int> mp; map<Bee, Bee> dp; for(int i=0; i<n; i++) { int a,b,c; cin>>a>>b>>c; mp[{a,b,c}]++; int x=0; while(a--) { pi t=v[x++]; res[t.ff][t.ss] += 0; } while(b--) { pi t=v[x++]; res[t.ff][t.ss] += 1; } while(c--) { pi t=v[x++]; res[t.ff][t.ss] += 2; } } sz++; dnc(0, m-1, 0, m-1, mp, dp); for(int i=0; i<m; i++) { for(int j=0; j<m; j++) cout<<res[i][j]+1<<bl; cout<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...