QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#296835#7995. 图tarjen#WA 35ms4392kbC++202.4kb2024-01-03 18:00:362024-01-03 18:00:37

Judging History

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

  • [2024-01-03 18:00:37]
  • 评测
  • 测评结果:WA
  • 用时:35ms
  • 内存:4392kb
  • [2024-01-03 18:00:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn=510;
int a[maxn][maxn];
const int inf=1.5e9;
int ans[maxn][maxn];
typedef long long ll;
const ll p1=31,p2=131;
const ll mod1=1e9+7,mod2=1e9+9;
typedef pair<ll,ll> hs;
const hs p = make_pair(p1,p2);
hs &operator+=(hs &a, hs b) {
    a.first=(a.first+b.first)%mod1;
    a.second=(a.second+b.second)%mod2;
    return a;
}
hs operator+(hs a, hs b) { return a += b; }
hs &operator-=(hs &a, hs b) {
    a.first=(a.first-b.first+mod1)%mod1;
    a.second=(a.second-b.second+mod2)%mod2;
    return a;
}
hs operator-(hs a, hs b) { return a -= b; }
hs &operator*=(hs &a, hs b) {
    a.first=(a.first*b.first)%mod1;
    a.second=(a.second*b.second)%mod2;
    return a;
}
hs operator*(hs a, hs b) { return a *= b; }
struct kkk{
    int x,len;
    hs c;
    kkk(){}
    kkk(int _x,int _len,hs _c){
        x=_x,len=_len,c=_c;
    }
    bool operator<(kkk k1)const{
        return len>k1.len;
    }
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++)cin>>a[i][j];
    }
    auto add= [&](hs &x,hs y){
        x+=y;
    };
    auto solve = [&](int root){
        vector<int> dis(n+1,inf);
        vector<hs> cnt(n+1);
        priority_queue<kkk,vector<kkk>> qu;
        qu.push(kkk(root,0,{1,1}));
        while(!qu.empty()){
            kkk k1=qu.top();qu.pop();
            // cout<<"root="<<root<<" x="<<k1.x<<" len="<<k1.len<<"\n";
            if(k1.len>dis[k1.x])continue;
            if(k1.len<=dis[k1.x]){
                add(cnt[k1.x],k1.c);
                // cout<<"cnt="<<cnt[k1.x].first<<"\n";
            }
            if(k1.len<dis[k1.x]){
                dis[k1.x]=k1.len;
            }
            else continue;
            for(int j=1;j<=n;j++)if(dis[k1.x]+a[k1.x][j]<dis[j]){
                qu.push(kkk{j,dis[k1.x]+a[k1.x][j],cnt[k1.x]});
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++)if(i!=j){
                if(dis[i]+a[i][j]==dis[j]&&cnt[j]==cnt[i]){
                    ans[i][j]=1;
                    // if(i==1&&j==3)cout<<root<<"\n";
                }
            }
        }
    };
    for(int i=1;i<=n;i++)solve(i);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++)cout<<ans[i][j];;
        cout<<"\n";
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3628kb

input:

4
0 3 2 100
3 0 8 100
2 8 0 10
100 100 10 0

output:

0110
1000
1001
0010

result:

ok 4 lines

Test #2:

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

input:

4
0 3 2 100
3 0 8 100
2 8 0 10
100 100 10 0

output:

0110
1000
1001
0010

result:

ok 4 lines

Test #3:

score: -100
Wrong Answer
time: 35ms
memory: 4392kb

input:

100
0 41659 61282 49636 67326 48035 29694 46438 87384 82143 38685 66540 48746 29800 91786 54931 56232 61941 53423 75707 45135 69244 53802 89998 64199 63778 75825 31745 66975 44537 35793 55663 72647 60768 80884 46657 54066 84568 6266 48213 78216 50369 66761 54861 67607 38509 52250 54210 71135 56840 5...

output:

0001000000000000000000000000000000000010000100000000100001001000000000000001000000000000000000000010
0011000000100000000000000000000000000000000000000000000000100000000000000000000001000000000000000000
01001000010000000000000000000000000000000000000000001000000010000000000010000000010000000000000000...

result:

wrong answer 1st lines differ - expected: '000000000000000000000000000000...0000001000000000000000000000010', found: '000100000000000000000000000000...0000001000000000000000000000010'