Submission #1019701

#TimeUsernameProblemLanguageResultExecution timeMemory
1019701beaconmcFire (BOI24_fire)C++14
0 / 100
203 ms96500 KiB
#include <bits/stdc++.h> typedef long long ll; #define FOR(i,x,y) for(ll i=x; i<y; i++) #define FORNEG(i,x,y) for(ll i=x; i>y; i--) using namespace std; vector<vector<ll>> normal; map<ll, ll> maxis; map<ll,ll> par; ll anc[100005][30]; ll ancc(ll x, ll k){ if (x==1000000000) return 1000000000; if (anc[x][k] != -1) return anc[x][k]; if (k==0){ if (par[x] == x) return anc[x][k] = 1000000000; return anc[x][k] = par[x]; } return anc[x][k] = ancc(ancc(x, k-1), k-1); } int main(){ FOR(i,0,100005) FOR(j,0,30) anc[i][j] = -1; ll n,m; cin >> n >> m; FOR(i,0,n){ ll a,b; cin >> a >> b; if (a<b) normal.push_back({a,b}); else normal.push_back({a,m+b}); } sort(normal.begin(), normal.end()); set<ll> things; for (auto&i : normal){ things.insert(i[0]); things.insert(i[1]); } ll cur = 0; ll maxi = -1; ll maxting = -1; for (auto&i : things){ while (cur < normal.size()){ if (normal[cur][0] <= i){ if (normal[cur][1] > maxi){ maxi = normal[cur][1]; maxting = cur; } }else break; cur++; } maxis[i] = maxting; } FOR(i,0,normal.size()){ par[i] = maxis[normal[i][1]]; } ll realans = 1000000000; FOR(i,0,normal.size()){ ll orig = normal[i][0]; ll idk = i; ll ans = 0; FORNEG(j,29,-1){ if (ancc(idk, j) != 1000000000 && (normal[ancc(idk, j)][1] - orig)<=m){ idk = ancc(idk, j); ans += (1<<j); } } if (normal[idk][1] - orig >= m){ realans = min(realans, ans+1); } } if (realans == 1000000000) cout << -1 << endl; else cout << realans << endl; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:52:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   while (cur < normal.size()){
      |          ~~~~^~~~~~~~~~~~~~~
Main.cpp:5:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
   64 |  FOR(i,0,normal.size()){
      |      ~~~~~~~~~~~~~~~~~           
Main.cpp:64:2: note: in expansion of macro 'FOR'
   64 |  FOR(i,0,normal.size()){
      |  ^~~
Main.cpp:5:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
   69 |  FOR(i,0,normal.size()){
      |      ~~~~~~~~~~~~~~~~~           
Main.cpp:69:2: note: in expansion of macro 'FOR'
   69 |  FOR(i,0,normal.size()){
      |  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...