Submission #115365

#TimeUsernameProblemLanguageResultExecution timeMemory
115365dsjongSeats (IOI18_seats)C++14
11 / 100
854 ms32888 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; int M,N; int r[10005],c[10005]; int last=0; int maxr[1000005],maxc[1000005],minr[1000005],minc[1000005]; void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { M=H,N=W; for(int i=0;i<M*N;i++){ r[i]=R[i]; c[i]=C[i]; } for(int i=0;i<M*N;i++){ if(i==0){ maxr[0]=minr[0]=r[i]; maxc[0]=minc[0]=c[i]; } else{ maxr[i]=max(maxr[i-1],r[i]); maxc[i]=max(maxc[i-1],c[i]); minr[i]=min(minr[i-1],r[i]); minc[i]=min(minc[i-1],c[i]); } if((maxr[i]-minr[i]+1)*(maxc[i]-minc[i]+1)==i+1) last++; } } int swap_seats(int a, int b){ if(a>b) swap(a,b); for(int i=a;i<=b;i++){ if((maxr[i]-minr[i]+1)*(maxc[i]-minc[i]+1)==i+1) last--; } swap(r[a],r[b]); swap(c[a],c[b]); for(int i=a;i<=b;i++){ if(i==0){ maxr[0]=minr[0]=r[i]; maxc[0]=minc[0]=c[i]; } else{ maxr[i]=max(maxr[i-1],r[i]); maxc[i]=max(maxc[i-1],c[i]); minr[i]=min(minr[i-1],r[i]); minc[i]=min(minc[i-1],c[i]); } if((maxr[i]-minr[i]+1)*(maxc[i]-minc[i]+1)==i+1) last++; } return last; }
#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...