QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#522976 | #8830. Breaking Bad | smosp# | WA | 187ms | 11700kb | C++20 | 3.3kb | 2024-08-17 17:41:59 | 2024-08-17 17:42:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for(int i = a; i < (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int a, int b) {
int x = abs((int)rng());
return x % (b - a + 1) + a;
}
const int T = 10;
vi brute_force(int n, vector<vi> &v, int rem) {
vi p(n);
iota(all(p), 0);
vi ans(5, 0);
do {
int x = rem;
rep(i, 0, n) x += v[i][p[i]];
ans[x % 5] = 1;
} while(next_permutation(all(p)));
return ans;
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
// If n <= 10 -> Try all. Easy.
vector<vi> v(n, vi(n));
rep(i, 0, n) rep(j, 0, n) {
cin >> v[i][j];
v[i][j] %= 5;
}
if(n <= T) {
auto ans = brute_force(n, v, 0);
for(auto i : ans) cout << (i == 0 ? 'N' : 'Y');
cout << '\n';
return 0;
}
vector<vi> r(n, vi(5, 0)), c(n, vi(5, 0));
rep(i, 0, n) rep(j, 0, n) {
r[i][v[i][j]]++;
c[j][v[i][j]]++;
}
vi bestr(n), bestc(n);
iota(all(bestr), 0);
iota(all(bestc), 0);
sort(all(bestr), [&](int a, int b) {
int suma = 0;
int sumb = 0;
// int nonzeroa = 0;
// int nonzerob = 0;
rep(i, 0, 5) {
suma += r[a][i] * r[a][i];
sumb += r[b][i] * r[b][i];
// if(r[a][i] != 0) nonzeroa++;
// if(r[b][i] != 0) nonzerob++;
}
return suma < sumb;
});
sort(all(bestc), [&](int a, int b) {
int suma = 0;
int sumb = 0;
rep(i, 0, 5) {
suma += c[a][i] * c[a][i];
sumb += c[b][i] * c[b][i];
}
return suma < sumb;
});
// Now we can try random cases based on this "variation" index.
int rem = 0;
rep(i, T, n) {
rem += v[bestr[i]][bestc[i]];
}
vector<vi> t(T, vi(T));
rep(i, 0, T) rep(j, 0, T) {
t[i][j] = v[bestr[i]][bestc[j]];
}
auto ans = brute_force(T, t, rem);
{
reverse(all(bestr));
reverse(all(bestc));
int rem = 0;
rep(i, T, n) {
rem += v[bestr[i]][bestc[i]];
}
vector<vi> t(T, vi(T));
rep(i, 0, T) rep(j, 0, T) {
t[i][j] = v[bestr[i]][bestc[j]];
}
auto ans2 = brute_force(T, t, rem);
rep(i, 0, 5) ans[i] += ans2[i];
}
reverse(all(bestr));
reverse(all(bestc));
rep(_, 0, 4) {
int tt = min(T*2, n);
shuffle(bestr.begin(), bestr.begin() + tt, rng);
shuffle(bestc.begin(), bestc.begin() + tt, rng);
int rem = 0;
rep(i, T, n) {
rem += v[bestr[i]][bestc[i]];
}
vector<vi> t(T, vi(T));
rep(i, 0, T) rep(j, 0, T) {
t[i][j] = v[bestr[i]][bestc[j]];
}
auto ans2 = brute_force(T, t, rem);
rep(i, 0, 5) ans[i] += ans2[i];
}
rep(_, 0, 10) {
shuffle(all(bestr), rng);
shuffle(all(bestc), rng);
vi a(5, 0);
int rem = 0;
for(int i = 0; i< 5; i += 5) {
if(i + 5 >= n) {
int x = 0;
while(i + x < n) rem += v[bestr[i + x]][bestc[i + x]];
break;
}
vector<vi> z(5, vi(5));
rep(x, 0, 5) rep(y, 0, 5) z[x][y] = v[bestr[i + x]][bestc[i + y]];
auto temp = brute_force(5, z, 0);
vi b(5, 0);
rep(i, 0, 5) rep(j, 0, 5) b[(i + j) % 5] += (a[i] + temp[j]);
}
vi b(5, 0);
rep(i, 0, 5) b[(i + rem) % 5] = a[i];
rep(i, 0, 5) ans[i] += b[i];
}
for(auto i : ans) cout << (i == 0 ? 'N' : 'Y');
cout << '\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3880kb
input:
2 0 4 4 0
output:
YNNYN
result:
ok "YNNYN"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
2 1 1 1 1
output:
NNYNN
result:
ok "NNYNN"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
4 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0
output:
YYYYN
result:
ok "YYYYN"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
4 0 0 0 1 0 1 0 1 1 0 0 0 0 1 0 0
output:
YYYYN
result:
ok "YYYYN"
Test #5:
score: 0
Accepted
time: 27ms
memory: 3648kb
input:
10 1 4 2 0 0 2 0 1 3 3 0 3 1 4 4 1 4 0 2 2 1 4 2 0 0 2 0 1 0 3 0 3 1 4 4 1 4 0 2 2 4 2 0 3 3 0 3 4 1 1 2 0 3 1 1 3 1 2 4 4 4 2 0 3 3 0 3 4 1 1 2 0 3 1 1 3 1 2 4 4 1 4 2 0 0 2 0 1 3 3 3 1 4 2 2 4 2 3 0 0
output:
NYNNY
result:
ok "NYNNY"
Test #6:
score: 0
Accepted
time: 26ms
memory: 3640kb
input:
10 4 4 4 1 3 4 1 4 3 0 3 3 3 0 2 3 0 3 2 4 3 3 3 0 2 3 0 3 2 4 4 4 4 1 3 4 1 4 3 0 2 2 2 4 1 2 4 2 1 3 2 2 2 4 1 3 4 2 1 3 4 4 4 1 3 4 1 4 3 0 3 3 3 0 2 3 0 3 2 4 2 2 2 4 1 2 4 2 1 3 4 4 4 1 3 4 1 1 3 0
output:
YYYNY
result:
ok "YYYNY"
Test #7:
score: 0
Accepted
time: 26ms
memory: 3652kb
input:
10 1 2 0 4 2 3 4 0 2 3 0 1 4 3 1 2 3 4 1 2 4 0 3 2 0 1 2 3 0 1 1 2 0 4 2 3 4 0 2 3 3 4 2 1 4 0 1 2 4 0 0 1 4 3 1 2 3 4 1 2 2 3 1 0 3 4 0 1 3 4 3 1 1 1 4 0 1 2 4 0 1 2 0 4 2 3 4 0 2 3 1 3 0 4 2 3 4 0 2 3
output:
NYYYY
result:
ok "NYYYY"
Test #8:
score: 0
Accepted
time: 26ms
memory: 3684kb
input:
10 3 4 0 3 2 2 0 4 0 2 0 1 2 0 4 4 2 1 2 4 2 3 4 2 1 1 4 3 4 1 0 1 2 0 4 4 2 1 2 4 0 1 2 0 4 4 2 1 2 4 0 1 2 0 4 4 2 1 2 4 3 4 0 3 2 2 0 4 0 2 0 1 2 0 4 4 2 1 2 4 3 4 0 3 2 2 0 4 0 2 0 1 2 0 4 4 2 1 2 4
output:
NYNNN
result:
ok "NYNNN"
Test #9:
score: 0
Accepted
time: 27ms
memory: 3620kb
input:
10 4 1 3 1 2 0 3 2 4 4 0 2 4 2 3 1 4 3 0 0 1 1 1 1 2 0 3 2 4 1 2 4 1 4 0 3 1 0 2 2 1 3 0 3 4 2 0 4 1 1 2 4 1 4 0 3 1 0 2 2 2 4 1 4 0 3 1 0 2 2 0 2 4 2 3 1 4 3 0 0 3 0 2 1 1 4 2 1 3 3 4 1 3 1 2 0 3 2 4 4
output:
YYYYY
result:
ok "YYYYY"
Test #10:
score: 0
Accepted
time: 27ms
memory: 3876kb
input:
10 1 2 0 2 4 2 3 1 2 1 4 0 3 0 2 0 1 4 0 4 0 1 4 1 3 1 2 0 1 0 0 1 4 1 3 1 2 0 1 0 3 4 2 4 1 4 0 3 4 3 4 0 3 0 2 0 1 4 0 4 0 1 4 1 3 1 2 0 1 0 0 1 4 1 3 1 2 0 1 0 3 4 2 4 1 4 0 3 4 3 0 1 4 1 3 1 2 0 1 0
output:
NNNYN
result:
ok "NNNYN"
Test #11:
score: 0
Accepted
time: 28ms
memory: 3844kb
input:
10 1 4 1 2 1 3 3 2 1 2 0 3 0 1 0 2 2 1 0 1 0 4 0 3 0 2 2 1 0 1 1 4 1 2 1 3 3 2 1 2 4 2 4 0 4 1 1 0 4 0 1 1 1 4 1 0 3 2 1 2 0 0 0 1 0 2 2 1 0 1 2 0 2 3 2 4 4 3 2 3 2 0 2 3 2 4 4 3 2 3 2 0 2 3 2 4 4 3 2 3
output:
YYYYY
result:
ok "YYYYY"
Test #12:
score: 0
Accepted
time: 23ms
memory: 3648kb
input:
10 1 2 0 1 4 0 1 2 2 2 1 2 0 1 4 3 1 2 2 2 0 1 4 0 3 1 0 1 1 1 1 2 0 1 4 3 1 2 2 2 3 4 2 3 1 4 3 4 4 4 0 1 4 0 3 1 0 1 1 1 4 0 3 4 2 0 4 0 0 0 3 4 2 3 1 4 3 4 4 4 4 0 3 4 2 0 4 0 0 0 0 1 4 0 3 1 0 1 1 1
output:
YNYNY
result:
ok "YNYNY"
Test #13:
score: 0
Accepted
time: 23ms
memory: 3644kb
input:
10 1 3 0 0 2 1 3 4 3 3 3 3 0 0 4 1 3 4 3 3 1 1 3 3 2 4 1 2 1 1 2 4 1 1 3 2 4 0 4 4 4 1 3 3 0 4 1 2 1 1 2 4 1 1 3 2 4 0 4 4 0 2 4 4 1 0 2 3 2 2 3 0 2 2 4 3 0 1 0 0 3 0 2 2 4 3 0 1 0 0 4 2 4 4 1 0 2 3 2 2
output:
YYYNY
result:
ok "YYYNY"
Test #14:
score: 0
Accepted
time: 27ms
memory: 3812kb
input:
10 2 0 3 1 3 0 0 0 4 1 1 4 2 0 2 4 4 4 3 0 2 0 3 1 3 0 0 0 4 1 1 4 2 0 2 4 4 4 3 0 1 4 2 0 2 4 4 4 3 0 3 3 4 2 4 1 1 1 0 2 3 1 4 2 4 1 1 1 0 2 4 2 0 3 0 2 2 2 1 3 3 1 4 2 4 1 1 1 0 2 1 4 2 0 2 4 4 4 3 0
output:
YNYNN
result:
ok "YNYNN"
Test #15:
score: 0
Accepted
time: 182ms
memory: 11700kb
input:
1000 3 4 1 2 4 1 0 3 0 4 1 4 3 1 4 4 1 0 1 2 3 1 0 1 3 4 4 0 3 0 3 2 2 1 0 4 1 3 3 0 3 1 3 2 2 0 3 3 2 2 3 0 4 2 1 2 1 2 1 4 2 4 1 4 2 4 3 2 0 3 0 4 2 1 2 3 3 0 2 0 3 3 1 1 0 3 4 3 2 0 4 0 3 4 4 2 3 4 2 3 4 2 1 3 2 2 4 1 0 2 2 4 0 1 2 0 4 1 3 2 3 2 2 2 1 4 4 4 2 0 0 4 4 1 3 4 0 2 2 3 1 1 3 2 3 2 3 0...
output:
NNNYN
result:
ok "NNNYN"
Test #16:
score: -100
Wrong Answer
time: 187ms
memory: 11700kb
input:
1000 2 3 0 1 0 0 0 1 1 4 1 4 2 3 0 3 4 2 3 2 4 2 1 1 1 1 0 0 3 3 2 0 2 2 2 4 3 0 3 3 3 0 1 3 0 2 0 1 0 0 0 3 1 4 3 1 4 0 3 4 4 1 3 3 4 0 1 4 2 3 0 1 0 0 2 3 1 4 0 0 2 1 2 3 3 4 4 3 3 2 0 0 4 3 2 3 3 2 4 0 2 2 3 0 3 2 4 1 0 2 4 2 4 1 2 1 3 0 3 3 0 1 1 0 2 3 0 2 4 1 4 3 4 1 2 2 2 4 0 1 3 3 0 0 1 3 2 4...
output:
NYNNN
result:
wrong answer 1st words differ - expected: 'NYYYY', found: 'NYNNN'