QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#93931#5520. Distance ParitiesAsad_BinWA 614ms6700kbC++173.6kb2023-04-04 04:30:192023-04-04 04:30:20

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-04 04:30:20]
  • 评测
  • 测评结果:WA
  • 用时:614ms
  • 内存:6700kb
  • [2023-04-04 04:30:19]
  • 提交

answer

// . . . Bismillahir Rahmanir Rahim . . .
 
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#ifndef ONLINE_JUDGE
#define dbg_out cout
#define debug(...) dbg_out << "DBG )> "; __f(#__VA_ARGS__, __VA_ARGS__);
template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> pr) { out << "{ " << pr.first << ", " << pr.second << " }"; return out; }
template<typename T1> ostream& operator<<(ostream& out, vector<T1> vec) { out << "{ "; for (auto &x: vec) out << x << ", "; out << "}"; return out; }
template<typename T1, size_t size> ostream& operator<<(ostream& out, array<T1, size> arr) { out << "{ "; for (auto &x: arr) out << x << ", "; out << "}"; return out; }
template<typename T1, typename T2> ostream& operator<<(ostream& out, map<T1, T2> mp) { out << "{ ";for (auto &x: mp) out << x.first << ": " << x.second <<  ", "; out << "}"; return out; }
template <typename Arg1> void __f(const char* name, Arg1&& arg1) { while (isspace(name[0])) name++; (isalpha(name[0]) || name[0] == '_') ? dbg_out << name << ": " << arg1 << "\n" : dbg_out << arg1 << "\n"; dbg_out.flush();}
template <typename Arg1, typename... Args> void __f (const char* names, Arg1&& arg1, Args&&... args) { const char *comma = strchr(names + 1, ','); while (isspace(names[0])) names++; (isalpha(names[0]) || names[0] == '_') ? dbg_out.write(names, comma - names) << ": " << arg1 << " | " : dbg_out << arg1 << " | "; __f(comma + 1, args...);}
#else
#define debug(...)
#endif
 
ll gcd(ll a, ll b){ while (b){ a %= b; swap(a, b);} return a;}
ll lcm(ll a, ll b){ return (a/gcd(a, b)*b);}
ll ncr(ll a, ll b){ ll x = max(a-b, b), ans=1; for(ll K=a, L=1; K>=x+1; K--, L++){ ans = ans * K; ans /= L;} return ans;}
ll bigmod(ll a,ll b,ll mod){ if(b==0){ return 1;} ll tm=bigmod(a,b/2,mod); tm=(tm*tm)%mod; if(b%2==1) tm=(tm*a)%mod; return tm;}
ll egcd(ll a,ll b,ll &x,ll &y){ if(a==0){ x=0; y=1; return b;} ll x1,y1; ll d=egcd(b%a,a,x1,y1); x=y1-(b/a)*x1; y=x1; return d;}
ll modpow(ll a,ll p,ll mod) {ll ans=1;while(p){if(p%2)ans=(ans*a)%mod;a=(a*a)%mod;p/=2;} return ans;}
ll inverse_mod(ll n,ll mod) {return modpow(n,mod-2,mod);}


const int N = 500;
vector<int> edge[N+5];
int vis[N+5];

int dfs(int u)
{
	int cnt = 0;
	vis[u] = 1;
	for(auto v : edge[u]){
		if(!vis[v]) cnt += dfs(v);
	}
	
	return cnt + 1;
}
int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	//cout.tie(0);
	
	int t; scanf("%d", &t);
	while(t--){
		int n; scanf("%d", &n);
		
		char s[n][n+5];
		for(int K = 0; K < n; K++) scanf("%s", s[K]);
		
		int ara[n+1][n+1];
		for(int K = 1; K <= n; K++) {
			for(int L = 1; L <= n; L++) ara[K][L] = s[K-1][L-1] - '0';
		}
		
		vector<pair<int, int> > v;
		int cnt[n+1][n+1] = {0};
		for(int L = 1; L <= n; L++){
			for(int K = 1; K <= n; K++){
				for(int M = K+1; M <= n; M++){
					if(K == L) continue;
					
					if((ara[K][L] + ara[L][M])%2 == ara[K][M]){
						if(ara[K][L] && !cnt[K][L]){
							v.push_back({K, L});
							cnt[K][L]++;
							cnt[L][K]++;
						}
						if(ara[L][M] && !cnt[L][M]){
							v.push_back({L, M});
							cnt[L][M]++;
							cnt[M][L]++;
						}
						if(ara[K][M] && !cnt[K][M]){
							v.push_back({K, M});
							cnt[K][M]++;
							cnt[M][K]++;
						}
					}
				}
			}
		}
		
		for(int K = 1; K <= n; K++) edge[K].clear();
		memset(vis, 0, sizeof vis);
		for(auto it: v){
			edge[it.first].push_back(it.second);
			edge[it.second].push_back(it.first);
		}
		
		int x = dfs(1);
		
		if(x != n){
			printf("NO\n");
			continue;
		}
		
		printf("YES\n");
		printf("%d\n",  (int)v.size());
		for(auto it : v) printf("%d %d\n", it.first, it.second);
	}
	
	return 0;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3656kb

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
2 1
2 3
1 4
2 5
3 4
4 5

