Submission #1575573


Source Code Expand

#include<bits/stdc++.h>
#define inf 2147483647
using namespace std;

struct Edge{
    int to,cap,flow,cost;
    Edge *dual;
    Edge(int t,int cp,int cs){
        to=t;cap=cp;flow=0;cost=cs;
    }
    int spare(void){
        return cap-flow;
    }
};

const int N=55;
char arr[N][N];
int source,sink;
vector<Edge*> adj[2*N];
vector<int> answer;

void add_edge(int u,int v,int cap,int cost){
    Edge *e1=new Edge(v,cap,cost);
    Edge *e2=new Edge(u,0,-cost);
    e1->dual=e2;
    e2->dual=e1;
    adj[u].push_back(e1);
    adj[v].push_back(e2);
}

int main(void){
    int n;scanf("%d",&n);
    source=0,sink=2*n+1;
    for(int i=1;i<=n;i++)scanf("%s",arr[i]+1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            add_edge(i,n+j,inf,arr[i][j]);
    for(int i=1;i<=n;i++){
        add_edge(source,i,1,0);
        add_edge(n+i,sink,1,0);
    }
    while(true){
        int pre[2*N],dist[2*N];
        bool inq[2*N]={0};
        Edge* p[2*N];
        fill(pre,pre+2*N,-1);
        fill(dist,dist+2*N,inf);
        queue<int> q;
        q.push(source);
        inq[source]=true;
        dist[source]=0;
        while(!q.empty()){
            int cur=q.front();
            q.pop();
            inq[cur]=false;
            for(Edge *e:adj[cur])
                if(e->spare()>0)
                    if(dist[e->to]>dist[cur]+e->cost){
                        dist[e->to]=dist[cur]+e->cost;
                        pre[e->to]=cur;
                        p[e->to]=e;
                        if(!inq[e->to])
                            q.push(e->to),inq[e->to]=true;
                    }
        }
        if(pre[sink]==-1)break;
        int F=inf,x,y=pre[sink]-n;
        for(int i=sink;i!=source;i=pre[i]){
            F=min(F,p[i]->spare());
            if(pre[i]==source)x=i;
        }
        for(int i=sink;i!=source;i=pre[i]){
            p[i]->flow+=F;
            p[i]->dual->flow-=F;
        }
        answer.push_back(arr[x][y]);
    }
    sort(answer.begin(),answer.end());
    for(int i:answer)
        printf("%c",i);
    printf("\n");
    return 0;
}

Submission Info

Submission Time
Task C - Decoding Ancient Messages
User lg970325
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2159 Byte
Status WA
Exec Time 2 ms
Memory 512 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:32:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     int n;scanf("%d",&n);
                         ^
./Main.cpp:34:46: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++)scanf("%s",arr[i]+1);
                                              ^

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
AC × 10
WA × 33
Set Name Test Cases
All 00_sample_00, 00_sample_01, 00_sample_02, 10_Random_03_09, 10_Random_05_00, 10_Random_08_03, 10_Random_09_12, 10_Random_10_06, 10_Random_13_10, 10_Random_16_01, 10_Random_19_07, 10_Random_19_13, 10_Random_26_04, 10_Random_30_05, 10_Random_34_14, 10_Random_35_08, 10_Random_44_02, 10_Random_46_11, 10_Random_50_15, 20_SkewRandom_13_12, 20_SkewRandom_14_08, 20_SkewRandom_20_00, 20_SkewRandom_25_04, 20_SkewRandom_29_16, 20_SkewRandom_31_13, 20_SkewRandom_36_01, 20_SkewRandom_38_09, 20_SkewRandom_41_17, 20_SkewRandom_47_05, 20_SkewRandom_50_02, 20_SkewRandom_50_03, 20_SkewRandom_50_06, 20_SkewRandom_50_07, 20_SkewRandom_50_10, 20_SkewRandom_50_11, 20_SkewRandom_50_14, 20_SkewRandom_50_15, 20_SkewRandom_50_18, 20_SkewRandom_50_19, 90_teuchi_00, 90_teuchi_01, 90_teuchi_02, 90_teuchi_03
Case Name Status Exec Time Memory
00_sample_00 AC 1 ms 256 KB
00_sample_01 WA 2 ms 384 KB
00_sample_02 AC 1 ms 256 KB
10_Random_03_09 AC 1 ms 256 KB
10_Random_05_00 AC 1 ms 256 KB
10_Random_08_03 WA 1 ms 256 KB
10_Random_09_12 AC 1 ms 256 KB
10_Random_10_06 WA 1 ms 256 KB
10_Random_13_10 AC 1 ms 256 KB
10_Random_16_01 WA 1 ms 256 KB
10_Random_19_07 WA 1 ms 256 KB
10_Random_19_13 WA 1 ms 256 KB
10_Random_26_04 WA 1 ms 256 KB
10_Random_30_05 WA 2 ms 384 KB
10_Random_34_14 WA 2 ms 384 KB
10_Random_35_08 WA 2 ms 384 KB
10_Random_44_02 WA 2 ms 384 KB
10_Random_46_11 WA 2 ms 384 KB
10_Random_50_15 WA 2 ms 512 KB
20_SkewRandom_13_12 WA 1 ms 256 KB
20_SkewRandom_14_08 WA 1 ms 256 KB
20_SkewRandom_20_00 WA 1 ms 256 KB
20_SkewRandom_25_04 WA 1 ms 256 KB
20_SkewRandom_29_16 WA 1 ms 384 KB
20_SkewRandom_31_13 WA 1 ms 384 KB
20_SkewRandom_36_01 WA 2 ms 384 KB
20_SkewRandom_38_09 WA 2 ms 384 KB
20_SkewRandom_41_17 WA 2 ms 384 KB
20_SkewRandom_47_05 WA 2 ms 384 KB
20_SkewRandom_50_02 WA 2 ms 512 KB
20_SkewRandom_50_03 WA 2 ms 512 KB
20_SkewRandom_50_06 WA 2 ms 512 KB
20_SkewRandom_50_07 WA 2 ms 512 KB
20_SkewRandom_50_10 WA 2 ms 512 KB
20_SkewRandom_50_11 WA 2 ms 512 KB
20_SkewRandom_50_14 WA 2 ms 512 KB
20_SkewRandom_50_15 WA 2 ms 512 KB
20_SkewRandom_50_18 WA 2 ms 512 KB
20_SkewRandom_50_19 WA 2 ms 512 KB
90_teuchi_00 AC 2 ms 512 KB
90_teuchi_01 AC 1 ms 256 KB
90_teuchi_02 AC 1 ms 256 KB
90_teuchi_03 AC 2 ms 512 KB