Submission #1111543

#TimeUsernameProblemLanguageResultExecution timeMemory
1111543SalihSahinSeats (IOI18_seats)C++14
0 / 100
4037 ms43848 KiB
#include <bits/stdc++.h>
#define pb push_back
#include "seats.h"
using namespace std;

vector<vector<int> > r;
vector<pair<int, int> > pos; 

void give_initial_chart(int H, int W, vector<int> R, vector<int> C){
  r.resize(H);
  for(int i = 0; i < H; i++){
    r[i].resize(W);
  }
  pos.resize(H * W);

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      r[i][j] = R[i * W + j] * W + C[i * W + j];
      pos[R[i * W + j] * W + C[i * W + j]] = {i, j};
    }
  }
}

int swap_seats(int a, int b) {
  pair<int, int> posa = pos[a], posb = pos[b];

  r[posa.first][posa.second] = b;
  r[posb.first][posb.second] = a;
  swap(pos[a], pos[b]);

  int w = r[0].size(), h = pos.size() / w;
  int mnx = h + w, mxx = 0, mny = h + w, mxy = 0;

  int ans = 0;
  for(int i = 0; i < h * w; i++){
    mnx = min(mnx, pos[i].second);
    mxx = max(mxx, pos[i].second);
    mny = min(mny, pos[i].first);
    mxy = max(mxy, pos[i].first);

    if((mxx - mnx + 1) * (mxy - mny + 1) == (i + 1)){
      ans++;
      //cout<<i<<" .."<<endl;
    }
  }

  return ans;
}
#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...