Submission #296719

#TimeUsernameProblemLanguageResultExecution timeMemory
296719BruteforcemanSeats (IOI18_seats)C++11
5 / 100
4098 ms29964 KiB
#include "bits/stdc++.h" #include "seats.h" using namespace std; const int maxn = 1e6 + 10; vector <vector <int>> a; vector <int> row, col; int h, w; int arr[maxn]; bool inside(int x, int y) { return (0 <= x && x < h) && (0 <= y && y < w); } bool isOkay(int R) { int total = 0; for(int i = 0; i <= R; i++) { for(int dx : {-1, 1}) { for(int dy : {-1, 1}) { int x = row[i]; int y = col[i]; int cnt = 0; if(!inside(x + dx, y) || a[x + dx][y] > R) ++cnt; if(!inside(x, y + dy) || a[x][y + dy] > R) ++cnt; if(cnt == 2) ++total; } } } for(int i = R + 1; i < h * w; i++) { for(int dx : {-1, 1}) { for(int dy : {-1, 1}) { int x = row[i]; int y = col[i]; int cnt = 0; if(inside(x + dx, y) && a[x + dx][y] <= R) ++cnt; if(inside(x, y + dy) && a[x][y + dy] <= R) ++cnt; if(cnt == 2) ++total; } } } return (total == 4); } void add(int x, int y, int val) { for(int i = x; i <= y; i++) arr[i] += val; } void process(int x, int y, int val) { for(int dx : {-1, 1}) { for(int dy : {-1, 1}) { int r = h * w; if(inside(x + dx, y)) r = min(r, a[x + dx][y]); if(inside(x, y + dy)) r = min(r, a[x][y + dy]); add(a[x][y], r - 1, val); r = 0; if(inside(x + dx, y)) r = max(r, a[x + dx][y]); else r = h * w; if(inside(x, y + dy)) r = max(r, a[x][y + dy]); else r = h * w; add(r, a[x][y] - 1, val); } } } void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { h = H; w = W; a = vector <vector <int>> (H, vector <int> (W, 0)); row = R; col = C; for(int i = 0; i < H * W; i++) { a[row[i]][col[i]] = i; } } int swap_seats(int p, int q) { swap(a[row[p]][col[p]], a[row[q]][col[q]]); swap(row[p], row[q]); swap(col[p], col[q]); int ans = 0; fill(arr, arr + (h * w), 0); for(int i = 0; i < h; i++) { for(int j = 0; j < w; j++) { process(i, j, 1); } } return count(arr, arr + (h * w), 4); }

Compilation message (stderr)

seats.cpp: In function 'int swap_seats(int, int)':
seats.cpp:75:7: warning: unused variable 'ans' [-Wunused-variable]
   75 |   int ans = 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...