QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#461680#4282. IntervalspropaneWA 1ms3600kbC++202.3kb2024-07-02 22:35:072024-07-02 22:35:08

Judging History

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

  • [2024-07-02 22:35:08]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3600kb
  • [2024-07-02 22:35:07]
  • 提交

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[u][i] > 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 (g[t][j] == 0) continue;
                    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';

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3580kb

input:

3
1000000 500000 500000
500000 1000000 500000
500000 500000 1000000

output:

No

result:

ok answer is NO

Test #3:

score: 0
Accepted
time: 1ms
memory: 3584kb

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:

Yes

result:

ok answer is YES

Test #4:

score: 0
Accepted
time: 1ms
memory: 3552kb

input:

10
1000000 0 333783 645285 0 0 0 0 91417 0
0 1000000 0 0 0 0 107222 0 0 461671
333783 0 1000000 688498 0 0 0 0 0 0
645285 0 688498 1000000 0 0 0 0 0 0
0 0 0 0 1000000 0 0 0 0 0
0 0 0 0 0 1000000 0 0 0 21662
0 107222 0 0 0 0 1000000 0 0 0
0 0 0 0 0 0 0 1000000 750265 0
91417 0 0 0 0 0 0 750265 100000...

output:

Yes

result:

ok answer is YES

Test #5:

score: 0
Accepted
time: 0ms
memory: 3476kb

input:

10
1000000 0 0 0 0 0 0 0 83267 0
0 1000000 0 0 0 0 0 0 0 979288
0 0 1000000 511234 0 0 0 0 0 0
0 0 511234 1000000 0 0 0 0 0 0
0 0 0 0 1000000 0 0 0 853421 0
0 0 0 0 0 1000000 0 592583 0 0
0 0 0 0 0 0 1000000 0 0 0
0 0 0 0 0 592583 0 1000000 0 0
83267 0 0 0 853421 0 0 0 1000000 0
0 979288 0 0 0 0 0 0...

output:

Yes

result:

ok answer is YES

Test #6:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

10
1000000 0 662921 128153 0 0 0 530784 0 0
0 1000000 0 0 454596 0 90389 0 0 0
662921 0 1000000 0 0 0 0 193705 0 0
128153 0 0 1000000 0 0 0 597369 0 0
0 454596 0 0 1000000 0 635793 0 0 0
0 0 0 0 0 1000000 0 0 0 0
0 90389 0 0 635793 0 1000000 0 0 0
530784 0 193705 597369 0 0 0 1000000 0 0
0 0 0 0 0 0...

output:

Yes

result:

ok answer is YES

Test #7:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

10
1000000 194114 0 372890 0 303429 0 0 0 0
194114 1000000 0 821224 0 0 0 0 0 514397
0 0 1000000 0 399458 0 0 0 0 425383
372890 821224 0 1000000 0 0 0 0 0 335621
0 0 399458 0 1000000 0 0 0 0 0
303429 0 0 0 0 1000000 0 0 0 0
0 0 0 0 0 0 1000000 372945 0 0
0 0 0 0 0 0 372945 1000000 0 0
0 0 0 0 0 0 0 ...

output:

Yes

result:

ok answer is YES

Test #8:

score: -100
Wrong Answer
time: 0ms
memory: 3472kb

input:

10
1000000 0 0 218418 0 0 144052 0 0 0
0 1000000 0 0 0 0 0 953348 0 0
0 0 1000000 0 0 0 844845 0 0 0
218418 0 0 1000000 0 0 0 0 39414 0
0 0 0 0 1000000 0 0 0 91667 0
0 0 0 0 0 1000000 0 0 0 0
144052 0 844845 0 0 0 1000000 0 0 0
0 953348 0 0 0 0 0 1000000 0 466707
0 0 0 39414 91667 0 0 0 1000000 0
0 ...

output:

Yes

result:

wrong answer expected NO, found YES