답안 #112694

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
112694 2019-05-21T14:00:37 Z arnold518 물통 (KOI17_bucket) C++14
100 / 100
597 ms 25456 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

int a, b, c, d;
struct Queue { int x, y, v; };
map<pii, int> vis;

queue<Queue> Q;

void enque(Queue p)
{
    if(vis.count({p.x, p.y})) return;
    vis[{p.x, p.y}]=p.v;
    Q.push(p);
}

int main()
{
    int i, j;
    scanf("%d%d%d%d", &a, &b, &c, &d);

    Q.push({0, 0, 0}); vis[{0, 0}];
    while(!Q.empty())
    {
        Queue now=Q.front();
        Q.pop();

        int s=now.x+now.y;
        Queue nxt; nxt.v=now.v+1;

        nxt.y=min(s, b); nxt.x=s-nxt.y;
        enque(nxt);

        nxt.x=min(s, a); nxt.y=s-nxt.x;
        enque(nxt);

        nxt.x=a; nxt.y=now.y;
        enque(nxt);

        nxt.x=now.x; nxt.y=b;
        enque(nxt);

        nxt.x=0; nxt.y=now.y;
        enque(nxt);

        nxt.x=now.x; nxt.y=0;
        enque(nxt);
    }
    if(vis.count({c, d})) printf("%d", vis[{c, d}]);
    else printf("-1");
}

Compilation message

bucket.cpp: In function 'int main()':
bucket.cpp:25:9: warning: unused variable 'i' [-Wunused-variable]
     int i, j;
         ^
bucket.cpp:25:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
bucket.cpp:26: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);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 10 ms 1152 KB Output is correct
7 Correct 52 ms 3960 KB Output is correct
8 Correct 235 ms 12872 KB Output is correct
9 Correct 246 ms 13012 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 10 ms 1152 KB Output is correct
7 Correct 52 ms 3960 KB Output is correct
8 Correct 235 ms 12872 KB Output is correct
9 Correct 246 ms 13012 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 15 ms 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 640 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 10 ms 1152 KB Output is correct
7 Correct 52 ms 3960 KB Output is correct
8 Correct 235 ms 12872 KB Output is correct
9 Correct 246 ms 13012 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 15 ms 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 4 ms 640 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 13 ms 1408 KB Output is correct
32 Correct 22 ms 2048 KB Output is correct
33 Correct 200 ms 12940 KB Output is correct
34 Correct 14 ms 1536 KB Output is correct
35 Correct 7 ms 896 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 13 ms 1408 KB Output is correct
38 Correct 19 ms 1664 KB Output is correct
39 Correct 15 ms 1664 KB Output is correct
40 Correct 7 ms 896 KB Output is correct
41 Correct 43 ms 4088 KB Output is correct
42 Correct 53 ms 5112 KB Output is correct
43 Correct 26 ms 2552 KB Output is correct
44 Correct 16 ms 1792 KB Output is correct
45 Correct 597 ms 25456 KB Output is correct
46 Correct 2 ms 384 KB Output is correct