QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#667217 | #5520. Distance Parities | xhytom# | WA | 9ms | 5856kb | C++23 | 3.2kb | 2024-10-22 21:40:18 | 2024-10-22 21:40:37 |
Judging History
answer
/*
_/ _/ _/ _/ _/ _/ _/_/_/_/_/ _/_/ _/ _/
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/_/ _/_/
_/_/ _/_/_/_/_/ _/ _/ _/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/ _/_/ _/ _/
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
using i64 = long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define multi int _;cin>>_;while(_--)
#define debug(x) cerr << #x << " = " << (x) << endl;
#define int long long
#define pb push_back
#define eb emplace_back
ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}
mt19937_64 mrand(chrono::steady_clock().now().time_since_epoch().count());
int rnd(int l,int r){ return mrand() % (r - l + 1) + l;}
void test() {cerr << "\n";}
template<typename T, typename... Args>
void test(T x, Args... args) {cerr << x << " ";test(args...);}
const ll MOD = 998244353;
// const ll MOD = 1e9+7;
ll ksm(ll x,ll y){ll ans=1;x%=MOD;while(y){if(y&1)ans=ans*x%MOD;x=x*x%MOD,y/=2;}return ans;}
const int P1 = 972152273, base1 = 809;
const int P2 = 905563261, base2 = 919;
const ll N = 200005;
//head
struct DSU {
std::vector<int> f, siz;
DSU(int n) : f(n), siz(n, 1) { std::iota(f.begin(), f.end(), 0); }
int leader(int x) {
while (x != f[x]) x = f[x] = f[f[x]];
return x;
}
bool same(int x, int y) { return leader(x) == leader(y); }
bool merge(int x, int y) {
x = leader(x);
y = leader(y);
if (x == y) return false;
siz[x] += siz[y];
f[y] = x;
return true;
}
int size(int x) { return siz[leader(x)]; }
};
void solve(int testcase) {
int n;
std::cin >> n;
std::vector<std::vector<int>> a(n + 2, std::vector<int> (n + 2));
DSU dsu(n + 1);
int cnt = 0;
for (int i = 1; i <= n; i++) {
std::string s;
std::cin >> s;
for (int j = 1; j <= n; j++) {
a[i][j] = s[j - 1] - '0';
if (a[i][j] == 1) {
cnt += dsu.merge(i, j);
}
}
}
for (int i = 1; i <= n; i++) {
if (a[i][i] == 1) {
std::cout << "NO\n";
return;
}
}
if (cnt + 1 == n) {
std::cout << "YES\n";
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
ans += a[i][j];
}
}
std::cout << ans << "\n";
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (a[i][j]) {
std::cout << i << " " << j << "\n";
}
}
}
} else {
std::cout << "NO\n";
}
}
signed main()
{
#ifdef localfreopen
// freopen("1.in","r",stdin);
#endif
fastio
std::cout << std::fixed << std::setprecision(10);
int t;
cin >> t;
for(int i = 1 ; i <= t ; i++ )
{
solve(i);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
input:
3 3 011 101 110 4 0100 1000 0001 0010 5 01010 10101 01010 10101 01010
output:
YES 3 1 2 1 3 2 3 NO YES 6 1 2 1 4 2 3 2 5 3 4 4 5
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 4ms
memory: 5552kb
input:
1 500 001001010000101001100000100011101011010001100110010000011000001100000011010001001111001010010101110100000100011000110111100010001000010111111000000101101010011111000010110010111100111110111000010000100100010010001110000100111000001111101011111101111110111110001000111110001011111100110011100100...
output:
YES 62433 1 3 1 6 1 8 1 13 1 15 1 18 1 19 1 25 1 29 1 30 1 31 1 33 1 35 1 36 1 38 1 42 1 43 1 46 1 47 1 50 1 56 1 57 1 63 1 64 1 71 1 72 1 74 1 78 1 81 1 82 1 83 1 84 1 87 1 89 1 92 1 94 1 96 1 97 1 98 1 100 1 106 1 110 1 111 1 115 1 116 1 118 1 119 1 120 1 121 1 125 1 129 1 134 1 136 1 137 1 138 1 ...
result:
ok Correct (1 test case)
Test #3:
score: 0
Accepted
time: 6ms
memory: 5784kb
input:
1 500 001010100000100110111000011101101110001000011110011000010011000000101110000011111110111000110110011111011101110010011100101110001000001010010011000011101000011110110101001010010110110001111101101100001100010110011100010001001011100111011001101110011010010001011101011110010111010011111001100101...
output:
YES 62414 1 3 1 5 1 7 1 13 1 16 1 17 1 19 1 20 1 21 1 26 1 27 1 28 1 30 1 31 1 33 1 34 1 35 1 39 1 44 1 45 1 46 1 47 1 50 1 51 1 56 1 59 1 60 1 67 1 69 1 70 1 71 1 77 1 78 1 79 1 80 1 81 1 82 1 83 1 85 1 86 1 87 1 91 1 92 1 94 1 95 1 98 1 99 1 100 1 101 1 102 1 104 1 105 1 106 1 108 1 109 1 110 1 11...
result:
ok Correct (1 test case)
Test #4:
score: 0
Accepted
time: 8ms
memory: 5856kb
input:
1 500 000110110101000000010111101011000001000011001001010001010100011101011111111111001010101010111001011110000000001100010001011110101100000001001000110000101011010111110101001101100000111111100011001000000111110001011101101000001101100001011100000000011101011011011011011011000010110111101111010101...
output:
YES 62389 1 4 1 5 1 7 1 8 1 10 1 12 1 20 1 22 1 23 1 24 1 25 1 27 1 29 1 30 1 36 1 41 1 42 1 45 1 48 1 50 1 54 1 56 1 58 1 62 1 63 1 64 1 66 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 1 76 1 77 1 78 1 81 1 83 1 85 1 87 1 89 1 91 1 92 1 93 1 96 1 98 1 99 1 100 1 101 1 111 1 112 1 116 1 120 1 122 1 123 1...
result:
ok Correct (1 test case)
Test #5:
score: 0
Accepted
time: 9ms
memory: 5596kb
input:
1 500 000111010001001110011010011100010100001101111101011100111011100000001010111010111100111011011110010111011000111100111011010100110101001010111001000101101100010111101010100101000000011001001110010000101010111100001000011111111110111000110110010010100000110000001010111111010111011100100101010110...
output:
YES 62423 1 4 1 5 1 6 1 8 1 12 1 15 1 16 1 17 1 20 1 21 1 23 1 26 1 27 1 28 1 32 1 34 1 39 1 40 1 42 1 43 1 44 1 45 1 46 1 48 1 50 1 51 1 52 1 55 1 56 1 57 1 59 1 60 1 61 1 69 1 71 1 73 1 74 1 75 1 77 1 79 1 80 1 81 1 82 1 85 1 86 1 87 1 89 1 90 1 92 1 93 1 94 1 95 1 98 1 100 1 101 1 102 1 104 1 105...
result:
ok Correct (1 test case)
Test #6:
score: 0
Accepted
time: 4ms
memory: 5788kb
input:
1 500 001101100011010001011010101010010000100100100010011101111100101101110111101010001101100001110001001110000001010010111110001100110111111110000010110110111110000110111000001010111011010111011001101101110001011011011011101110101000011000010101011101000000011001111101011111001010111000101110000011...
output:
YES 62393 1 3 1 4 1 6 1 7 1 11 1 12 1 14 1 18 1 20 1 21 1 23 1 25 1 27 1 29 1 32 1 37 1 40 1 43 1 47 1 50 1 51 1 52 1 54 1 55 1 56 1 57 1 58 1 61 1 63 1 64 1 66 1 67 1 68 1 70 1 71 1 72 1 73 1 75 1 77 1 81 1 82 1 84 1 85 1 90 1 91 1 92 1 96 1 99 1 100 1 101 1 108 1 110 1 113 1 115 1 116 1 117 1 118 ...
result:
ok Correct (1 test case)
Test #7:
score: 0
Accepted
time: 8ms
memory: 4288kb
input:
3 288 011100101100101010010110010101010000101101000110011000110011100111100110100010010000110111111100100011110000000101111010110000101011000010000101101001011101111101010010111111100111111111001101010110001111011011111100111000111111011011110101101100101011111000011000110010000110000111110001 10000...
output:
YES 20659 1 2 1 3 1 4 1 7 1 9 1 10 1 13 1 15 1 17 1 20 1 22 1 23 1 26 1 28 1 30 1 32 1 37 1 39 1 40 1 42 1 46 1 47 1 50 1 51 1 55 1 56 1 59 1 60 1 61 1 64 1 65 1 66 1 67 1 70 1 71 1 73 1 77 1 80 1 85 1 86 1 88 1 89 1 90 1 91 1 92 1 93 1 94 1 97 1 101 1 102 1 103 1 104 1 112 1 114 1 115 1 116 1 117 1...
result:
ok Correct (3 test cases)
Test #8:
score: 0
Accepted
time: 8ms
memory: 4332kb
input:
3 288 011000011000101100111000100010010111001110110011011100110100100010111010111100101110100111110011001010101101100111010011111100101011000001111100110011110100111100000101110111010110110001000011101010110000111100011100001101101100010010010011110110011100010110001111010011010010101100110011 10110...
output:
YES 20570 1 2 1 3 1 8 1 9 1 13 1 15 1 16 1 19 1 20 1 21 1 25 1 29 1 32 1 34 1 35 1 36 1 39 1 40 1 41 1 43 1 44 1 47 1 48 1 50 1 51 1 52 1 55 1 56 1 58 1 61 1 65 1 67 1 68 1 69 1 71 1 73 1 74 1 75 1 76 1 79 1 81 1 82 1 83 1 85 1 88 1 89 1 90 1 91 1 92 1 95 1 96 1 99 1 101 1 103 1 105 1 106 1 108 1 10...
result:
ok Correct (3 test cases)
Test #9:
score: 0
Accepted
time: 8ms
memory: 4456kb
input:
3 288 001001111011100000110001011100111011010000101001010101110011111111001011101000011010010101010100000001110100011001111001001101100001111100000111000100110110110101000011010010111000111111010110100110111011101001001001010000001000010010110011010000111001111101011011010111001111001000101001 00110...
output:
YES 20599 1 3 1 6 1 7 1 8 1 9 1 11 1 12 1 13 1 19 1 20 1 24 1 26 1 27 1 28 1 31 1 32 1 33 1 35 1 36 1 38 1 43 1 45 1 48 1 50 1 52 1 54 1 55 1 56 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 69 1 71 1 72 1 73 1 75 1 80 1 81 1 83 1 86 1 88 1 90 1 92 1 94 1 102 1 103 1 104 1 106 1 110 1 111 1 114 1 115 1 ...
result:
ok Correct (3 test cases)
Test #10:
score: 0
Accepted
time: 8ms
memory: 4260kb
input:
3 288 000111001111001111111100001011101110011001011100011110011100000000111110011000101011010000111011000000101000110011111100000101000001110110011100100111100101110101111010111000001010110000011001010111010010000110011010100011011011111100010100011011010001101101011100110111011010100111100011 00110...
output:
YES 20582 1 4 1 5 1 6 1 9 1 10 1 11 1 12 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 27 1 29 1 30 1 31 1 33 1 34 1 35 1 38 1 39 1 42 1 44 1 45 1 46 1 50 1 51 1 52 1 53 1 56 1 57 1 58 1 67 1 68 1 69 1 70 1 71 1 74 1 75 1 79 1 81 1 83 1 84 1 86 1 91 1 92 1 93 1 95 1 96 1 103 1 105 1 109 1 110 1 113 1 11...
result:
ok Correct (3 test cases)
Test #11:
score: 0
Accepted
time: 8ms
memory: 4280kb
input:
3 288 000110011111010001111101111001100001010110000010010011011011001100100011000100011111000010011000011001000001001101010111010101001100111101101101010000100010110000101101011101101010110110000110011001011101100010001011011110101100111101000110100101100110000110001001010011001111000111101001 00000...
output:
YES 20705 1 4 1 5 1 8 1 9 1 10 1 11 1 12 1 14 1 18 1 19 1 20 1 21 1 22 1 24 1 25 1 26 1 27 1 30 1 31 1 36 1 38 1 40 1 41 1 47 1 50 1 53 1 54 1 56 1 57 1 59 1 60 1 63 1 64 1 67 1 71 1 72 1 76 1 80 1 81 1 82 1 83 1 84 1 89 1 92 1 93 1 98 1 99 1 102 1 108 1 111 1 112 1 114 1 116 1 118 1 119 1 120 1 122...
result:
ok Correct (3 test cases)
Test #12:
score: 0
Accepted
time: 8ms
memory: 3852kb
input:
10 158 01100010011000000001011011110010100111101010001101000100110011111110111000110111110000101000010001001110110101101100101001001010111011001011101001000011100010 10111010111111011001011001110000110100101000110101101001111011111101011100010100010101011000110011000000111101011111101010011011011111...
output:
YES 6333 1 2 1 3 1 7 1 10 1 11 1 20 1 22 1 23 1 25 1 26 1 27 1 28 1 31 1 33 1 36 1 37 1 38 1 39 1 41 1 43 1 47 1 48 1 50 1 54 1 57 1 58 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 69 1 70 1 71 1 75 1 76 1 78 1 79 1 80 1 81 1 82 1 87 1 89 1 94 1 98 1 101 1 102 1 103 1 105 1 106 1 108 1 110 1 111 1 113 1 114...
result:
ok Correct (10 test cases)
Test #13:
score: 0
Accepted
time: 8ms
memory: 3564kb
input:
100 50 00110110011011111001110000110010010000111111001100 00001011101101000001011001101100111011111100111101 10011000011111111111010110100011101000101110100001 10101001101110010000000100100000111100010011001001 01110101100010111000101000010001111111010011110000 10001011110110000101000000001101011101...
output:
YES 624 1 3 1 4 1 6 1 7 1 10 1 11 1 13 1 14 1 15 1 16 1 17 1 20 1 21 1 22 1 27 1 28 1 31 1 34 1 39 1 40 1 41 1 42 1 43 1 44 1 47 1 48 2 5 2 7 2 8 2 9 2 11 2 12 2 14 2 20 2 22 2 23 2 26 2 27 2 29 2 30 2 33 2 34 2 35 2 37 2 38 2 39 2 40 2 41 2 42 2 45 2 46 2 47 2 48 2 50 3 4 3 5 3 10 3 11 3 12 3 13 3 ...
result:
ok Correct (100 test cases)
Test #14:
score: -100
Wrong Answer
time: 4ms
memory: 3580kb
input:
1000 15 010011000011111 101111011100010 010000101011101 010010110101011 110100100010101 110000111000001 001111010010110 010101101001111 011001010010110 010100000011000 101010101101100 101100010110000 101010111010010 110100111000101 101111010000010 15 001100011010101 000111111100101 100011001110100 1...
output:
YES 55 1 2 1 5 1 6 1 11 1 12 1 13 1 14 1 15 2 3 2 4 2 5 2 6 2 8 2 9 2 10 2 14 3 7 3 9 3 11 3 12 3 13 3 15 4 5 4 7 4 8 4 10 4 12 4 14 4 15 5 7 5 11 5 13 5 15 6 7 6 8 6 9 6 15 7 8 7 11 7 13 7 14 8 9 8 12 8 13 8 14 8 15 9 11 9 13 9 14 10 11 10 12 11 12 11 13 13 14 14 15 YES 63 1 3 1 4 1 8 1 9 1 11 1 13...
result:
wrong answer Parities did not match (test case 4)