Submission #60520

# Submission time Handle Problem Language Result Execution time Memory
60520 2018-07-24T09:37:43 Z istlemin Jakarta Skyscrapers (APIO15_skyscraper) C++14
22 / 100
1000 ms 33864 KB
#include<bits/stdc++.h>

using namespace std;

#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;

int main(){
	cin.sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;

    vi b(m);
    vi p(m);


    vector<set<ll> > doges(n);
    vector<vi> e;

    rep(i,0,m) {
		cin>>b[i]>>p[i];
        doges[b[i]].insert(i);
	}

    priority_queue<pair<ll,ll>,vector<pii>,greater<pii> > q; //(jumps,doge);
    q.emplace(0,b[0]);

    vector<bool> seen(n);

    while(q.size()){
        ll pos,jumps;
        tie(jumps,pos) = q.top();
        q.pop();
        //cout<<pos<<" "<<jumps<<": "<<endl;

		if(seen[pos]) continue;
		seen[pos] = true;


        vector<bool> seenHere(n);

		trav(doge,doges[pos]){
			if(doge==1){
				cout<<jumps<<endl;
				return 0;
			}
			//rep(i,0,n)
			//	if((i-pos)%p[doge]==0&&!seen[i])
			//		q.emplace(jumps+abs(i-pos)/p[doge],i);
			ll pi = p[doge];
            rep(i,1,n/pi+1){
				//cout<<pos+pi*i<<endl;
				if(pos+pi*i<n) {
					//if(seenHere[pos+pi*i]) break;
					//seenHere[pos+pi*i] = true;
					q.emplace(jumps+i,pos+pi*i);
				}
				if(pos-pi*i>=0) {
					//if(seenHere[pos-pi*i]) break;
					//seenHere[pos-pi*i] = true;
					q.emplace(jumps+i,pos-pi*i);
				}
            }
		}
        /*rep(i,0,n){
            if((b[i]-b[doge])%p[doge]==0&&!seen[i])
				q.emplace(jumps+abs(b[i]-b[doge])/p[doge],i);
        }*/
    }

    cout<<-1<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 3 ms 488 KB Output is correct
5 Correct 3 ms 492 KB Output is correct
6 Correct 3 ms 568 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 620 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 3 ms 624 KB Output is correct
4 Correct 3 ms 624 KB Output is correct
5 Correct 2 ms 624 KB Output is correct
6 Correct 4 ms 624 KB Output is correct
7 Correct 3 ms 624 KB Output is correct
8 Correct 3 ms 624 KB Output is correct
9 Correct 3 ms 624 KB Output is correct
10 Correct 3 ms 624 KB Output is correct
11 Correct 3 ms 748 KB Output is correct
12 Correct 3 ms 748 KB Output is correct
13 Correct 17 ms 4912 KB Output is correct
14 Correct 5 ms 4912 KB Output is correct
15 Correct 6 ms 4912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4912 KB Output is correct
2 Correct 3 ms 4912 KB Output is correct
3 Correct 3 ms 4912 KB Output is correct
4 Correct 3 ms 4912 KB Output is correct
5 Correct 3 ms 4912 KB Output is correct
6 Correct 3 ms 4912 KB Output is correct
7 Correct 3 ms 4912 KB Output is correct
8 Correct 3 ms 4912 KB Output is correct
9 Correct 2 ms 4912 KB Output is correct
10 Correct 4 ms 4912 KB Output is correct
11 Correct 4 ms 4912 KB Output is correct
12 Correct 4 ms 4912 KB Output is correct
13 Correct 18 ms 4924 KB Output is correct
14 Correct 6 ms 4924 KB Output is correct
15 Correct 4 ms 4924 KB Output is correct
16 Correct 4 ms 4924 KB Output is correct
17 Correct 6 ms 4924 KB Output is correct
18 Correct 4 ms 4924 KB Output is correct
19 Correct 5 ms 4924 KB Output is correct
20 Execution timed out 1069 ms 33840 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 33840 KB Output is correct
2 Correct 3 ms 33840 KB Output is correct
3 Correct 3 ms 33840 KB Output is correct
4 Correct 4 ms 33840 KB Output is correct
5 Correct 2 ms 33840 KB Output is correct
6 Correct 3 ms 33840 KB Output is correct
7 Correct 3 ms 33840 KB Output is correct
8 Correct 3 ms 33840 KB Output is correct
9 Correct 4 ms 33840 KB Output is correct
10 Correct 2 ms 33840 KB Output is correct
11 Correct 3 ms 33840 KB Output is correct
12 Correct 3 ms 33840 KB Output is correct
13 Correct 16 ms 33840 KB Output is correct
14 Correct 5 ms 33840 KB Output is correct
15 Correct 3 ms 33840 KB Output is correct
16 Correct 4 ms 33840 KB Output is correct
17 Correct 5 ms 33840 KB Output is correct
18 Correct 3 ms 33840 KB Output is correct
19 Correct 4 ms 33840 KB Output is correct
20 Execution timed out 1081 ms 33864 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 33864 KB Output is correct
2 Correct 2 ms 33864 KB Output is correct
3 Correct 3 ms 33864 KB Output is correct
4 Correct 2 ms 33864 KB Output is correct
5 Correct 2 ms 33864 KB Output is correct
6 Correct 3 ms 33864 KB Output is correct
7 Correct 3 ms 33864 KB Output is correct
8 Correct 2 ms 33864 KB Output is correct
9 Correct 3 ms 33864 KB Output is correct
10 Correct 3 ms 33864 KB Output is correct
11 Correct 5 ms 33864 KB Output is correct
12 Correct 4 ms 33864 KB Output is correct
13 Correct 19 ms 33864 KB Output is correct
14 Correct 5 ms 33864 KB Output is correct
15 Correct 4 ms 33864 KB Output is correct
16 Correct 2 ms 33864 KB Output is correct
17 Correct 5 ms 33864 KB Output is correct
18 Correct 3 ms 33864 KB Output is correct
19 Correct 3 ms 33864 KB Output is correct
20 Execution timed out 1054 ms 33864 KB Time limit exceeded
21 Halted 0 ms 0 KB -