result:

ok Correct (3 test cases)

Test #2:

score: 0
Accepted
time: 614ms
memory: 6672kb

input:

1
500
001001010000101001100000100011101011010001100110010000011000001100000011010001001111001010010101110100000100011000110111100010001000010111111000000101101010011111000010110010111100111110111000010000100100010010001110000100111000001111101011111101111110111110001000111110001011111100110011100100...

output:

YES
62433
1 3
2 3
1 8
2 8
1 15
2 15
1 19
2 19
1 31
2 31
1 33
2 33
1 36
2 36
1 38
2 38
1 42
2 42
1 43
2 43
1 47
2 47
1 50
2 50
1 56
2 56
1 63
2 63
1 71
2 71
1 72
2 72
1 74
2 74
1 82
2 82
1 83
2 83
1 84
2 84
1 89
2 89
1 92
2 92
1 94
2 94
1 97
2 97
1 98
2 98
1 100
2 100
1 115
2 115
1 116
2 116
1 119
2 ...

result:

ok Correct (1 test case)

Test #3:

score: 0
Accepted
time: 604ms
memory: 6652kb

input:

1
500
001010100000100110111000011101101110001000011110011000010011000000101110000011111110111000110110011111011101110010011100101110001000001010010011000011101000011110110101001010010110110001111101101100001100010110011100010001001011100111011001101110011010010001011101011110010111010011111001100101...

output:

YES
62414
1 5
2 5
1 17
2 17
1 19
2 19
1 20
2 20
1 26
2 26
1 27
2 27
1 28
2 28
1 30
2 30
1 33
2 33
1 34
2 34
1 35
2 35
1 56
2 56
1 59
2 59
1 60
2 60
1 70
2 70
1 77
2 77
1 79
2 79
1 80
2 80
1 81
2 81
1 83
2 83
1 85
2 85
1 86
2 86
1 87
2 87
1 91
2 91
1 92
2 92
1 99
2 99
1 100
2 100
1 101
2 101
1 102
2 ...

result:

ok Correct (1 test case)

Test #4:

score: 0
Accepted
time: 607ms
memory: 6660kb

input:

1
500
000110110101000000010111101011000001000011001001010001010100011101011111111111001010101010111001011110000000001100010001011110101100000001001000110000101011010111110101001101100000111111100011001000000111110001011101101000001101100001011100000000011101011011011011011011000010110111101111010101...

output:

YES
62389
1 5
2 5
1 10
2 10
1 12
2 12
1 20
2 20
1 23
2 23
1 24
2 24
1 27
2 27
1 41
2 41
1 42
2 42
1 48
2 48
1 50
2 50
1 58
2 58
1 62
2 62
1 71
2 71
1 72
2 72
1 74
2 74
1 75
2 75
1 76
2 76
1 78
2 78
1 81
2 81
1 83
2 83
1 85
2 85
1 87
2 87
1 89
2 89
1 93
2 93
1 96
2 96
1 99
2 99
1 100
2 100
1 111
2 11...

result:

ok Correct (1 test case)

Test #5:

score: 0
Accepted
time: 606ms
memory: 6700kb

input:

1
500
000111010001001110011010011100010100001101111101011100111011100000001010111010111100111011011110010111011000111100111011010100110101001010111001000101101100010111101010100101000000011001001110010000101010111100001000011111111110111000110110010010100000110000001010111111010111011100100101010110...

output:

YES
62423
1 5
2 5
1 6
2 6
1 8
2 8
1 12
2 12
1 15
2 15
1 17
2 17
1 21
2 21
1 34
2 34
1 39
2 39
1 44
2 44
1 48
2 48
1 51
2 51
1 55
2 55
1 59
2 59
1 86
2 86
1 89
2 89
1 92
2 92
1 93
2 93
1 95
2 95
1 100
2 100
1 102
2 102
1 109
2 109
1 112
2 112
1 117
2 117
1 120
2 120
1 127
2 127
1 135
2 135
1 141
2 14...

