답안 #544634

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544634 2022-04-02T14:08:48 Z pokmui9909 물통 (KOI17_bucket) C++17
100 / 100
467 ms 18312 KB
#include <bits/stdc++.h>
using namespace std;

int a, b, c, d;
struct water
{
    int a, b, lvl;
};
set<pair<int, int>> visited;

void push(queue<water> &q, int v1, int v2, int t)
{
    if(visited.count({v1, v2})) return;
    visited.insert({v1, v2});
    q.push({v1, v2, t});
    if(v1 == c && v2 == d)
    {
        cout << t;
        exit(0);
    }
}

void bfs()
{
    queue<water> q;
    push(q, 0, 0, 0);
    while(!q.empty())
    {
        int x=q.front().a, y=q.front().b, lvl=q.front().lvl;
        //cout << x << ' ' << y << ' ' << lvl << '\n';
        q.pop();
        push(q, a, y, lvl + 1);
        push(q, x, b, lvl + 1);
        push(q, 0, y, lvl + 1);
        push(q, x, 0, lvl + 1);
        int k;
        // 1 -> 2
        if(x >= b - y) push(q, x - b + y, b, lvl + 1);
        else push(q, 0, x + y, lvl + 1);
        // 2 -> 1
        if(y >= a - x) push(q, a, y - a + x, lvl + 1);
        else push(q, x + y, 0, lvl + 1);
    }
}

int main()
{
	cin.tie(NULL); cout.tie(NULL);
	ios_base::sync_with_stdio(false);

    cin >>a >> b >> c >> d;
    bfs();
    cout << -1;
}

Compilation message

bucket.cpp: In function 'void bfs()':
bucket.cpp:36:13: warning: unused variable 'k' [-Wunused-variable]
   36 |         int k;
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 27 ms 2132 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 27 ms 2132 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 224 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 324 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 27 ms 2132 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 324 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 224 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 5 ms 596 KB Output is correct
34 Correct 175 ms 9732 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 4 ms 520 KB Output is correct
37 Correct 3 ms 340 KB Output is correct
38 Correct 7 ms 688 KB Output is correct
39 Correct 18 ms 1232 KB Output is correct
40 Correct 6 ms 704 KB Output is correct
41 Correct 6 ms 740 KB Output is correct
42 Correct 18 ms 1616 KB Output is correct
43 Correct 47 ms 3388 KB Output is correct
44 Correct 22 ms 1964 KB Output is correct
45 Correct 15 ms 1420 KB Output is correct
46 Correct 467 ms 18312 KB Output is correct