Submission #43933

# Submission time Handle Problem Language Result Execution time Memory
43933 2018-03-28T11:02:51 Z Kerim Jakarta Skyscrapers (APIO15_skyscraper) C++17
36 / 100
1000 ms 262144 KB
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define BLOK 555
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
PII arr[MAXN];
int dis[MAXN];
vector<PII>adj[MAXN];
int s,t;
bool vis[30009][BLOK+5];
int main(){
    //~ freopen("file.in", "r", stdin);
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		if(i==1)
			s=u;
		if(i==2)
			t=u;
		arr[i]=mp(u,v);	
	}
	sort(arr+1,arr+m+1);
	for(int i=m;i>=1;i--){
		int cur=1;
		int u=arr[i].ff,v=arr[i].ss;
		for(int j=u+v;j<n;j+=v){
			adj[u].pb(mp(j,cur));	
			//~ cout<<u<<" "<<j<<" "<<cur<<endl;
			if(v<BLOK and vis[j][v])
				break;
			//might be break condition
			cur++;
		}
		if(v<BLOK)
			vis[u][v]=1;
	}memset(vis,0,sizeof vis);
	for(int i=1;i<=m;i++){
		int cur=1;
		int u=arr[i].ff,v=arr[i].ss;
		for(int j=u-v;j>=0;j-=v){
			//~ cout<<u<<" "<<j<<" "<<cur<<endl;
			adj[u].pb(mp(j,cur));	
			if(v<BLOK and vis[j][v])
				break;
			//might be break condition
			cur++;
		}
		if(v<BLOK)
			vis[u][v]=1;
	}
	priority_queue<pair<int,int> >q;
	q.push(mp(0,s));
	for(int i=0;i<n;i++)
		dis[i]=INF;
	dis[s]=0;
	while(!q.empty()){
		int val=-q.top().ff;
		int nd=q.top().ss;
		q.pop();
		if(dis[nd]!=val)
			continue;
		tr(it,adj[nd])
			if(umin(dis[it->ff],dis[nd]+it->ss))
				q.push(mp(-dis[it->ff],it->ff));
	}
	if(dis[t]==INF)
		dis[t]=-1;
	printf("%d\n",dis[t]);
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&u,&v);
   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 19064 KB Output is correct