result:

ok Correct (1 test case)

Test #6:

score: 0
Accepted
time: 609ms
memory: 6692kb

input:

1
500
001101100011010001011010101010010000100100100010011101111100101101110111101010001101100001110001001110000001010010111110001100110111111110000010110110111110000110111000001010111011010111011001101101110001011011011011101110101000011000010101011101000000011001111101011111001010111000101110000011...

output:

YES
62393
1 7
2 7
1 11
2 11
1 14
2 14
1 18
2 18
1 37
2 37
1 43
2 43
1 47
2 47
1 50
2 50
1 52
2 52
1 54
2 54
1 58
2 58
1 61
2 61
1 63
2 63
1 66
2 66
1 67
2 67
1 68
2 68
1 71
2 71
1 72
2 72
1 73
2 73
1 75
2 75
1 77
2 77
1 81
2 81
1 82
2 82
1 84
2 84
1 90
2 90
1 100
2 100
1 101
2 101
1 108
2 108
1 110
...

result:

ok Correct (1 test case)

Test #7:

score: 0
Accepted
time: 348ms
memory: 4864kb

input:

3
288
011100101100101010010110010101010000101101000110011000110011100111100110100010010000110111111100100011110000000101111010110000101011000010000101101001011101111101010010111111100111111111001101010110001111011011111100111000111111011011110101101100101011111000011000110010000110000111110001
10000...

output:

YES
20659
2 1
1 3
1 4
2 6
1 7
2 8
2 12
1 13
2 16
1 17
2 21
1 23
2 24
1 26
2 27
1 28
2 29
2 31
2 35
2 36
2 38
1 40
1 42
2 43
2 44
2 45
2 49
1 51
2 53
2 54
1 59
2 63
1 64
1 65
2 69
1 71
1 73
2 74
2 76
1 77
2 78
2 79
2 81
2 83
2 87
1 89
1 91
1 94
2 95
2 96
2 98
1 101
1 102
2 105
2 107
2 108
2 110
2 113...

result:

ok Correct (3 test cases)

Test #8:

score: 0
Accepted
time: 347ms
memory: 4832kb

input:

3
288
011000011000101100111000100010010111001110110011011100110100100010111010111100101110100111110011001010101101100111010011111100101011000001111100110011110100111100000101110111010110110001000011101010110000111100011100001101101100010010010011110110011100010110001111010011010010101100110011
10110...

output:

YES
20570
2 1
2 4
2 7
1 8
2 10
2 12
1 13
1 15
1 19
2 24
2 28
1 29
2 30
1 32
1 35
2 38
1 40
1 41
1 43
1 44
2 45
2 46
2 49
1 50
2 53
2 54
1 56
1 58
2 60
1 61
2 62
1 65
1 67
1 69
2 72
1 74
1 76
2 78
2 84
1 85
1 88
1 90
2 94
2 98
2 100
1 101
2 102
2 104
2 107
1 108
2 110
2 111
1 112
1 113
1 114
2 115
2 ...

result:

ok Correct (3 test cases)

Test #9:

score: 0
Accepted
time: 356ms
memory: 4912kb

input:

3
288
001001111011100000110001011100111011010000101001010101110011111111001011101000011010010101010100000001110100011001111001001101100001111100000111000100110110110101000011010010111000111111010110100110111011101001001001010000001000010010110011010000111001111101011011010111001111001000101001
00110...

output:

YES
20599
1 3
2 3
1 7
2 7
1 13
2 13
1 19
2 19
1 28
2 28
1 32
2 32
1 35
2 35
1 36
2 36
1 38
2 38
1 48
2 48
1 50
2 50
1 55
2 55
1 59
2 59
1 60
2 60
1 63
2 63
1 64
2 64
1 66
2 66
1 69
2 69
1 71
2 71
1 72
2 72
1 73
2 73
1 75
2 75
1 81
2 81
1 83
2 83
1 86
2 86
1 88
2 88
1 90
2 90
1 92
2 92
1 103
2 103
1 ...

result:

ok Correct (3 test cases)

Test #10:

score: 0
Accepted
time: 356ms
memory: 4828kb

input:

3
288
000111001111001111111100001011101110011001011100011110011100000000111110011000101011010000111011000000101000110011111100000101000001110110011100100111100101110101111010111000001010110000011001010111010010000110011010100011011011111100010100011011010001101101011100110111011010100111100011
00110...

