Submission #229956

#TimeUsernameProblemLanguageResultExecution timeMemory
229956fedoseevtimofeySeats (IOI18_seats)C++14
5 / 100
4078 ms27896 KiB
#include "seats.h" #include <iostream> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> #include <random> #include <iomanip> #include <functional> #include <cassert> using namespace std; typedef long long ll; vector <vector <int>> a; vector <int> r, c; int n, m; void give_initial_chart(int N, int M, vector<int> R, vector<int> C) { n = N, m = M; r = R, c = C; a.resize(n, vector <int> (m)); for (int i = 0; i < n * m; ++i) { a[r[i]][c[i]] = i; } } bool ok(int x, int y) { return 0 <= x && x < n && 0 <= y && y < m; } int swap_seats(int x, int y) { swap(a[r[x]][c[x]], a[r[y]][c[y]]); swap(r[x], r[y]); swap(c[x], c[y]); vector <vector <int>> have(n, vector <int> (m)); int ans = 0; for (int x = 0; x < n * m; ++x) { have[r[x]][c[x]] = 1; bool bad = false; int cnt = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (have[i][j]) continue; int cur = 0; for (int dx = -1; dx <= 1; ++dx) { for (int dy = -1; dy <= 1; ++dy) { if (dx * dx + dy * dy == 1) { int nx = i + dx, ny = j + dy; if (ok(nx, ny) && have[nx][ny]) ++cur; } } } if (cur > 1) bad = true; } } for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (!have[i][j]) continue; int cur = 0; for (int dx = -1; dx <= 1; ++dx) { for (int dy = -1; dy <= 1; ++dy) { if (dx * dx + dy * dy == 1) { int nx = i + dx, ny = j + dy; if (!ok(nx, ny)) ++cur; else if (!have[nx][ny]) ++cur; } } } if (cur == 2) ++cnt; if (cur > 2) bad = true; } } if (cnt != 4) bad = true; if (!bad) { ++ans; } } int min_r = n, max_r = 0, min_c = m, max_c = 0; for (int i = 0; i < n * m; ++i) { min_r = min(min_r, r[i]); max_r = max(max_r, r[i]); min_c = min(min_c, c[i]); max_c = max(max_c, c[i]); if ((min_r == max_r || min_c == max_c) && (max_r - min_r + 1) * (max_c - min_c + 1) == i + 1) { ++ans; } } return ans; } #ifdef LOCAL int main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, m, q; cin >> n >> m >> q; vector <int> R(n * m), C(n * m); for (int i = 0; i < n * m; ++i) { cin >> R[i] >> C[i]; } vector <int> aq(q), bq(q); for (int i = 0; i < q; ++i) { cin >> aq[i] >> bq[i]; } give_initial_chart(n, m, R, C); for (int j = 0; j < q; ++j) { cout << swap_seats(aq[j], bq[j]) << '\n'; } } #endif
#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...