답안 #666192

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
666192 2022-11-27T17:19:47 Z nolimiya Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
659 ms 31352 KB
#include <bits/stdc++.h>
#include <math.h>
//in the name of god,aka allah
//**gray sety orz**
using namespace std;
#define pi pair<int , int>
#define pii pair<long long , pair<long long , long long>>
const int maxm = 3e4 + 5;
const long long mod = 1e9 + 7;
const int SQ = 176;
typedef long long ll;
int l,r,mid;
int n,m;
ll dis[maxm] , sum[maxm];
bool isval(int mid){
    //cout << mid <<" " << mid*mid-mid <<endl;
    if (((mid-1)*mid)/2 < m) return 0;
    return 1;
}
int darage[maxm] , ss , mm;
queue<int> q;
vector<int> g[maxm] , z[maxm];
ll sath[maxm];
bool vis[maxm*SQ] , gos[maxm];
int pedaret[maxm*SQ];
ll get_par(ll v){
    if (pedaret[v]==v) return v;
    return pedaret[v] = get_par(pedaret[v]);
}
ll pars1[maxm] , pars2[maxm];
vector<ll> se[maxm];
set<ll> st,ts;
int rp[maxm] , pr[maxm];
ll dp[maxm*SQ];
pi w[maxm];
int rw[400][400];
int dage[maxm*SQ];
map<ll,ll> mp,pm,f;
priority_queue<pi> lowq;
priority_queue<int, vector<int>, greater<int> > upq;
void bfs(int k){
	q.push(k);
	vis[k] = 1;
	while (q.size()){
		auto x = q.front();
		q.pop();
		for (auto m : g[x]){
			if (!vis[m]) vis[m] = 1 , q.push(m) , darage[m] = darage[x] + 1;
		}
	}
}
vector<int> vec;
void prep(){
	for (int i=1; i<=n; i++) vis[i] = darage[i] = 0;
}
void solve(ll x){
	for (int i=0; i<31; i++){
		if (x&(1<<i)) dp[i]++;
	}
	return ;
}
bool val(int x){
	//cout<<x<<" ";
	if (x>n/2) return 0;
	for (int i=1; i<=x; i++){
		//cout<<x<<" "<<pedaret[n-x+i]<<" "<<pedaret[i]<<endl;
		if (pedaret[n-x+i]-pedaret[i]<m) return 0;
	}
	return 1;
}
string k[maxm],t[maxm];
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >>n>>m;
    int sq = sqrt(n)+1;
    for (int i=0; i<m; i++){
    	cin >>rp[i]>>pr[i];
    	if (i==0) l = rp[i];
    	if (i==1) r = rp[i];
    	g[rp[i]].push_back(pr[i]);
    }
    for (int i=0; i<n*sq; i++) pedaret[i] = mod;
    pedaret[l*sq] = 0;
	lowq.push({0,l*sq});
	while (lowq.size()){
		auto x =(lowq.top()).second;
		lowq.pop();
		if (!vis[x]){
			vis[x] = 1;
			ss = x/sq , mm = x%sq;
			if (mm==0){
				for (auto k:g[ss]){
					if (k<sq){
						mid=ss*sq+k;
						if(pedaret[mid]>pedaret[x]){
							pedaret[mid] =pedaret[x];
							lowq.push({-pedaret[mid],mid});
						}
					}
					else{
						for (int j=1; j<mod; j++){
							mid=ss-k*j;
							if (mid<0) break;
							if (pedaret[mid*sq]>pedaret[x]+j){
								pedaret[mid*sq] = pedaret[x]+j;
								lowq.push({-pedaret[mid*sq],mid*sq});
							}
						}
						for (int j = 1; j<=mod;j++){
							mid=ss+k*j;
							if (mid>=n) break;
							if (pedaret[mid*sq]>pedaret[x]+j){
								pedaret[mid*sq]=pedaret[x]+j;
								lowq.push({-pedaret[mid*sq],mid*sq});
							}
						}
					}
				}
			}
			else{
				if (pedaret[ss*sq]>pedaret[x]){
					pedaret[ss*sq] = pedaret[x] , lowq.push({-pedaret[ss*sq],ss*sq});
				}
				if(ss-mm>=0 && pedaret[(ss-mm)*sq+mm]>pedaret[x]+1){
					pedaret[(ss-mm)*sq+mm] = pedaret[x]+1;
					lowq.push({-pedaret[(ss-mm)*sq+mm],(ss-mm)*sq+mm});
				}
				if(ss+mm<n && pedaret[(ss+mm)*sq+mm]>pedaret[x]+1){
					pedaret[(ss+mm)*sq+mm] = pedaret[x]+1;
					lowq.push({-pedaret[(ss+mm)*sq+mm],(ss+mm)*sq+mm});
				}
			}
		}
	}
	if (pedaret[r*sq]==mod) return cout<<-1,0;
	cout<<pedaret[r*sq];
}