output:

YES
20582
1 4
2 4
1 12
2 12
1 15
2 15
1 17
2 17
1 18
2 18
1 30
2 30
1 31
2 31
1 38
2 38
1 52
2 52
1 67
2 67
1 74
2 74
1 75
2 75
1 79
2 79
1 83
2 83
1 91
2 91
1 92
2 92
1 95
2 95
1 103
2 103
1 105
2 105
1 109
2 109
1 113
2 113
1 114
2 114
1 115
2 115
1 116
2 116
1 117
2 117
1 124
2 124
1 132
2 132
1 ...

result:

ok Correct (3 test cases)

Test #11:

score: 0
Accepted
time: 350ms
memory: 4828kb

input:

3
288
000110011111010001111101111001100001010110000010010011011011001100100011000100011111000010011000011001000001001101010111010101001100111101101101010000100010110000101101011101101010110110000110011001011101100010001011011110101100111101000110100101100110000110001001010011001111000111101001
00000...

output:

YES
20705
1 12
2 12
1 19
2 19
1 20
2 20
1 21
2 21
1 25
2 25
1 27
2 27
1 30
2 30
1 31
2 31
1 38
2 38
1 41
2 41
1 47
2 47
1 54
2 54
1 56
2 56
1 59
2 59
1 63
2 63
1 64
2 64
1 67
2 67
1 72
2 72
1 76
2 76
1 83
2 83
1 84
2 84
1 89
2 89
1 92
2 92
1 93
2 93
1 112
2 112
1 119
2 119
1 120
2 120
1 122
2 122
1 ...

result:

ok Correct (3 test cases)

Test #12:

score: 0
Accepted
time: 198ms
memory: 4108kb

input:

10
158
01100010011000000001011011110010100111101010001101000100110011111110111000110111110000101000010001001110110101101100101001001010111011001011101001000011100010
10111010111111011001011001110000110100101000110101101001111011111101011100010100010101011000110011000000111101011111101010011011011111...

output:

YES
6333
2 1
2 4
2 5
2 9
2 12
2 13
2 14
2 16
2 17
1 25
1 31
2 34
1 37
1 38
1 43
2 45
2 46
1 47
2 51
2 53
1 54
2 56
2 59
1 67
2 68
1 69
2 72
1 75
1 79
1 80
1 81
2 84
2 86
1 87
2 88
2 93
2 97
1 101
1 102
1 103
2 107
1 111
2 112
2 115
2 116
2 121
1 122
2 124
2 128
1 129
2 132
2 136
1 137
2 138
1 140
2 ...

result:

ok Correct (10 test cases)

Test #13:

score: 0
Accepted
time: 75ms
memory: 3716kb

input:

100
50
00110110011011111001110000110010010000111111001100
00001011101101000001011001101100111011111100111101
10011000011111111111010110100011101000101110100001
10101001101110010000000100100000111100010011001001
01110101100010111000101000010001111111010011110000
10001011110110000101000000001101011101...

output:

YES
624
1 7
2 7
1 11
2 11
1 14
2 14
1 20
2 20
1 22
2 22
1 27
2 27
1 34
2 34
1 39
2 39
1 40
2 40
1 41
2 41
1 42
2 42
1 47
2 47
1 48
2 48
3 1
3 5
1 6
3 12
3 18
3 19
1 21
3 24
3 25
1 28
3 32
3 33
3 35
1 44
3 45
3 50
4 1
4 5
4 8
4 9
1 10
4 12
1 15
1 17
4 24
1 31
4 33
4 35
4 36
4 50
5 6
1 13
5 13
5 15
1 ...

result:

ok Correct (100 test cases)

Test #14:

score: -100
Wrong Answer
time: 26ms
memory: 3656kb

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
2 1
2 3
2 4
2 8
2 9
2 10
1 11
1 12
1 13
1 15
3 11
3 12
3 13
3 15
1 5
4 5
4 12
1 14
4 14
4 15
1 6
5 7
6 7
6 8
6 9
7 11
7 13
7 14
8 12
8 13
8 14
8 15
9 11
9 13
9 14
10 11
10 12
2 5
2 6
3 7
2 14
4 7
5 11
5 13
5 15
6 15
7 8
13 14
14 15
3 9
8 9
4 8
4 10
11 12
11 13
YES
63
1 4
2 4
1 8
2 8
1 9
2 9
1...

result:

wrong answer Parities did not match (test case 4)