Submission #71864

#TimeUsernameProblemLanguageResultExecution timeMemory
71864비타오백 (#119)Angelic Hourglass (FXCUP3_hourglass)C++17
100 / 100
10 ms1008 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...