이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "seats.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int n = 105;
vector <int> r, c;
int rc[n][n], cc[n][n], rz[n], cz[n], res, h, w;
void add(int i, int j) {
if (!rc[i][r[j]]) rz[i]--;
rc[i][r[j]]++;
rc[i][r[j] + 1]--;
if (!rc[i][r[j] + 1]) rz[i]++;
if (!cc[i][c[j]]) cz[i]--;
cc[i][c[j]]++;
cc[i][c[j] + 1]--;
if (!cc[i][c[j] + 1]) cz[i]++;
}
void del(int i, int j) {
rc[i][r[j]]--;
if (!rc[i][r[j]]) rz[i]++;
if (!rc[i][r[j] + 1]) rz[i]--;
rc[i][r[j] + 1]++;
cc[i][c[j]]--;
if (!cc[i][c[j]]) cz[i]++;
if (!cc[i][c[j] + 1]) cz[i]--;
cc[i][c[j] + 1]++;
}
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
r = R, c = C, h = H, w = W;
for (int i = 0; i < H * W; i++) {
rz[i] = H + 1, cz[i] = W + 1;
for (int j = 0; j <= i; j++) {
add(i, j);
}
if (rz[i] == H - 1 && cz[i] == W - 1) res++;
}
}
int swap_seats(int a, int b) {
if (a > b) swap(a, b);
for (int i = a + 1; i < b; i++) {
if (rz[i] == h - 1 && cz[i] == w - 1) res--;
del(i, a);
add(i, b);
if (rz[i] == h - 1 && cz[i] == w - 1) res++;
}
swap(r[a], r[b]);
swap(c[a], c[b]);
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |