QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#277211 | #4282. Intervals | PetroTarnavskyi# | WA | 0ms | 3588kb | C++20 | 1.8kb | 2023-12-06 16:37:13 | 2023-12-06 16:37:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int L = 1'000'000;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector a(n, VI(n));
for (VI& ai : a)
for (int& aij : ai)
cin >> aij;
unordered_set<int> unused;
FOR(i, 0, n)
unused.insert(i);
VI can(n), x(n);
while (!unused.empty())
{
int i = *unused.begin();
can[i] = 1;
VI vec;
while (true)
{
int j = -1;
for (int k : unused)
if (can[k])
j = k;
if (j == -1)
break;
unused.erase(j);
if (j != i)
{
unordered_map<int, int> mp;
int cntNonZero = 0;
for (int k : vec)
{
if (a[j][k] != 0)
{
mp[x[k] + L - a[j][k]]++;
mp[x[k] + a[j][k] - L]++;
cntNonZero++;
}
}
assert(cntNonZero != 0);
bool ok = false;
for (auto [cand, cntCand] : mp)
{
if (!ok && cntCand == cntNonZero)
{
ok = true;
x[j] = cand;
for (int k : vec)
{
if (max(0, min(x[k], x[j]) + L - max(x[k], x[j])) != a[k][j])
{
ok = false;
}
}
}
}
if (!ok)
{
cout << "No\n";
return 0;
}
}
vec.PB(j);
FOR(k, 0, n)
{
if (a[j][k] != 0)
can[k] = 1;
}
}
}
FOR(i, 0, n)
{
FOR(j, 0, n)
{
if (max(0, min(x[i], x[j]) + L - max(x[i], x[j])) != a[i][j])
{
cout << "No\n";
return 0;
}
}
}
cout << "Yes\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
3 1000000 500000 0 500000 1000000 500000 0 500000 1000000
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
3 1000000 500000 500000 500000 1000000 500000 500000 500000 1000000
output:
No
result:
ok answer is NO
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3528kb
input:
10 1000000 0 0 0 451708 0 0 0 0 0 0 1000000 123857 854215 0 789032 115663 874764 0 0 0 123857 1000000 269642 0 334825 0 249093 0 0 0 854215 269642 1000000 0 934817 0 979451 0 0 451708 0 0 0 1000000 0 0 0 0 0 0 789032 334825 934817 0 1000000 0 914268 0 0 0 115663 0 0 0 0 1000000 0 0 0 0 874764 249093...
output:
No
result:
wrong answer expected YES, found NO