Submission #58998

# Submission time Handle Problem Language Result Execution time Memory
58998 2018-07-20T02:08:55 Z andy627 None (KOI17_bucket) C++17
100 / 100
472 ms 24916 KB
#include <stdio.h>
#include <queue>
#include <map>
#include <algorithm>
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;

map<pii,int> mp;
queue<pii> q;

int main(){
    int a,b,c,d;

    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a!=c && c && b!=d && d){printf("-1");return 0;}
    if(c==0 && d==0){printf("0");return 0;}

    mp[{0,0}]=0; q.push({0,0});
    while(!q.empty()){
        int pa=q.front().ff;
        int pb=q.front().ss; q.pop();
        int pd=mp[{pa,pb}];

        if(pa==c && pb==d){printf("%d",pd);return 0;}

        if(pa && mp.find({0,pb})==mp.end()) mp[{0,pb}]=pd+1,q.push({0,pb});
        if(pb && mp.find({pa,0})==mp.end()) mp[{pa,0}]=pd+1,q.push({pa,0});
        if(pa!=a){
            if(mp.find({a,pb})==mp.end()) mp[{a,pb}]=pd+1,q.push({a,pb});
            if(pa+pb>a && mp.find({a,pa+pb-a})==mp.end()) mp[{a,pa+pb-a}]=pd+1,q.push({a,pa+pb-a});
            if(pa+pb<=a && mp.find({pa+pb,0})==mp.end()) mp[{pa+pb,0}]=pd+1,q.push({pa+pb,0});
        }
        if(pb!=b){
            if(mp.find({pa,b})==mp.end()) mp[{pa,b}]=pd+1,q.push({pa,b});
            if(pa+pb>b && mp.find({pa+pb-b,b})==mp.end()) mp[{pa+pb-b,b}]=pd+1,q.push({pa+pb-b,b});
            if(pa+pb<=b && mp.find({0,pa+pb})==mp.end()) mp[{0,pa+pb}]=pd+1,q.push({0,pa+pb});
        }

        //printf("%d %d %d\n",q.front().ff,q.front().ss,q.size());
    }

    printf("-1");

    return 0;
}

Compilation message

bucket.cpp: In function 'int main()':
bucket.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d",&a,&b,&c,&d);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 520 KB Output is correct
6 Correct 3 ms 700 KB Output is correct
7 Correct 33 ms 3176 KB Output is correct
8 Correct 2 ms 3176 KB Output is correct
9 Correct 2 ms 3176 KB Output is correct
10 Correct 2 ms 3176 KB Output is correct
11 Correct 2 ms 3176 KB Output is correct
12 Correct 2 ms 3176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 520 KB Output is correct
6 Correct 3 ms 700 KB Output is correct
7 Correct 33 ms 3176 KB Output is correct
8 Correct 2 ms 3176 KB Output is correct
9 Correct 2 ms 3176 KB Output is correct
10 Correct 2 ms 3176 KB Output is correct
11 Correct 2 ms 3176 KB Output is correct
12 Correct 2 ms 3176 KB Output is correct
13 Correct 2 ms 3176 KB Output is correct
14 Correct 2 ms 3176 KB Output is correct
15 Correct 3 ms 3176 KB Output is correct
16 Correct 2 ms 3176 KB Output is correct
17 Correct 3 ms 3176 KB Output is correct
18 Correct 2 ms 3176 KB Output is correct
19 Correct 2 ms 3176 KB Output is correct
20 Correct 2 ms 3176 KB Output is correct
21 Correct 2 ms 3176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3176 KB Output is correct
2 Correct 3 ms 3176 KB Output is correct
3 Correct 2 ms 3176 KB Output is correct
4 Correct 2 ms 3176 KB Output is correct
5 Correct 3 ms 3176 KB Output is correct
6 Correct 3 ms 3176 KB Output is correct
7 Correct 4 ms 3176 KB Output is correct
8 Correct 5 ms 3176 KB Output is correct
9 Correct 2 ms 3176 KB Output is correct
10 Correct 2 ms 3176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 520 KB Output is correct
6 Correct 3 ms 700 KB Output is correct
7 Correct 33 ms 3176 KB Output is correct
8 Correct 2 ms 3176 KB Output is correct
9 Correct 2 ms 3176 KB Output is correct
10 Correct 2 ms 3176 KB Output is correct
11 Correct 2 ms 3176 KB Output is correct
12 Correct 2 ms 3176 KB Output is correct
13 Correct 2 ms 3176 KB Output is correct
14 Correct 2 ms 3176 KB Output is correct
15 Correct 3 ms 3176 KB Output is correct
16 Correct 2 ms 3176 KB Output is correct
17 Correct 3 ms 3176 KB Output is correct
18 Correct 2 ms 3176 KB Output is correct
19 Correct 2 ms 3176 KB Output is correct
20 Correct 2 ms 3176 KB Output is correct
21 Correct 3 ms 3176 KB Output is correct
22 Correct 3 ms 3176 KB Output is correct
23 Correct 2 ms 3176 KB Output is correct
24 Correct 2 ms 3176 KB Output is correct
25 Correct 3 ms 3176 KB Output is correct
26 Correct 3 ms 3176 KB Output is correct
27 Correct 4 ms 3176 KB Output is correct
28 Correct 5 ms 3176 KB Output is correct
29 Correct 2 ms 3176 KB Output is correct
30 Correct 2 ms 3176 KB Output is correct
31 Correct 5 ms 3176 KB Output is correct
32 Correct 9 ms 3176 KB Output is correct
33 Correct 3 ms 3176 KB Output is correct
34 Correct 5 ms 3176 KB Output is correct
35 Correct 5 ms 3176 KB Output is correct
36 Correct 4 ms 3176 KB Output is correct
37 Correct 10 ms 3176 KB Output is correct
38 Correct 3 ms 3176 KB Output is correct
39 Correct 10 ms 3176 KB Output is correct
40 Correct 9 ms 3176 KB Output is correct
41 Correct 25 ms 3176 KB Output is correct
42 Correct 66 ms 4972 KB Output is correct
43 Correct 38 ms 4972 KB Output is correct
44 Correct 18 ms 4972 KB Output is correct
45 Correct 472 ms 24916 KB Output is correct
46 Correct 2 ms 3176 KB Output is correct