QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#461677 | #4282. Intervals | propane | WA | 1ms | 3724kb | C++20 | 2.2kb | 2024-07-02 22:31:06 | 2024-07-02 22:31:06 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
using LL = long long;
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n;
cin >> n;
vector<vector<int> > g(n, vector<int>(n));
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin >> g[i][j];
}
}
vector<bool> v(n);
vector<int> p;
auto dfs = [&](auto &&dfs, int u) -> void {
v[u] = true;
p.push_back(u);
for(int i = 0; i < n; i++){
if (g[i][u] > 0 and !v[i]){
dfs(dfs, i);
}
}
};
vector<bool> vis(n);
vector<pair<int, int> > seg(n);
auto inter = [&](pair<int, int> a, pair<int, int> b){
int l = max(a.first, b.first);
int r = min(a.second, b.second);
return max(0, r - l);
};
const int N = 1e6;
auto solve = [&](vector<int> p){
// 枚举最左的区间
for(auto x : p){
for(auto u : p) vis[u] = false;
bool ok = true;
seg[x] = {0, N};
vis[x] = true;
using P = pair<int, int>;
priority_queue<P, vector<P>, greater<P> > q;
q.push({0, x});
vis[x] = true;
while(!q.empty() and ok){
auto [_, t] = q.top();
q.pop();
for(auto j : p){
if (!vis[j]){
vis[j] = true;
int l = seg[t].second - g[t][j];
seg[j] = {l, l + N};
q.push({l, j});
}
else if (inter(seg[t], seg[j]) != g[t][j]){
ok = false;
break;
}
}
}
if (ok) return;
}
cout << "No" << '\n';
exit(0);
};
for(int i = 0; i < n; i++){
if (v[i]) continue;
p.clear();
dfs(dfs, i);
solve(p);
}
cout << "Yes" << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3604kb
input:
3 1000000 500000 0 500000 1000000 500000 0 500000 1000000
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 1ms
memory: 3472kb
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: 1ms
memory: 3724kb
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