제출 #296732

#제출 시각아이디문제언어결과실행 시간메모리
296732Bruteforceman자리 배치 (IOI18_seats)C++11
11 / 100
4100 ms48820 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; } fill(arr, arr + (h * w), 0); for(int i = 0; i < h; i++) { for(int j = 0; j < w; j++) { process(i, j, 1); } } } const int dx[] = {0, 0, -1, 1}; const int dy[] = {-1, 1, 0, 0}; int swap_seats(int p, int q) { int ans = 0; set <pair <int, int>> change; change.insert(make_pair(row[p], col[p])); change.insert(make_pair(row[q], col[q])); for(int i = 0; i < 4; i++) { int x = row[p] + dx[i]; int y = col[p] + dy[i]; if(inside(x, y)) change.insert(make_pair(x, y)); } for(int i = 0; i < 4; i++) { int x = row[q] + dx[i]; int y = col[q] + dy[i]; if(inside(x, y)) change.insert(make_pair(x, y)); } for(auto i : change) { process(i.first, i.second, -1); } swap(a[row[p]][col[p]], a[row[q]][col[q]]); swap(row[p], row[q]); swap(col[p], col[q]); for(auto i : change) { process(i.first, i.second, 1); } return count(arr, arr + (h * w), 4); }

컴파일 시 표준 에러 (stderr) 메시지

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