Submission #199830

#TimeUsernameProblemLanguageResultExecution timeMemory
199830pathSajam (COCI18_sajam)C++14
90 / 90
45 ms4216 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define f first #define s second #define pb push_back const int N=1e3+5; int n,k,a[N][N],c[N],r[N],t,tmp; char ch; pair<int,int> mr,mc; priority_queue< pair<int,int> > q[2]; int main(){ cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); cin>>n>>k; for(int i=0;i<n;i++) for(int j=0;j<n;j++){ cin>>ch; a[i][j]=(ch=='o'); if(a[i][j]) t++; } for(int i=0;i<n;i++){ tmp=0; for(int j=0;j<n;j++) if(a[i][j]) tmp++; r[i]=tmp; } for(int j=0;j<n;j++){ tmp=0; for(int i=0;i<n;i++) if(a[i][j]) tmp++; c[j]=tmp; } for(int i=0;i<2*n && t>k ;i++){ //cout<<t<<'\n'; mr= {r[0],0}; mc={c[0],0}; for(int j=0;j<n;j++){ if(r[j]>mr.f) mr={r[j],j}; if(c[j]>mc.f) mc={c[j],j}; } if(mr.f>mc.f){ int row=mr.s; for(int j=0;j<n;j++){ if(a[row][j]){ r[row]--; c[j]--; t--; } else{ r[row]++; c[j]++; t++; } a[row][j]=(!a[row][j]); } } else{ int col=mc.s; for(int j=0;j<n;j++){ if(a[j][col]){ r[j]--; c[col]--; t--; } else{ r[j]++; c[col]++; t++; } a[j][col]=(!a[j][col]); } } } if(t<=k) cout<<"DA\n"; else cout<<"NE\n"; return 0; }
#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...