Compilation message

skyscraper.cpp: In function 'void prep()':
skyscraper.cpp:54:46: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   54 |  for (int i=1; i<=n; i++) vis[i] = darage[i] = 0;
      |                                    ~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4308 KB Output is correct
2 Correct 3 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 2 ms 4336 KB Output is correct
7 Correct 2 ms 4308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4308 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 3 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4332 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 3 ms 4332 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 2 ms 4336 KB Output is correct
11 Correct 3 ms 4308 KB Output is correct
12 Correct 3 ms 4308 KB Output is correct
13 Correct 3 ms 4308 KB Output is correct
14 Correct 3 ms 4308 KB Output is correct
15 Correct 3 ms 4308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4332 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 3 ms 4328 KB Output is correct
7 Correct 2 ms 4308 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 2 ms 4308 KB Output is correct
10 Correct 2 ms 4308 KB Output is correct
11 Correct 3 ms 4308 KB Output is correct
12 Correct 2 ms 4308 KB Output is correct
13 Correct 2 ms 4308 KB Output is correct
14 Correct 3 ms 4344 KB Output is correct
15 Correct 2 ms 4308 KB Output is correct
16 Correct 3 ms 4308 KB Output is correct
17 Correct 3 ms 4436 KB Output is correct
18 Correct 3 ms 4564 KB Output is correct
19 Correct 3 ms 4692 KB Output is correct
20 Correct 3 ms 4820 KB Output is correct
21 Correct 2 ms 4308 KB Output is correct
22 Correct 2 ms 4564 KB Output is correct
23 Correct 3 ms 4600 KB Output is correct
24 Correct 4 ms 4728 KB Output is correct
25 Correct 3 ms 4820 KB Output is correct
26 Correct 3 ms 4728 KB Output is correct
27 Correct 3 ms 4820 KB Output is correct
28 Correct 5 ms 4856 KB Output is correct
29 Correct 7 ms 4820 KB Output is correct
30 Correct 4 ms 4716 KB Output is correct
31 Correct 6 ms 4844 KB Output is correct
32 Correct 4 ms 4820 KB Output is correct
33 Correct 10 ms 4820 KB Output is correct
34 Correct 10 ms 4900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4436 KB Output is correct
2 Correct 3 ms 4328 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4332 KB Output is correct
8 Correct 3 ms 4336 KB Output is correct
9 Correct 2 ms 4328 KB Output is correct
10 Correct 3 ms 4308 KB Output is correct
11 Correct 3 ms 4308 KB Output is correct
12 Correct 3 ms 4340 KB Output is correct
13 Correct 2 ms 4344 KB Output is correct
14 Correct 3 ms 4308 KB Output is correct
15 Correct 3 ms 4308 KB Output is correct
16 Correct 3 ms 4308 KB Output is correct
17 Correct 4 ms 4436 KB Output is correct
18 Correct 3 ms 4564 KB Output is correct
19 Correct 4 ms 4720 KB Output is correct
20 Correct 3 ms 4820 KB Output is correct
21 Correct 3 ms 4308 KB Output is correct
22 Correct 3 ms 4564 KB Output is correct
23 Correct 4 ms 4820 KB Output is correct
24 Correct 4 ms 4820 KB Output is correct
25 Correct 5 ms 4872 KB Output is correct
26 Correct 3 ms 4820 KB Output is correct
27 Correct 3 ms 4820 KB Output is correct
28 Correct 4 ms 4820 KB Output is correct
29 Correct 8 ms 4836 KB Output is correct
30 Correct 5 ms 4692 KB Output is correct
31 Correct 7 ms 4820 KB Output is correct
32 Correct 4 ms 4820 KB Output is correct
33 Correct 11 ms 4820 KB Output is correct
34 Correct 11 ms 4900 KB Output is correct
35 Correct 10 ms 5236 KB Output is correct
36 Correct 5 ms 4564 KB Output is correct
37 Correct 13 ms 5252 KB Output is correct
38 Correct 14 ms 5496 KB Output is correct
39 Correct 15 ms 5460 KB Output is correct
40 Correct 14 ms 5504 KB Output is correct
41 Correct 14 ms 5496 KB Output is correct
42 Correct 7 ms 5368 KB Output is correct
43 Correct 7 ms 5432 KB Output is correct
44 Correct 7 ms 5364 KB Output is correct
45 Correct 21 ms 5496 KB Output is correct
46 Correct 15 ms 5460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4332 KB Output is correct
2 Correct 3 ms 4308 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4332 KB Output is correct
5 Correct 3 ms 4332 KB Output is correct
6 Correct 3 ms 4308 KB Output is correct
7 Correct 3 ms 4324 KB Output is correct
8 Correct 3 ms 4324 KB Output is correct
9 Correct 3 ms 4308 KB Output is correct
10 Correct 3 ms 4308 KB Output is correct
11 Correct 3 ms 4308 KB Output is correct
12 Correct 3 ms 4308 KB Output is correct
13 Correct 3 ms 4308 KB Output is correct
14 Correct 3 ms 4308 KB Output is correct
15 Correct 3 ms 4308 KB Output is correct
16 Correct 3 ms 4308 KB Output is correct
17 Correct 4 ms 4436 KB Output is correct
18 Correct 3 ms 4600 KB Output is correct
19 Correct 3 ms 4692 KB Output is correct
20 Correct 3 ms 4820 KB Output is correct
21 Correct 3 ms 4340 KB Output is correct
22 Correct 3 ms 4592 KB Output is correct
23 Correct 5 ms 4692 KB Output is correct
24 Correct 5 ms 4820 KB Output is correct
25 Correct 4 ms 4820 KB Output is correct
26 Correct 6 ms 4820 KB Output is correct
27 Correct 3 ms 4728 KB Output is correct
28 Correct 4 ms 4892 KB Output is correct
29 Correct 9 ms 4720 KB Output is correct
30 Correct 4 ms 4716 KB Output is correct
31 Correct 7 ms 4824 KB Output is correct
32 Correct 4 ms 4820 KB Output is correct
33 Correct 12 ms 4820 KB Output is correct
34 Correct 14 ms 4852 KB Output is correct
35 Correct 11 ms 5324 KB Output is correct
36 Correct 4 ms 4628 KB Output is correct
37 Correct 12 ms 5228 KB Output is correct
38 Correct 14 ms 5508 KB Output is correct
39 Correct 13 ms 5508 KB Output is correct
40 Correct 13 ms 5492 KB Output is correct
41 Correct 19 ms 5572 KB Output is correct
42 Correct 7 ms 5364 KB Output is correct
43 Correct 7 ms 5460 KB Output is correct
44 Correct 7 ms 5432 KB Output is correct
45 Correct 16 ms 5492 KB Output is correct
46 Correct 15 ms 5460 KB Output is correct
47 Correct 68 ms 12132 KB Output is correct
48 Correct 14 ms 19056 KB Output is correct
49 Correct 16 ms 21028 KB Output is correct
50 Correct 15 ms 23252 KB Output is correct
51 Correct 56 ms 31308 KB Output is correct
52 Correct 61 ms 31316 KB Output is correct
53 Correct 31 ms 30908 KB Output is correct
54 Correct 17 ms 29780 KB Output is correct
55 Correct 19 ms 29924 KB Output is correct
56 Correct 24 ms 31248 KB Output is correct
57 Correct 78 ms 29956 KB Output is correct
58 Correct 23 ms 30420 KB Output is correct
59 Correct 27 ms 30528 KB Output is correct
60 Correct 31 ms 30472 KB Output is correct
61 Correct 27 ms 30544 KB Output is correct
62 Correct 51 ms 31352 KB Output is correct
63 Correct 54 ms 31144 KB Output is correct
64 Correct 54 ms 31008 KB Output is correct
65 Correct 227 ms 31128 KB Output is correct
66 Correct 659 ms 31188 KB Output is correct
67 Correct 655 ms 31200 KB Output is correct