Submission #296702

#TimeUsernameProblemLanguageResultExecution timeMemory
296702BruteforcemanSeats (IOI18_seats)C++11
5 / 100
4077 ms43768 KiB
#include "bits/stdc++.h" #include "seats.h" using namespace std; vector <vector <int>> a; vector <int> row, col; int h, w; 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 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; for(int i = 0; i < h * w; i++) { ans += isOkay(i); } 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...