답안 #882773

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
882773 2023-12-03T17:22:29 Z mychecksedad Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
244 ms 135252 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;


int n, m;
vector<pair<int, int>> g[N];
bitset<30005> vis[30005];
vector<bool> VIS(N);
void solve(){ 
  cin >> n >> m;
  int z = 0, aim;
  for(int i = 1; i <= m; ++i){
    int b, p; cin >> b >> p;
    if(i==1) z = b;
    if(i==2) aim = b;
    g[b].pb({i, p});
  }
  deque<array<int, 3>> q;
  for(auto x: g[z]) q.pb({0, z, x.second}), vis[z][x.second] = 1;
  VIS[z] = 1;
  while(!q.empty()){
    auto v = q.front(); q.pop_front();
    // cout << v[0] << ' ' << v[1] << ' ' << v[2] << '\n';
    if(!VIS[v[1]]){
      VIS[v[1]] = 1;
      for(auto x: g[v[1]]){
        q.push_front({v[0], v[1], x.second});
        vis[v[1]][x.second] = 1;
      }
    }
    if(v[1] == aim){
      cout << v[0];
      return;
    }
    if(v[1] - v[2] >= 0 && !vis[v[1] - v[2]][v[2]]){
      vis[v[1] - v[2]][v[2]] = 1;
      q.pb({v[0] + 1, v[1] - v[2], v[2]});
    }
    if(v[1] + v[2] < n && !vis[v[1] + v[2]][v[2]]){
      vis[v[1] + v[2]][v[2]] = 1;
      q.pb({v[0] + 1, v[1] + v[2], v[2]});
    }
  }
  cout << -1;
}