2 Correct 15 ms 19172 KB Output is correct
3 Correct 14 ms 19172 KB Output is correct
4 Correct 16 ms 19264 KB Output is correct
5 Correct 16 ms 19264 KB Output is correct
6 Correct 15 ms 19344 KB Output is correct
7 Correct 15 ms 19344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 19400 KB Output is correct
2 Correct 15 ms 19400 KB Output is correct
3 Correct 17 ms 19404 KB Output is correct
4 Correct 15 ms 19404 KB Output is correct
5 Correct 16 ms 19404 KB Output is correct
6 Correct 15 ms 19404 KB Output is correct
7 Correct 16 ms 19404 KB Output is correct
8 Correct 15 ms 19404 KB Output is correct
9 Correct 16 ms 19404 KB Output is correct
10 Correct 15 ms 19404 KB Output is correct
11 Correct 16 ms 19436 KB Output is correct
12 Correct 19 ms 21656 KB Output is correct
13 Correct 17 ms 21656 KB Output is correct
14 Correct 16 ms 21656 KB Output is correct
15 Correct 16 ms 21656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 21656 KB Output is correct
2 Correct 15 ms 21656 KB Output is correct
3 Correct 15 ms 21656 KB Output is correct
4 Correct 17 ms 21656 KB Output is correct
5 Correct 20 ms 21656 KB Output is correct
6 Correct 15 ms 21656 KB Output is correct
7 Correct 15 ms 21656 KB Output is correct
8 Correct 15 ms 21656 KB Output is correct
9 Correct 15 ms 21656 KB Output is correct
10 Correct 15 ms 21656 KB Output is correct
11 Correct 16 ms 21656 KB Output is correct
12 Correct 21 ms 21656 KB Output is correct
13 Correct 15 ms 21656 KB Output is correct
14 Correct 15 ms 21656 KB Output is correct
15 Correct 17 ms 21656 KB Output is correct
16 Correct 16 ms 21656 KB Output is correct
17 Correct 19 ms 21656 KB Output is correct
18 Correct 16 ms 21656 KB Output is correct
19 Correct 16 ms 21656 KB Output is correct
20 Correct 19 ms 21656 KB Output is correct
21 Correct 15 ms 21656 KB Output is correct
22 Correct 16 ms 21656 KB Output is correct
23 Correct 16 ms 21656 KB Output is correct
24 Correct 18 ms 21656 KB Output is correct
25 Correct 17 ms 21656 KB Output is correct
26 Correct 100 ms 52396 KB Output is correct
27 Correct 96 ms 52416 KB Output is correct
28 Correct 17 ms 52416 KB Output is correct
29 Correct 20 ms 52416 KB Output is correct
30 Correct 16 ms 52416 KB Output is correct
31 Correct 17 ms 52416 KB Output is correct
32 Correct 16 ms 52416 KB Output is correct
33 Correct 20 ms 52416 KB Output is correct
34 Correct 20 ms 52416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 52416 KB Output is correct
2 Correct 16 ms 52416 KB Output is correct
3 Correct 15 ms 52416 KB Output is correct
4 Correct 15 ms 52416 KB Output is correct
5 Correct 15 ms 52416 KB Output is correct
6 Correct 16 ms 52416 KB Output is correct
7 Correct 16 ms 52416 KB Output is correct
8 Correct 15 ms 52416 KB Output is correct
9 Correct 15 ms 52416 KB Output is correct
10 Correct 15 ms 52416 KB Output is correct
11 Correct 16 ms 52416 KB Output is correct
12 Correct 20 ms 52416 KB Output is correct
13 Correct 15 ms 52416 KB Output is correct
14 Correct 18 ms 52416 KB Output is correct
15 Correct 17 ms 52416 KB Output is correct
16 Correct 15 ms 52416 KB Output is correct
17 Correct 17 ms 52416 KB Output is correct
18 Correct 15 ms 52416 KB Output is correct
19 Correct 18 ms 52416 KB Output is correct
20 Correct 17 ms 52416 KB Output is correct
21 Correct 17 ms 52416 KB Output is correct
22 Correct 16 ms 52416 KB Output is correct
23 Correct 18 ms 52416 KB Output is correct
24 Correct 19 ms 52416 KB Output is correct
25 Correct 18 ms 52416 KB Output is correct
26 Correct 102 ms 52416 KB Output is correct
27 Correct 104 ms 52416 KB Output is correct
28 Correct 18 ms 52416 KB Output is correct
29 Correct 19 ms 52416 KB Output is correct
30 Correct 18 ms 52416 KB Output is correct
31 Correct 22 ms 52416 KB Output is correct
32 Correct 18 ms 52416 KB Output is correct
33 Correct 25 ms 52416 KB Output is correct
34 Correct 22 ms 52416 KB Output is correct
35 Correct 31 ms 52416 KB Output is correct
36 Correct 21 ms 52416 KB Output is correct
37 Correct 33 ms 52416 KB Output is correct
38 Correct 41 ms 52416 KB Output is correct
39 Correct 34 ms 52416 KB Output is correct
40 Correct 33 ms 52416 KB Output is correct
41 Correct 35 ms 52416 KB Output is correct
42 Execution timed out 1109 ms 262144 KB Time limit exceeded
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 262144 KB Output is correct
2 Correct 17 ms 262144 KB Output is correct
3 Correct 20 ms 262144 KB Output is correct
4 Correct 20 ms 262144 KB Output is correct
5 Correct 18 ms 262144 KB Output is correct
6 Correct 20 ms 262144 KB Output is correct
7 Correct 19 ms 262144 KB Output is correct
8 Correct 20 ms 262144 KB Output is correct
9 Correct 17 ms 262144 KB Output is correct
10 Correct 15 ms 262144 KB Output is correct
11 Correct 15 ms 262144 KB Output is correct
12 Correct 19 ms 262144 KB Output is correct
13 Correct 16 ms 262144 KB Output is correct
14 Correct 16 ms 262144 KB Output is correct
15 Correct 16 ms 262144 KB Output is correct
16 Correct 15 ms 262144 KB Output is correct
17 Correct 18 ms 262144 KB Output is correct
18 Correct 19 ms 262144 KB Output is correct
19 Correct 15 ms 262144 KB Output is correct
20 Correct 17 ms 262144 KB Output is correct
21 Correct 15 ms 262144 KB Output is correct
22 Correct 16 ms 262144 KB Output is correct
23 Correct 15 ms 262144 KB Output is correct
24 Correct 18 ms 262144 KB Output is correct
25 Correct 18 ms 262144 KB Output is correct
26 Correct 105 ms 262144 KB Output is correct
27 Correct 105 ms 262144 KB Output is correct
28 Correct 17 ms 262144 KB Output is correct
29 Correct 38 ms 262144 KB Output is correct
30 Correct 18 ms 262144 KB Output is correct
31 Correct 17 ms 262144 KB Output is correct
32 Correct 17 ms 262144 KB Output is correct
33 Correct 20 ms 262144 KB Output is correct
34 Correct 21 ms 262144 KB Output is correct
35 Correct 29 ms 262144 KB Output is correct
36 Correct 20 ms 262144 KB Output is correct
37 Correct 29 ms 262144 KB Output is correct
38 Correct 33 ms 262144 KB Output is correct
39 Correct 32 ms 262144 KB Output is correct
40 Correct 31 ms 262144 KB Output is correct
41 Correct 31 ms 262144 KB Output is correct
42 Execution timed out 1114 ms 262144 KB Time limit exceeded
43 Halted 0 ms 0 KB -