Submission #677131

# Submission time Handle Problem Language Result Execution time Memory
677131 2023-01-02T10:30:27 Z MohammadAghil Amusement Park (JOI17_amusement_park) C++17
100 / 100
37 ms 32884 KB
      #include <bits/stdc++.h>
#include "Joi.h"
//   #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
 using namespace std;
  typedef long long ll;
   typedef pair<int, int> pp;
     #define per(i,r,l) for(int i = (r); i >= (l); i--)
       #define rep(i,l,r) for(int i = (l); i < (r); i++)
          #define all(x) begin(x), end(x)
             #define sz(x) (int)(x).size()
                 #define pb push_back
                     #define ss second
                          #define ff first
                                  void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
     cin.tie(0) -> sync_with_stdio(0);
     #ifndef ONLINE_JUDGE
          #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
     #else
          #define er(args ...) 0
     #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 3e5 + 5, lg = 60, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll,md);return k*k%md*(b&1ll?a:1)%md;}

vector<int> adj[maxn], adj2[maxn];
int vl[maxn], par[maxn], h[maxn];
bool vis[maxn], bt[maxn], spe[maxn];
ll ans, X;

void dfs(int r, int& k, int p, int v = 0){
     if(k){
          vl[r] = lg - k;
          k--;
          spe[r] = true;
     } else vl[r] = v;
     bt[r] = X>>vl[r]&1ll;
     vis[r] = true;
     par[r] = p;
     for(int c: adj[r]) if(!vis[c]){
          dfs(c, k, r, k? 0: (v+lg-1)%lg);
          if(spe[r] && spe[c]){
               adj2[r].pb(c);
               adj2[c].pb(r);
          }
     }
}

void Joi(int n, int m, int a[], int b[], ll x, int T) { X = x;
     rep(i,0,m){
          adj[a[i]].pb(b[i]), adj[b[i]].pb(a[i]);
     }
     int tmp = lg;
     dfs(0, tmp, -1);
     rep(i,0,n) MessageBoard(i, bt[i]);
     return;
}
      #include <bits/stdc++.h>
     #include "Ioi.h"
//   #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
 using namespace std;
  typedef long long ll;
   typedef pair<int, int> pp;
     #define per(i,r,l) for(int i = (r); i >= (l); i--)
       #define rep(i,l,r) for(int i = (l); i < (r); i++)
          #define all(x) begin(x), end(x)
             #define sz(x) (int)(x).size()
                 #define pb push_back
                     #define ss second
                          #define ff first
                                  void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
     cin.tie(0) -> sync_with_stdio(0);
     #ifndef ONLINE_JUDGE
          #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
     #else
          #define er(args ...) 0
     #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 3e5 + 5, lg = 60, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll,md);return k*k%md*(b&1ll?a:1)%md;}

vector<int> adj[maxn], adj2[maxn];
int vl[maxn], par[maxn], h[maxn];
bool vis[maxn], spe[maxn], seen[maxn];
ll ans;

void dfs(int r, int& k, int p, int v = 0){
     if(k){
          vl[r] = lg - k;
          k--;
          spe[r] = true;
     } else vl[r] = v;
     vis[r] = true;
     par[r] = p;
     for(int c: adj[r]) if(!vis[c]){
          dfs(c, k, r, k? 0: (v+lg-1)%lg);
          if(spe[r] && spe[c]){
               adj2[r].pb(c);
               adj2[c].pb(r);
          }
     }
}

void dfs2(int r, bool cr){
     // er(r);
     vis[r] = true;
     if(cr) ans |= 1ll<<vl[r];
     seen[vl[r]] = true;
     for(int c: adj2[r]) if(c - par[r]){
          if(!seen[vl[c]]){
               // er(r, c);
               dfs2(c, Move(c));
               Move(r);
          }
     }
     if(par[r] + 1 && !vis[par[r]]){
          // er(r, par[r]);
          dfs2(par[r], Move(par[r]));
     }
}