int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  while(tt--){
    solve();
    en;
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:59:15: warning: unused variable 'aa' [-Wunused-variable]
   59 |   int tt = 1, aa;
      |               ^~
skyscraper.cpp: In function 'void solve()':
skyscraper.cpp:39:5: warning: 'aim' may be used uninitialized in this function [-Wmaybe-uninitialized]
   39 |     if(v[1] == aim){
      |     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 25176 KB Output is correct
2 Correct 5 ms 25180 KB Output is correct
3 Correct 5 ms 25180 KB Output is correct
4 Correct 5 ms 25176 KB Output is correct
5 Correct 5 ms 25176 KB Output is correct
6 Correct 6 ms 25308 KB Output is correct
7 Correct 5 ms 25180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 25180 KB Output is correct
2 Correct 6 ms 25180 KB Output is correct
3 Correct 5 ms 25052 KB Output is correct
4 Correct 5 ms 25180 KB Output is correct
5 Correct 5 ms 25180 KB Output is correct
6 Correct 5 ms 25180 KB Output is correct
7 Correct 6 ms 25180 KB Output is correct
8 Correct 5 ms 25180 KB Output is correct
9 Correct 5 ms 25180 KB Output is correct
10 Correct 5 ms 25436 KB Output is correct
11 Correct 6 ms 25436 KB Output is correct
12 Correct 5 ms 25436 KB Output is correct
13 Correct 6 ms 25692 KB Output is correct
14 Correct 6 ms 25688 KB Output is correct
15 Correct 6 ms 25692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 25180 KB Output is correct
2 Correct 5 ms 25180 KB Output is correct
3 Correct 5 ms 25180 KB Output is correct
4 Correct 5 ms 25180 KB Output is correct
5 Correct 5 ms 25180 KB Output is correct
6 Correct 5 ms 25180 KB Output is correct
7 Correct 6 ms 25180 KB Output is correct
8 Correct 6 ms 25180 KB Output is correct
9 Correct 5 ms 25180 KB Output is correct
10 Correct 5 ms 25436 KB Output is correct
11 Correct 6 ms 25436 KB Output is correct
12 Correct 6 ms 25436 KB Output is correct
13 Correct 6 ms 25692 KB Output is correct
14 Correct 6 ms 25692 KB Output is correct
15 Correct 5 ms 25692 KB Output is correct
16 Correct 8 ms 27228 KB Output is correct
17 Correct 7 ms 29528 KB Output is correct
18 Correct 7 ms 27228 KB Output is correct
19 Correct 6 ms 27228 KB Output is correct
20 Correct 10 ms 32604 KB Output is correct
21 Correct 7 ms 27476 KB Output is correct
22 Correct 6 ms 27228 KB Output is correct
23 Correct 8 ms 30660 KB Output is correct
24 Correct 10 ms 31836 KB Output is correct
25 Correct 6 ms 28252 KB Output is correct
26 Correct 9 ms 31416 KB Output is correct
27 Correct 10 ms 31836 KB Output is correct
28 Correct 9 ms 32600 KB Output is correct
29 Correct 10 ms 32604 KB Output is correct
30 Correct 9 ms 32440 KB Output is correct
31 Correct 9 ms 32440 KB Output is correct
32 Correct 9 ms 32600 KB Output is correct
33 Correct 10 ms 32604 KB Output is correct
34 Correct 10 ms 32604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 25180 KB Output is correct
2 Correct 5 ms 25284 KB Output is correct
3 Correct 6 ms 25052 KB Output is correct
4 Correct 5 ms 25048 KB Output is correct
5 Correct 5 ms 25180 KB Output is correct
6 Correct 6 ms 25180 KB Output is correct
7 Correct 5 ms 25180 KB Output is correct
8 Correct 7 ms 25180 KB Output is correct
9 Correct 5 ms 25180 KB Output is correct
10 Correct 5 ms 25436 KB Output is correct
11 Correct 6 ms 25436 KB Output is correct
12 Correct 5 ms 25724 KB Output is correct
13 Correct 6 ms 25692 KB Output is correct
14 Correct 6 ms 25692 KB Output is correct
15 Correct 5 ms 25692 KB Output is correct
16 Correct 6 ms 27228 KB Output is correct
17 Correct 7 ms 29532 KB Output is correct
18 Correct 6 ms 27228 KB Output is correct
19 Correct 8 ms 27228 KB Output is correct
20 Correct 9 ms 32448 KB Output is correct
21 Correct 6 ms 27228 KB Output is correct
22 Correct 6 ms 27228 KB Output is correct
23 Correct 9 ms 30556 KB Output is correct
24 Correct 8 ms 31836 KB Output is correct
25 Correct 6 ms 28252 KB Output is correct
26 Correct 9 ms 31580 KB Output is correct
27 Correct 9 ms 31836 KB Output is correct
28 Correct 9 ms 32600 KB Output is correct
29 Correct 10 ms 32604 KB Output is correct
30 Correct 11 ms 32604 KB Output is correct
31 Correct 12 ms 32604 KB Output is correct
32 Correct 9 ms 32500 KB Output is correct
33 Correct 10 ms 32604 KB Output is correct
34 Correct 10 ms 32688 KB Output is correct
35 Correct 12 ms 32092 KB Output is correct
36 Correct 6 ms 27996 KB Output is correct
37 Correct 11 ms 32716 KB Output is correct
38 Correct 13 ms 34140 KB Output is correct
39 Correct 10 ms 27996 KB Output is correct
40 Correct 14 ms 30300 KB Output is correct
41 Correct 13 ms 33628 KB Output is correct
42 Correct 11 ms 31808 KB Output is correct
43 Correct 12 ms 32468 KB Output is correct
44 Correct 14 ms 33244 KB Output is correct
45 Correct 17 ms 33236 KB Output is correct
46 Correct 15 ms 33372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 25180 KB Output is correct
2 Correct 5 ms 25272 KB Output is correct
3 Correct 5 ms 25180 KB Output is correct
4 Correct 5 ms 25180 KB Output is correct
5 Correct 5 ms 25180 KB Output is correct
6 Correct 6 ms 25060 KB Output is correct
7 Correct 5 ms 25180 KB Output is correct
8 Correct 5 ms 25176 KB Output is correct
9 Correct 5 ms 25180 KB Output is correct
10 Correct 5 ms 25436 KB Output is correct
11 Correct 5 ms 25436 KB Output is correct
12 Correct 6 ms 25436 KB Output is correct
13 Correct 5 ms 25688 KB Output is correct
14 Correct 7 ms 25692 KB Output is correct
15 Correct 6 ms 25692 KB Output is correct
16 Correct 6 ms 27228 KB Output is correct
17 Correct 7 ms 29532 KB Output is correct
18 Correct 6 ms 27228 KB Output is correct
19 Correct 6 ms 27352 KB Output is correct
20 Correct 10 ms 32604 KB Output is correct
21 Correct 6 ms 27228 KB Output is correct
22 Correct 5 ms 27360 KB Output is correct
23 Correct 9 ms 30556 KB Output is correct
24 Correct 9 ms 31736 KB Output is correct
25 Correct 7 ms 28252 KB Output is correct
26 Correct 8 ms 31456 KB Output is correct
27 Correct 9 ms 31836 KB Output is correct
28 Correct 11 ms 32452 KB Output is correct
29 Correct 10 ms 32604 KB Output is correct
30 Correct 10 ms 32604 KB Output is correct
31 Correct 9 ms 32604 KB Output is correct
32 Correct 9 ms 32404 KB Output is correct
33 Correct 10 ms 32604 KB Output is correct
34 Correct 10 ms 32448 KB Output is correct
35 Correct 12 ms 32092 KB Output is correct
36 Correct 7 ms 27996 KB Output is correct
37 Correct 11 ms 32856 KB Output is correct
38 Correct 17 ms 34156 KB Output is correct
39 Correct 11 ms 28016 KB Output is correct
40 Correct 12 ms 30136 KB Output is correct
41 Correct 13 ms 33884 KB Output is correct
42 Correct 12 ms 31704 KB Output is correct
43 Correct 11 ms 32472 KB Output is correct
44 Correct 12 ms 33240 KB Output is correct
45 Correct 18 ms 33372 KB Output is correct
46 Correct 15 ms 33116 KB Output is correct
47 Correct 26 ms 56728 KB Output is correct
48 Correct 10 ms 27996 KB Output is correct
49 Correct 11 ms 27996 KB Output is correct
50 Correct 9 ms 27740 KB Output is correct
51 Correct 52 ms 110420 KB Output is correct
52 Correct 55 ms 118096 KB Output is correct
53 Correct 19 ms 41816 KB Output is correct
54 Correct 37 ms 85596 KB Output is correct
55 Correct 46 ms 101168 KB Output is correct
56 Correct 61 ms 135252 KB Output is correct
57 Correct 7 ms 26972 KB Output is correct
58 Correct 59 ms 134772 KB Output is correct
59 Correct 63 ms 127004 KB Output is correct
60 Correct 52 ms 126928 KB Output is correct
61 Correct 53 ms 122176 KB Output is correct
62 Correct 89 ms 135252 KB Output is correct
63 Correct 109 ms 135028 KB Output is correct
64 Correct 160 ms 134992 KB Output is correct
65 Correct 165 ms 135248 KB Output is correct
66 Correct 244 ms 135148 KB Output is correct
67 Correct 145 ms 134996 KB Output is correct