Submission #71864

# Submission time Handle Problem Language Result Execution time Memory
71864 2018-08-25T17:31:23 Z 비타오백(#2241, junodeveloper) Angelic Hourglass (FXCUP3_hourglass) C++17
100 / 100
10 ms 1008 KB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
const int INF = 1e9;
struct Z {
	int w,t,a,b;
	bool operator<(const Z& b) const { return w > b.w; }
};
int n;
int dist[5001][4][6];
int main() {
	scanf("%d",&n);
	for(int i=0; i<=n; i++) for(int j=0; j<=3; j++) for(int k=0; k<=5; k++)
		dist[i][j][k]=INF;
	priority_queue<Z> pq;
	pq.push({0,0,0,0}); dist[0][0][0] = 0;
	while(!pq.empty()) {
		Z top = pq.top(); pq.pop();
		int t=top.t,a=top.a,b=top.b,w=top.w;
		if(dist[t][a][b] < w) continue;
		if(!a || !b) {
			if(w+1<dist[t][3-a][b]) { dist[t][3-a][b]=w+1; pq.push({w+1,t,3-a,b}); }
			if(w+1<dist[t][a][5-b]) { dist[t][a][5-b]=w+1; pq.push({w+1,t,a,5-b}); }
		}
		if(t+a<=n&&w<dist[t+a][0][max(0,b-a)]) { dist[t+a][0][max(0,b-a)]=w; pq.push({w,t+a,0,max(0,b-a)}); }
		if(t+b<=n&&w<dist[t+b][max(0,a-b)][0]) { dist[t+b][max(0,a-b)][0]=w; pq.push({w,t+b,max(0,a-b),0}); }
	}
	int res = INF;
	for(int i=0; i<=3; i++) for(int j=0; j<=5; j++)
		res = min(res, dist[n][i][j]);
	printf("%d", res==INF?-1:res);
	return 0;
}

Compilation message

hourglass.cpp: In function 'int main()':
hourglass.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 868 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 8 ms 868 KB Output is correct
4 Correct 10 ms 868 KB Output is correct
5 Correct 3 ms 868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 868 KB Output is correct
2 Correct 2 ms 868 KB Output is correct
3 Correct 2 ms 868 KB Output is correct
4 Correct 2 ms 868 KB Output is correct
5 Correct 2 ms 868 KB Output is correct
6 Correct 3 ms 868 KB Output is correct
7 Correct 2 ms 868 KB Output is correct
8 Correct 3 ms 868 KB Output is correct
9 Correct 2 ms 868 KB Output is correct
10 Correct 2 ms 868 KB Output is correct
11 Correct 2 ms 868 KB Output is correct
12 Correct 3 ms 868 KB Output is correct
13 Correct 2 ms 868 KB Output is correct
14 Correct 3 ms 868 KB Output is correct
15 Correct 2 ms 868 KB Output is correct
16 Correct 3 ms 868 KB Output is correct
17 Correct 2 ms 868 KB Output is correct
18 Correct 2 ms 868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 868 KB Output is correct
2 Correct 3 ms 868 KB Output is correct
3 Correct 5 ms 868 KB Output is correct
4 Correct 2 ms 868 KB Output is correct
5 Correct 10 ms 1008 KB Output is correct
6 Correct 3 ms 868 KB Output is correct
7 Correct 9 ms 1008 KB Output is correct
8 Correct 2 ms 868 KB Output is correct
9 Correct 7 ms 868 KB Output is correct
10 Correct 3 ms 868 KB Output is correct
11 Correct 2 ms 868 KB Output is correct
12 Correct 3 ms 868 KB Output is correct