ll Ioi(int n, int m, int a[], int b[], int x, int cr, int T) {
     rep(i,0,m){
          adj[a[i]].pb(b[i]), adj[b[i]].pb(a[i]);
     }
     int tmp = lg;
     dfs(0, tmp, -1);
     rep(i,0,n) vis[i] = false;
     int cnt = lg;
     while(!spe[x] && cnt){
          if(cr) ans |= 1ll<<vl[x];
          seen[vl[x]] = true;
          // er(vl[x], h[x]);
          cr = Move(par[x]), x = par[x];
          cnt--;
     }
     // er(x, f);
     if(cnt){
          dfs2(x, cr);
     }
     return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 28976 KB Output is correct
2 Correct 17 ms 28980 KB Output is correct
3 Correct 16 ms 28948 KB Output is correct
4 Correct 16 ms 28976 KB Output is correct
5 Correct 14 ms 28976 KB Output is correct
6 Correct 14 ms 28976 KB Output is correct
7 Correct 16 ms 28936 KB Output is correct
8 Correct 16 ms 28972 KB Output is correct
9 Correct 15 ms 29048 KB Output is correct
10 Correct 15 ms 28976 KB Output is correct
11 Correct 19 ms 29296 KB Output is correct
12 Correct 16 ms 28956 KB Output is correct
13 Correct 15 ms 28972 KB Output is correct
14 Correct 16 ms 28960 KB Output is correct
15 Correct 17 ms 28972 KB Output is correct
16 Correct 17 ms 28984 KB Output is correct
17 Correct 16 ms 29012 KB Output is correct
18 Correct 16 ms 28860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 32756 KB Output is correct
2 Correct 34 ms 32884 KB Output is correct
3 Correct 35 ms 32824 KB Output is correct
4 Correct 27 ms 30740 KB Output is correct
5 Correct 27 ms 31468 KB Output is correct
6 Correct 27 ms 31412 KB Output is correct
7 Correct 27 ms 31436 KB Output is correct
8 Correct 27 ms 31480 KB Output is correct
9 Correct 26 ms 31412 KB Output is correct
10 Correct 26 ms 30776 KB Output is correct
11 Correct 28 ms 30776 KB Output is correct
12 Correct 28 ms 30512 KB Output is correct
13 Correct 27 ms 30396 KB Output is correct
14 Correct 27 ms 30632 KB Output is correct
15 Correct 25 ms 30644 KB Output is correct
16 Correct 25 ms 30512 KB Output is correct
17 Correct 26 ms 30700 KB Output is correct
18 Correct 26 ms 30792 KB Output is correct
19 Correct 26 ms 30588 KB Output is correct
20 Correct 25 ms 31608 KB Output is correct
21 Correct 25 ms 31560 KB Output is correct
22 Correct 30 ms 31084 KB Output is correct
23 Correct 28 ms 31428 KB Output is correct
24 Correct 27 ms 31216 KB Output is correct
25 Correct 27 ms 31316 KB Output is correct
26 Correct 27 ms 31388 KB Output is correct
27 Correct 27 ms 31332 KB Output is correct
28 Correct 30 ms 31376 KB Output is correct
29 Correct 27 ms 31248 KB Output is correct
30 Correct 26 ms 31272 KB Output is correct
31 Correct 16 ms 28976 KB Output is correct
32 Correct 15 ms 28968 KB Output is correct
33 Correct 15 ms 28972 KB Output is correct
34 Correct 16 ms 28936 KB Output is correct
35 Correct 15 ms 28976 KB Output is correct
36 Correct 15 ms 28972 KB Output is correct
37 Correct 16 ms 28956 KB Output is correct
38 Correct 17 ms 28932 KB Output is correct
39 Correct 17 ms 28932 KB Output is correct
40 Correct 15 ms 28976 KB Output is correct
41 Correct 16 ms 28976 KB Output is correct
42 Correct 16 ms 28968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 28960 KB Output is correct
2 Correct 16 ms 28920 KB Output is correct
3 Correct 16 ms 28984 KB Output is correct
4 Correct 18 ms 29412 KB Output is correct
5 Correct 17 ms 29532 KB Output is correct
6 Correct 17 ms 29540 KB Output is correct
7 Correct 18 ms 29520 KB Output is correct
8 Correct 18 ms 29460 KB Output is correct
9 Correct 24 ms 32460 KB Output is correct
10 Correct 24 ms 32620 KB Output is correct
11 Correct 26 ms 32552 KB Output is correct
12 Correct 18 ms 28976 KB Output is correct
13 Correct 16 ms 29020 KB Output is correct
14 Correct 16 ms 28968 KB Output is correct
15 Correct 15 ms 28968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 32780 KB Output is correct
2 Correct 37 ms 32796 KB Output is correct
3 Correct 36 ms 32780 KB Output is correct
4 Correct 28 ms 30768 KB Output is correct
5 Correct 28 ms 32184 KB Output is correct
6 Correct 28 ms 31432 KB Output is correct
7 Correct 27 ms 31328 KB Output is correct
8 Correct 26 ms 31064 KB Output is correct
9 Correct 26 ms 31160 KB Output is correct
10 Correct 25 ms 30844 KB Output is correct
11 Correct 30 ms 30776 KB Output is correct
12 Correct 24 ms 30576 KB Output is correct
13 Correct 27 ms 30520 KB Output is correct
14 Correct 26 ms 30488 KB Output is correct
15 Correct 26 ms 30620 KB Output is correct
16 Correct 26 ms 30676 KB Output is correct
17 Correct 25 ms 30764 KB Output is correct
18 Correct 27 ms 30668 KB Output is correct
19 Correct 26 ms 30652 KB Output is correct
20 Correct 24 ms 31572 KB Output is correct
21 Correct 27 ms 31560 KB Output is correct
22 Correct 26 ms 31428 KB Output is correct
23 Correct 30 ms 31112 KB Output is correct
24 Correct 27 ms 31300 KB Output is correct
25 Correct 27 ms 31512 KB Output is correct
26 Correct 25 ms 31348 KB Output is correct
27 Correct 26 ms 31560 KB Output is correct
28 Correct 27 ms 31212 KB Output is correct
29 Correct 25 ms 30980 KB Output is correct
30 Correct 26 ms 31288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 32768 KB Output is correct
2 Correct 36 ms 32712 KB Output is correct
3 Correct 37 ms 32736 KB Output is correct
4 Correct 26 ms 30772 KB Output is correct
5 Correct 26 ms 32232 KB Output is correct
6 Correct 27 ms 31308 KB Output is correct
7 Correct 31 ms 31088 KB Output is correct
8 Correct 27 ms 31380 KB Output is correct
9 Correct 25 ms 31240 KB Output is correct
10 Correct 25 ms 30820 KB Output is correct
11 Correct 26 ms 30780 KB Output is correct
12 Correct 26 ms 30416 KB Output is correct
13 Correct 26 ms 30548 KB Output is correct
14 Correct 26 ms 30632 KB Output is correct
15 Correct 26 ms 30568 KB Output is correct
16 Correct 28 ms 30636 KB Output is correct
17 Correct 26 ms 30776 KB Output is correct
18 Correct 26 ms 30712 KB Output is correct
19 Correct 27 ms 30688 KB Output is correct
20 Correct 26 ms 31536 KB Output is correct
21 Correct 28 ms 31472 KB Output is correct
22 Correct 27 ms 31276 KB Output is correct
23 Correct 26 ms 31284 KB Output is correct
24 Correct 27 ms 31324 KB Output is correct
25 Correct 27 ms 31216 KB Output is correct
26 Correct 26 ms 31120 KB Output is correct
27 Correct 27 ms 31668 KB Output is correct
28 Correct 26 ms 31528 KB Output is correct
29 Correct 27 ms 31264 KB Output is correct
30 Correct 30 ms 31292 KB Output is correct
31 Correct 15 ms 28968 KB Output is correct
32 Correct 14 ms 28964 KB Output is correct
33 Correct 15 ms 28936 KB Output is correct
34 Correct 16 ms 28968 KB Output is correct
35 Correct 17 ms 28956 KB Output is correct
36 Correct 15 ms 28976 KB Output is correct
37 Correct 17 ms 28996 KB Output is correct
38 Correct 16 ms 28940 KB Output is correct
39 Correct 15 ms 28808 KB Output is correct
40 Correct 16 ms 28932 KB Output is correct
41 Correct 15 ms 28924 KB Output is correct
42 Correct 14 ms 28964 KB Output is correct