QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#101878 | #5446. 琪露诺的符卡交换 | hos_lyric | 40 | 7ms | 4132kb | C++14 | 3.8kb | 2023-05-01 15:48:10 | 2023-05-01 15:48:12 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
int N;
int A[210][210];
struct Op {
int i0, j0, i1, j1;
};
int ansLen;
Op ans[20010];
namespace sub1 {
bool validate() {
for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) {
if (A[i][0] != A[i][j]) return false;
}
return true;
}
void run() {
for (int i = 0; i < N; ++i) for (int j = i + 1; j < N; ++j) {
ans[ansLen++] = Op{i, j, j, i};
}
}
} // sub1
namespace sub2 {
vector<int> P, Q, J;
bool validate() {
assert(N >= 2);
P.assign(N, -1);
Q.assign(N, -1);
J.assign(N, -1);
for (int i = 0; i < N; ++i) {
vector<int> freq(N, 0);
for (int j = 0; j < N; ++j) {
++freq[A[i][j]];
}
P[i] = max_element(freq.begin(), freq.end()) - freq.begin();
if (freq[P[i]] == N) {
Q[i] = P[i];
J[i] = 0;
} else if (freq[P[i]] == N - 1) {
for (int j = 0; j < N; ++j) if (P[i] != A[i][j]) {
Q[i] = A[i][j];
J[i] = j;
break;
}
assert(~Q[i]);
} else {
return false;
}
}
cerr<<"[sub2] P = "<<P<<", Q = "<<Q<<", J = "<<J<<endl;
return true;
}
bool adj[210][210];
void run() {
vector<int> invP(N, -1), invQ(N, -1);
for (int i = 0; i < N; ++i) {
invP[P[i]] = i;
invQ[Q[i]] = i;
}
vector<vector<int>> jss(N);
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) if (J[i] != j) {
jss[i].push_back(j);
}
jss[i].push_back(J[i]);
}
for (int i0 = 0; i0 < N; ++i0) for (int i1 = i0 + 1; i1 < N; ++i1) {
ans[ansLen++] = Op{i0, jss[i0][i1], i1, jss[i1][i0]};
}
}
} // sub1
int main() {
for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
scanf("%d", &N);
for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) {
scanf("%d", &A[i][j]);
--A[i][j];
}
ansLen = 0;
if (sub1::validate()) {
sub1::run();
} else if (sub2::validate()) {
sub2::run();
} else {
// HELP
puts("-1");
continue;
}
printf("%d\n", ansLen);
for (int h = 0; h < ansLen; ++h) {
printf("%d %d %d %d\n", ans[h].i0 + 1, ans[h].j0 + 1, ans[h].i1 + 1, ans[h].j1 + 1);
}
#ifdef LOCAL
int oped[210][210]={};
for(int h=0;h<ansLen;++h){
assert(!oped[ans[h].i0][ans[h].j0]++);
assert(!oped[ans[h].i1][ans[h].j1]++);
swap(A[ans[h].i0][ans[h].j0],A[ans[h].i1][ans[h].j1]);
}
cerr<<"A = "<<endl;for(int i=0;i<N;++i)pv(A[i],A[i]+N);
for(int i=0;i<N;++i){
vector<int>freq(N,0);
for(int j=0;j<N;++j)++freq[A[i][j]];
for(int a=0;a<N;++a)assert(freq[a]==1);
}
#endif
}
#ifndef LOCAL
break;
#endif
}
return 0;
}
详细
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 5ms
memory: 3768kb
input:
7 132 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 ...
output:
8646 1 2 2 1 1 3 3 1 1 4 4 1 1 5 5 1 1 6 6 1 1 7 7 1 1 8 8 1 1 9 9 1 1 10 10 1 1 11 11 1 1 12 12 1 1 13 13 1 1 14 14 1 1 15 15 1 1 16 16 1 1 17 17 1 1 18 18 1 1 19 19 1 1 20 20 1 1 21 21 1 1 22 22 1 1 23 23 1 1 24 24 1 1 25 25 1 1 26 26 1 1 27 27 1 1 28 28 1 1 29 29 1 1 30 30 1 1 31 31 1 1 32 32 1 1...
result:
ok your solution is correct.
Test #2:
score: 0
Accepted
time: 1ms
memory: 3816kb
input:
8 14 13 13 13 13 13 13 13 13 13 13 13 13 13 13 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 8 8 8 14 14 14 14 14 14 14 14 14 14 14 14 14 14 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 10 10 10 10 10 10 10 10 10 10 10 10 10 10 2 2 2 2 2 2 2 2 2 2 2 2 2 2 9...
output:
91 1 2 2 1 1 3 3 1 1 4 4 1 1 5 5 1 1 6 6 1 1 7 7 1 1 8 8 1 1 9 9 1 1 10 10 1 1 11 11 1 1 12 12 1 1 13 13 1 1 14 14 1 2 3 3 2 2 4 4 2 2 5 5 2 2 6 6 2 2 7 7 2 2 8 8 2 2 9 9 2 2 10 10 2 2 11 11 2 2 12 12 2 2 13 13 2 2 14 14 2 3 4 4 3 3 5 5 3 3 6 6 3 3 7 7 3 3 8 8 3 3 9 9 3 3 10 10 3 3 11 11 3 3 12 12 3...
result:
ok your solution is correct.
Test #3:
score: 0
Accepted
time: 3ms
memory: 3752kb
input:
4 82 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 1...
output:
3321 1 2 2 1 1 3 3 1 1 4 4 1 1 5 5 1 1 6 6 1 1 7 7 1 1 8 8 1 1 9 9 1 1 10 10 1 1 11 11 1 1 12 12 1 1 13 13 1 1 14 14 1 1 15 15 1 1 16 16 1 1 17 17 1 1 18 18 1 1 19 19 1 1 20 20 1 1 21 21 1 1 22 22 1 1 23 23 1 1 24 24 1 1 25 25 1 1 26 26 1 1 27 27 1 1 28 28 1 1 29 29 1 1 30 30 1 1 31 31 1 1 32 32 1 1...
result:
ok your solution is correct.
Test #4:
score: 0
Accepted
time: 3ms
memory: 4064kb
input:
8 3 1 1 1 3 3 3 2 2 2 3 1 1 1 3 3 3 2 2 2 1 1 11 5 5 5 5 5 5 5 5 5 5 5 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 9 9 9 9 9 9 9 9 9 9 9 4 4 4 4 4 4 4 4 4 4 4 11 11 11 11 11 11 11 11 11 11 11 2 2 2 2 2 2 2 2 2 2 2 6 6 6 6 6 6 6 6 6 6 6 8 8 8 8 8 8 8 8 8 8 8 10 10 10 10 10 10 10 10 10 10 10 7 7 7 7 7...
output:
3 1 2 2 1 1 3 3 1 2 3 3 2 3 1 2 2 1 1 3 3 1 2 3 3 2 0 55 1 2 2 1 1 3 3 1 1 4 4 1 1 5 5 1 1 6 6 1 1 7 7 1 1 8 8 1 1 9 9 1 1 10 10 1 1 11 11 1 2 3 3 2 2 4 4 2 2 5 5 2 2 6 6 2 2 7 7 2 2 8 8 2 2 9 9 2 2 10 10 2 2 11 11 2 3 4 4 3 3 5 5 3 3 6 6 3 3 7 7 3 3 8 8 3 3 9 9 3 3 10 10 3 3 11 11 3 4 5 5 4 4 6 6 4...
result:
ok your solution is correct.
Subtask #2:
score: 20
Accepted
Dependency #1:
100%
Accepted
Test #5:
score: 20
Accepted
time: 7ms
memory: 4132kb
input:
5 17 9 9 9 9 9 9 9 9 9 9 9 9 9 2 9 9 9 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 2 2 2 2 2 2 2 2 2 2 2 2 11 2 2 2 2 4 4 4 4 4 4 10 4 4 4 4 4 4 4 4 4 4 10 10 10 10 10 10 8 10 10 10 10 10 10 10 10 10 10 12 12 12 12 12 12 12 12 12 12 12 12 14 12 12 12 12 14 14 14 14 14 14 14 14 14 14 14 12 14 14 14 14 14 16 16...
output:
136 1 2 2 1 1 3 3 1 1 4 4 1 1 5 5 1 1 6 6 1 1 7 7 1 1 8 8 1 1 9 9 1 1 10 10 1 1 11 11 1 1 12 12 1 1 13 13 1 1 15 14 1 1 16 15 1 1 17 16 1 1 14 17 1 2 3 3 2 2 4 4 2 2 5 5 2 2 6 6 2 2 7 7 2 2 8 8 2 2 9 9 3 2 10 10 2 2 11 11 3 2 12 12 3 2 13 13 2 2 14 14 2 2 15 15 2 2 16 16 2 2 17 17 2 3 4 4 3 3 5 5 3 ...
result:
ok your solution is correct.
Test #6:
score: 0
Accepted
time: 7ms
memory: 4012kb
input:
9 1 1 28 2 2 2 2 5 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 7 24 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 8 13 13 13 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 16 8 8 8 8 8 8 8 8 8 8 8 8 17 24 24 24 24 24 24 24 24 24 24 24 24...
output:
0 378 1 2 2 1 1 3 3 1 1 4 4 1 1 6 5 2 1 7 6 1 1 8 7 2 1 9 8 1 1 10 9 1 1 11 10 1 1 12 11 2 1 13 12 1 1 14 13 1 1 15 14 1 1 16 15 1 1 17 16 1 1 18 17 1 1 19 18 1 1 20 19 1 1 21 20 1 1 22 21 1 1 23 22 1 1 24 23 1 1 25 24 1 1 26 25 1 1 27 26 1 1 28 27 2 1 5 28 1 2 4 3 2 2 5 4 2 2 6 5 3 2 7 6 2 2 8 7 3 ...
result:
ok your solution is correct.
Test #7:
score: 0
Accepted
time: 3ms
memory: 3900kb
input:
9 22 19 19 19 19 19 19 19 19 19 10 19 19 19 19 19 19 19 19 19 19 19 19 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 8 21 21 21 21 21 21 21 21 5 21 21 21 21 21 21 21 21 21 21 21 21 21 12 12 12 12 12 12 12 22 12 12 12 12 12 12 12 12 12 12 12 12 12 12 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3...
output:
231 1 2 2 1 1 3 3 1 1 4 4 1 1 5 5 1 1 6 6 1 1 7 7 1 1 8 8 1 1 9 9 2 1 11 10 1 1 12 11 1 1 13 12 1 1 14 13 1 1 15 14 1 1 16 15 1 1 17 16 1 1 18 17 1 1 19 18 1 1 20 19 1 1 21 20 1 1 22 21 1 1 10 22 1 2 3 3 2 2 4 4 2 2 5 5 2 2 6 6 2 2 7 7 3 2 8 8 2 2 9 9 3 2 10 10 2 2 11 11 2 2 12 12 2 2 13 13 3 2 14 1...
result:
ok your solution is correct.
Test #8:
score: 0
Accepted
time: 5ms
memory: 3744kb
input:
8 29 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 6 3 3 3 3 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 3 11 11 11 11 11 11 11 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 23 1 1 1 1 1 1 1 20 20 20 20 20 20 20 20 20 20 20 25 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 26 26...
output:
406 1 2 2 1 1 3 3 1 1 4 4 1 1 5 5 1 1 6 6 1 1 7 7 1 1 8 8 1 1 9 9 1 1 10 10 1 1 11 11 1 1 12 12 1 1 13 13 1 1 14 14 1 1 15 15 1 1 16 16 1 1 17 17 1 1 18 18 1 1 19 19 1 1 20 20 1 1 21 21 1 1 22 22 1 1 23 23 1 1 24 24 1 1 26 25 1 1 27 26 1 1 28 27 1 1 29 28 1 1 25 29 1 2 3 3 2 2 4 4 2 2 5 5 2 2 6 6 2 ...
result:
ok your solution is correct.
Subtask #3:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #9:
score: 0
Wrong Answer
time: 2ms
memory: 3612kb
input:
19 1 1 2 1 2 1 2 3 1 3 2 2 3 1 2 1 3 4 1 4 3 4 3 2 2 1 3 1 2 3 4 4 1 2 5 4 2 1 5 4 4 5 4 4 1 5 3 2 3 2 3 1 3 2 1 3 1 2 5 5 6 6 2 2 1 6 6 2 5 5 3 4 6 1 2 4 2 6 1 4 4 1 4 5 1 1 2 6 5 3 5 5 3 3 3 3 4 7 5 2 3 6 4 2 7 2 1 6 1 1 5 2 1 6 7 7 5 1 2 6 6 3 4 4 7 1 3 6 5 7 3 2 7 3 2 5 1 4 5 4 5 3 3 7 4 4 6 8 1...
output:
0 1 1 2 2 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
result:
wrong answer exist a kind of card which a person don't hold.