답안 #233886

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
233886 2020-05-22T09:29:32 Z LittleFlowers__ Dango Maker (JOI18_dango_maker) C++17
33 / 100
24 ms 29184 KB
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0);
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define gg exit(0);

struct pack{
    int u,v,c;
};

const int N=5010,
          INF=1e9;

int m,n;
int a[N][N];

vector<pack> e;
vector<int> ad[N];
int it,s,t;
int tr[N],id[N][N],st[N][N],ed[N][N];

void add(int u,int v){
    ad[u].pb(e.size()); e.pb({u,v,1});
    ad[v].pb(e.size()); e.pb({v,u,0});
}

int bfs(){
    reset(tr,-1);
    queue<int> q; q.push(s); tr[s]=-2;
    while(q.size()){
        int u=q.front(); q.pop();
        if(u==t) return 1;
        forv(i,ad[u]){
            if(tr[e[i].v]==-1 && e[i].c)
                tr[e[i].v]=i, q.push(e[i].v);
        }
    }
    return 0;
}

main(){
    #define task "rgw"
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    fasty;

    cin>>m>>n;
    forinc(i,1,m){
        string s; cin>>s;
        forinc(j,1,n){
            a[i][j]=s[j-1]=='R' ? 1 : s[j-1]=='G' ? 2 : 3;
        }
    }

    forinc(i,1,m) forinc(j,1,n) if(a[i][j]==1) id[i][j]=++it;
    forinc(i,1,m) forinc(j,1,n) if(a[i][j]==3) id[i][j]=++it;
    forinc(i,1,m) forinc(j,1,n) if(a[i][j]==2) st[i][j]=++it, ed[i][j]=++it, add(it-1,it);

    forinc(i,1,m) forinc(j,1,n) if(a[i][j]==2){
        if(1<i && i<m && a[i][j]+a[i-1][j]+a[i+1][j]==6 && a[i-1][j]==1)
            add(id[i-1][j],st[i][j]), add(ed[i][j],id[i+1][j]);
        if(1<j && j<n && a[i][j]+a[i][j-1]+a[i][j+1]==6 && a[i][j-1]==1)
            add(id[i][j-1],st[i][j]), add(ed[i][j],id[i][j+1]);
    }

    s=++it, t=++it;

    forinc(i,1,m) forinc(j,1,n) if(a[i][j]==1) add(s,id[i][j]);
    forinc(i,1,m) forinc(j,1,n) if(a[i][j]==3) add(id[i][j],t);

    int flow=0;
    while(bfs()){
        int d=INF;
        int u=t;
        vector<int> path;
        while(u!=s){
            d=min(d,e[tr[u]].c);
            path.push_back(tr[u]);
            u=e[tr[u]].u;
        }
        forv(i,path) e[i].c-=d, e[i^1].c+=d;
        flow+=d;
    }
    cout<<flow;
}

Compilation message

dango_maker.cpp:56:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 640 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 640 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 640 KB Output is correct
19 Correct 5 ms 640 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 5 ms 640 KB Output is correct
22 Correct 5 ms 640 KB Output is correct
23 Correct 5 ms 640 KB Output is correct
24 Correct 5 ms 640 KB Output is correct
25 Correct 5 ms 640 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 5 ms 640 KB Output is correct
28 Correct 5 ms 640 KB Output is correct
29 Correct 5 ms 640 KB Output is correct
30 Correct 5 ms 640 KB Output is correct
31 Correct 5 ms 640 KB Output is correct
32 Correct 5 ms 640 KB Output is correct
33 Correct 5 ms 640 KB Output is correct
34 Correct 5 ms 640 KB Output is correct
35 Correct 5 ms 640 KB Output is correct
36 Correct 5 ms 640 KB Output is correct
37 Correct 5 ms 640 KB Output is correct
38 Correct 5 ms 640 KB Output is correct
39 Correct 5 ms 640 KB Output is correct
40 Correct 5 ms 640 KB Output is correct
41 Correct 5 ms 640 KB Output is correct
42 Correct 5 ms 640 KB Output is correct
43 Correct 5 ms 640 KB Output is correct
44 Correct 5 ms 640 KB Output is correct
45 Correct 5 ms 640 KB Output is correct
46 Correct 5 ms 640 KB Output is correct
47 Correct 5 ms 640 KB Output is correct
48 Correct 5 ms 640 KB Output is correct
49 Correct 5 ms 640 KB Output is correct
50 Correct 5 ms 640 KB Output is correct
51 Correct 5 ms 640 KB Output is correct
52 Correct 5 ms 640 KB Output is correct
53 Correct 5 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 640 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 640 KB Output is correct
19 Correct 5 ms 640 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 5 ms 640 KB Output is correct
22 Correct 5 ms 640 KB Output is correct
23 Correct 5 ms 640 KB Output is correct
24 Correct 5 ms 640 KB Output is correct
25 Correct 5 ms 640 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 5 ms 640 KB Output is correct
28 Correct 5 ms 640 KB Output is correct
29 Correct 5 ms 640 KB Output is correct
30 Correct 5 ms 640 KB Output is correct
31 Correct 5 ms 640 KB Output is correct
32 Correct 5 ms 640 KB Output is correct
33 Correct 5 ms 640 KB Output is correct
34 Correct 5 ms 640 KB Output is correct
35 Correct 5 ms 640 KB Output is correct
36 Correct 5 ms 640 KB Output is correct
37 Correct 5 ms 640 KB Output is correct
38 Correct 5 ms 640 KB Output is correct
39 Correct 5 ms 640 KB Output is correct
40 Correct 5 ms 640 KB Output is correct
41 Correct 5 ms 640 KB Output is correct
42 Correct 5 ms 640 KB Output is correct
43 Correct 5 ms 640 KB Output is correct
44 Correct 5 ms 640 KB Output is correct
45 Correct 5 ms 640 KB Output is correct
46 Correct 5 ms 640 KB Output is correct
47 Correct 5 ms 640 KB Output is correct
48 Correct 5 ms 640 KB Output is correct
49 Correct 5 ms 640 KB Output is correct
50 Correct 5 ms 640 KB Output is correct
51 Correct 5 ms 640 KB Output is correct
52 Correct 5 ms 640 KB Output is correct
53 Correct 5 ms 640 KB Output is correct
54 Correct 8 ms 896 KB Output is correct
55 Correct 20 ms 29184 KB Output is correct
56 Runtime error 24 ms 2936 KB Execution killed with signal 11 (could be triggered by violating memory limits)
57 Halted 0 ms 0 KB -