QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#692702#5520. Distance ParitiescxqghzjRE 0ms3872kbC++142.1kb2024-10-31 14:55:362024-10-31 14:55:47

Judging History

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

  • [2024-10-31 14:55:47]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3872kb
  • [2024-10-31 14:55:36]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <array>
#include <vector>
#include <bitset>
#define pii pair <int, int>
using namespace std;
#ifdef ONLINE_JUDGE

/* #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++) */
/* char buf[1 << 23], *p1 = buf, *p2 = buf, ubuf[1 << 23], *u = ubuf; */

#endif
int read() {
    int p = 0, flg = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') flg = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        p = p * 10 + c - '0';
        c = getchar();
    }
    return p * flg;
}
void write(int x) {
    if (x < 0) {
        x = -x;
        putchar('-');
    }
    if (x > 9) {
        write(x / 10);
    }
    putchar(x % 10 + '0');
}
bool _stmer;

#define fi first
#define se second

const int N = 305;

array <bitset <N>, N> vis;
array <string, N> mp;
char strbuf[N];

void solve() {
    vector <pii> ans;
    int n = read();
    vis.fill((bitset <N>)0);
    for (int i = 1; i <= n; i++) {
        scanf("%s", strbuf);
        mp[i] = strbuf, mp[i] = " " + mp[i];
        for (int j = 1; j <= n; j++)
            if (mp[i][j] == '1' && !vis[i][j]) vis[i][j] = vis[j][i] = 1, ans.push_back(make_pair(i, j));
    }
    bool _flg = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (mp[i][j] == '0') {
                bool flg = 0;
                for (int k = 1; k <= n; k++)
                    flg |= i != k && j != k && mp[i][k] == mp[j][k] && mp[i][k] == '1';
                if (!flg) _flg = 1;
            }
        }
    }
    if (_flg) puts("NO");
    else {
        puts("YES");
        write(ans.size()), puts("");
        for (auto k : ans) {
            write(k.fi), putchar(32);
            write(k.se), puts("");
        }
    }
}

bool _edmer;
int main() {
    cerr << (&_stmer - &_edmer) / 1024.0 / 1024.0 << "MB\n";
#ifndef cxqghzj
//    freopen("bridge.in", "r", stdin);
//    freopen("bridge.out", "w", stdout);
#endif
    int T = read();
    while (T--) solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3872kb

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: -100
Runtime Error

input:

1
500
001001010000101001100000100011101011010001100110010000011000001100000011010001001111001010010101110100000100011000110111100010001000010111111000000101101010011111000010110010111100111110111000010000100100010010001110000100111000001111101011111101111110111110001000111110001011111100110011100100...

output:


result: