This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "seats.h"
using namespace std;
using ll = long long;
int h, w;
std::vector<int> r, c;
vector<vector<int>> arr;
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
h = H;
w = W;
r = R;
c = C;
arr = vector(H, vector<int>(W, 0));
for (int i = 0; i < H * W; i++)
arr[r[i]][c[i]] = i;
#ifdef ONPC
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
cout << arr[i][j] << " \n"[j == W-1];
#endif
}
ll sum(int r1, int c1, int r2, int c2) {
ll res = 0;
for (int i = r1; i <= r2; i++) {
for (int j = c1; j <= c2; j++) {
res += arr[i][j];
}
}
return res;
}
int swap_seats(int a, int b) {
swap(arr[r[a]][c[a]], arr[r[b]][c[b]]);
swap(r[a], r[b]);
swap(c[a], c[b]);
int ans = 0;
for (int r1 = 0; r1 < h; r1++) {
for (int r2 = r1; r2 < h; r2++) {
for (int c1 = 0; c1 < w; c1++) {
for (int c2 = c1; c2 < w; c2++) {
ll k = (r2 - r1 + 1) * (c2 - c1 + 1);
if (sum(r1, c1, r2, c2) == k * (k-1) / 2)
ans ++;
}
}
}
}
return ans;
}
# | 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... |