QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#106845 | #6373. Impress Her | ckiseki# | WA | 8ms | 17880kb | C++20 | 2.9kb | 2023-05-19 15:17:48 | 2023-05-19 15:17:51 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef CKISEKI
#define safe cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange(#a, a)
using std::cerr;
template <typename ...T>
void debug_(const char *s, T ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int cnt = sizeof...(T);
(..., (cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename I>
void orange_(const char *s, I L, I R) {
cerr << "\e[1;32m[ " << s << " ] = [ ";
for (int f = 0; L != R; ++L)
cerr << (f++ ? ", " : "") << *L;
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) ((void)0)
#define orange(...) ((void)0)
#endif
#define all(v) begin(v),end(v)
using namespace std;
constexpr int maxc = 1'000'000 + 5;
constexpr int maxn = 500 + 5;
int a[maxn][maxn];
bool exi[maxc];
int x_min[maxc], x_max[maxc];
int y_min[maxc], y_max[maxc];
int v[maxn][maxn];
int vis[maxc], visc;
int main() {
cin.tie(nullptr) -> sync_with_stdio(false);
int n, m; cin >> n >> m;
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
cin >> a[i][j];
for (int i = 0; i < maxc; ++i) {
y_min[i] = m;
x_min[i] = n;
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
const int c = a[i][j];
x_min[c] = min(x_min[c], i);
x_max[c] = max(x_max[c], i);
y_min[c] = min(y_min[c], j);
y_max[c] = max(y_max[c], j);
exi[c] = true;
}
}
for (int c = 0; c < maxc; ++c) {
if (not exi[c]) continue;
v[x_min[c]][y_min[c]] += 1;
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (i > 0) v[i][j] += v[i - 1][j];
if (j > 0) v[i][j] += v[i][j - 1];
if (i > 0 and j > 0) v[i][j] -= v[i - 1][j - 1];
}
}
int64_t ans = 0;
for (int c = 0; c < maxc; ++c) {
if (not exi[c]) continue;
int s = v[x_max[c]][y_max[c]];
if (x_min[c] > 0) s -= v[x_min[c] - 1][y_max[c]];
if (y_min[c] > 0) s -= v[x_max[c]][y_min[c] - 1];
if (x_min[c] > 0 and y_min[c] > 0)
s += v[x_min[c] - 1][y_min[c] - 1];
visc += 1;
auto upd = [&](int x, int y) {
int o = a[x][y];
if (vis[o] == visc) return;
vis[o] = visc;
if (x_min[c] > x_min[o] or x_min[o] > x_max[c])
return;
if (y_min[c] > y_min[o] or y_min[o] > y_max[c])
return;
if (x_min[c] > x_min[o] or x_min[o] > x_max[c] or y_min[c] > y_min[o] or y_min[o] > y_max[c])
s -= 1;
};
for (int j = y_min[c]; j <= y_max[c]; ++j) {
upd(x_min[c], j);
upd(x_max[c], j);
}
for (int i = x_min[c]; i <= x_max[c]; ++i) {
upd(i, y_min[c]);
upd(i, y_max[c]);
}
ans += s - 1;
}
cout << ans << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 15656kb
input:
3 4 1 2 2 4 1 1 1 4 5 1 7 4
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 3ms
memory: 15820kb
input:
1 3 1 2 3
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 3ms
memory: 15784kb
input:
1 3 1 1 3
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 1ms
memory: 15644kb
input:
1 3 2 2 2
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 4ms
memory: 17832kb
input:
1 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 3ms
memory: 17728kb
input:
1 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 25 27 28 29 30
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 0ms
memory: 17640kb
input:
1 30 11 11 11 11 11 11 11 11 11 11 11 11 21 21 21 21 21 21 21 21 21 21 21 21 21 21 21 28 28 28
output:
0
result:
ok 1 number(s): "0"
Test #8:
score: 0
Accepted
time: 2ms
memory: 17744kb
input:
1 200 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 0ms
memory: 15828kb
input:
1 200 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 48 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 68 70 71 72 73 74 75 76 76 78 79 80 81 83 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 0
Accepted
time: 2ms
memory: 15836kb
input:
1 200 1 1 3 4 6 6 7 9 9 10 11 12 13 14 15 16 17 19 19 19 21 22 24 24 26 26 26 28 28 30 31 32 33 34 35 36 36 38 38 40 41 42 43 44 44 46 46 48 49 50 51 53 53 53 55 56 57 58 59 60 60 62 63 63 65 66 67 68 69 70 71 72 73 74 77 77 77 77 79 79 81 82 84 84 84 86 87 88 89 90 92 92 93 95 95 96 97 100 100 100 ...
output:
0
result:
ok 1 number(s): "0"
Test #11:
score: 0
Accepted
time: 1ms
memory: 15652kb
input:
1 200 2 2 2 2 6 6 11 11 11 11 11 11 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 33 33 33 33 33 33 33 33 33 43 43 43 43 43 43 43 43 43 43 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 71 71 71 71 71 71 71 71 71 71 71 85 85 85 85 85 85 85 85 89 89 89 92 92 92 92 92 92 92 92 92 92 ...
output:
0
result:
ok 1 number(s): "0"
Test #12:
score: 0
Accepted
time: 2ms
memory: 15656kb
input:
1 200 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 157 15...
output:
0
result:
ok 1 number(s): "0"
Test #13:
score: 0
Accepted
time: 1ms
memory: 17708kb
input:
1 200 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 136 13...
output:
0
result:
ok 1 number(s): "0"
Test #14:
score: 0
Accepted
time: 3ms
memory: 15772kb
input:
1 200 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 ...
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 3ms
memory: 15660kb
input:
1 200 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 137 13...
output:
0
result:
ok 1 number(s): "0"
Test #16:
score: 0
Accepted
time: 8ms
memory: 17684kb
input:
1 500 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...
output:
0
result:
ok 1 number(s): "0"
Test #17:
score: 0
Accepted
time: 7ms
memory: 15716kb
input:
1 500 1 2 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...
output:
0
result:
ok 1 number(s): "0"
Test #18:
score: 0
Accepted
time: 3ms
memory: 15664kb
input:
1 500 1 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 19 21 21 22 23 24 25 26 27 29 29 30 31 31 33 34 35 36 37 38 39 41 41 42 43 44 45 46 47 48 49 50 51 51 53 54 55 56 57 58 59 60 61 61 64 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 10...
output:
0
result:
ok 1 number(s): "0"
Test #19:
score: 0
Accepted
time: 1ms
memory: 17724kb
input:
1 500 7 7 7 7 7 7 7 9 9 9 11 11 14 14 14 17 17 19 19 19 19 22 23 23 25 26 26 28 29 32 32 32 32 32 32 32 38 38 39 44 44 44 44 44 44 44 44 44 44 44 44 52 52 55 55 55 55 58 58 62 62 62 63 64 65 67 67 67 67 67 67 67 74 74 74 74 74 74 74 74 81 83 83 83 85 86 88 88 88 88 88 88 88 88 88 96 96 96 96 96 101 ...
output:
0
result:
ok 1 number(s): "0"
Test #20:
score: 0
Accepted
time: 0ms
memory: 15676kb
input:
1 500 2 2 2 2 2 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 92 100 100 100 100 100 ...
output:
0
result:
ok 1 number(s): "0"
Test #21:
score: 0
Accepted
time: 1ms
memory: 15708kb
input:
1 500 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 406 40...
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 1ms
memory: 17640kb
input:
1 500 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 15...
output:
0
result:
ok 1 number(s): "0"
Test #23:
score: 0
Accepted
time: 1ms
memory: 15660kb
input:
1 500 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 444 44...
output:
0
result:
ok 1 number(s): "0"
Test #24:
score: 0
Accepted
time: 2ms
memory: 15668kb
input:
3 3 1 2 3 7 5 6 7 8 9
output:
0
result:
ok 1 number(s): "0"
Test #25:
score: 0
Accepted
time: 3ms
memory: 15800kb
input:
3 3 2 2 2 4 5 6 7 7 9
output:
0
result:
ok 1 number(s): "0"
Test #26:
score: 0
Accepted
time: 1ms
memory: 17704kb
input:
3 3 5 5 5 5 5 5 5 5 5
output:
0
result:
ok 1 number(s): "0"
Test #27:
score: 0
Accepted
time: 1ms
memory: 17880kb
input:
3 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 52 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
output:
0
result:
ok 1 number(s): "0"
Test #28:
score: 0
Accepted
time: 3ms
memory: 15812kb
input:
3 30 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 16 18 19 20 21 22 23 24 25 26 26 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
output:
0
result:
ok 1 number(s): "0"
Test #29:
score: -100
Wrong Answer
time: 3ms
memory: 17748kb
input:
3 30 31 38 38 38 38 38 38 38 38 38 73 73 73 73 16 16 16 16 19 85 85 85 85 85 85 85 27 85 85 30 31 32 38 38 38 38 38 38 38 40 73 73 73 73 16 16 16 48 80 85 85 85 85 85 85 85 85 85 85 60 62 62 38 38 65 38 38 38 38 70 71 73 73 73 75 76 77 78 80 80 81 82 82 84 85 85 85 89 89 89
output:
11
result:
wrong answer 1st numbers differ - expected: '10', found: '11'