Submission #313734

#TimeUsernameProblemLanguageResultExecution timeMemory
313734CaroLindaAmusement Park (JOI17_amusement_park)C++14
18 / 100
43 ms4884 KiB
#include "Joi.h" #include <bits/stdc++.h> #define sz(x) (int)(x.size()) #define ff first #define ss second #define all(x) x.begin(),x.end() #define ll long long using namespace std ; vector<int> ordem ; vector< vector<int> > adj ; vector<bool> vis ; void dfs(int x) { vis[x] = true ; ordem.push_back(x) ; for(auto e : adj[x]) { if(vis[e]) continue ; dfs(e) ; ordem.push_back(x) ; } } int isOn(int i, ll x ) { return ((1LL<<i)&x) != 0; } void Joi(int N, int M, int A[], int B[], long long X, int T) { adj.resize( N+10 , vector<int>() ) ; vis.resize(N+10,false) ; for(int i= 0 ; i < M ; i++ ) { adj[ A[i] ].push_back( B[i] ) ; adj[ B[i] ].push_back( A[i] ) ; } for(int i = 0 ; i < N ; i++ ) sort(all(adj[i])); dfs(0) ; vector<int> freq(60, 0) ; vector<int> val(N+10, -1) ; set<int> holdingOn ; for(int i = 0 ; i < sz(ordem) ; i++ ) { if( i-121 >= 0 && val[ordem[i-121]]!= -1 && (--freq[ val[ordem[i-121]] ]) == 0 && sz(holdingOn) > 0) { int x = *holdingOn.begin() ; holdingOn.erase( holdingOn.begin() ) ; val[x] = val[ordem[i-121]] ; for(int j = i-120 ; j <= i ; j++ ) if( ordem[j] == x ) freq[ val[x] ]++ ; } if(val[ ordem[i] ] == -1) { for(int j = 0 ; j < 60 ; j++ ) if(freq[j] == 0) { val[ ordem[i] ] = j ; break ; } if( val[ordem[i]] == -1 ) holdingOn.insert(ordem[i]) ; else if( holdingOn.find(ordem[i]) != holdingOn.end() ) holdingOn.erase( holdingOn.find(ordem[i]) ) ; } if( val[ordem[i]] != -1 ) freq[ val[ ordem[i] ] ]++ ; } for(int i = 0 ; i < N ; i++ ) MessageBoard( i, isOn(val[i] , X) ) ; }
#include "Ioi.h" #include <bits/stdc++.h> #define debug printf #define sz(x) (int)(x.size()) #define ff first #define ss second #define all(x) x.begin(),x.end() #define ll long long using namespace std ; vector<int> ord , tin , tout ; vector< vector<int> > graph ; vector<bool> mark ; void dfsPrime(int x) { tin[x] = tout[x] = sz(ord); mark[x] = true ; ord.push_back(x) ; for(auto e : graph[x]) { if(mark[e]) continue ; dfsPrime(e) ; tout[x] = sz(ord) ; ord.push_back(x) ; } } long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) { graph.resize( N+10 , vector<int>() ); tin.resize(N+10); tout.resize(N+10) ; mark.resize(N+10,false) ; for(int i= 0 ; i < M ; i++ ) { graph[ A[i] ].push_back( B[i] ) ; graph[ B[i] ].push_back( A[i] ) ; } for(int i = 0 ; i < N ; i++ ) sort(all(graph[i])); dfsPrime(0) ; vector<int> freq(60, 0) ; vector<int> val(N+10, -1) ; set<int> holdingOn ; for(int i = 0 ; i < sz(ord) ; i++ ) { if( i-121 >= 0 && val[ord[i-121]]!= -1 && (--freq[ val[ord[i-121]] ]) == 0 && sz(holdingOn) > 0) { int x = *holdingOn.begin() ; holdingOn.erase( holdingOn.begin() ) ; val[x] = val[ord[i-121]] ; for(int j = i-120 ; j <= i ; j++ ) if( ord[j] == x ) freq[ val[x] ]++ ; } if(val[ ord[i] ] == -1) { for(int j = 0 ; j < 60 ; j++ ) if(freq[j] == 0) { val[ ord[i] ] = j ; break ; } if( val[ord[i]] == -1 ) holdingOn.insert(ord[i]) ; else if( holdingOn.find(ord[i]) != holdingOn.end() ) holdingOn.erase( holdingOn.find(ord[i]) ) ; } if( val[ord[i]] != -1 ) freq[ val[ ord[i] ] ]++ ; } int ptrBeg , ptrEn ; for(int i = 0 ; i < sz(ord) ; i++ ) if(ord[i] == P) { ptrBeg = ptrEn = i ; break ; } vector<int> achei(60,0) ; achei[ val[P] ] = V ; int qtd = 20000 ; while(qtd--) { //cout << ptrBeg << " " << ptrEn << " " << qtd << " " << tin[P]<<" " << tout[P] << " " << P << endl ; if( ptrBeg == tin[P] && ptrEn == tout[P] ) { if(ptrBeg == 0 || ptrEn+1 == sz(ord)) break ; P = ord[ptrBeg-1] ; achei[ val[P] ] = Move(P) ; ptrBeg-- ; ptrEn++ ; } else { if( ptrBeg > tin[P] ) { achei[ val[ ord[ptrBeg-1] ] ] = Move(ord[ptrBeg-1]) ; ptrBeg-- ; } else { achei[ val[ord[ptrEn+1]] ] = Move(ord[ptrEn+1]); ptrEn++ ; } } } ll x = 0LL ; for(int i = 0 ; i< 60 ; i++ ) x += (1LL<<i) * achei[i] ; return x ; }

Compilation message (stderr)

Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:108:26: warning: 'ptrEn' may be used uninitialized in this function [-Wmaybe-uninitialized]
  108 |   if(ptrBeg == 0 || ptrEn+1 == sz(ord)) break ;
      |                     ~~~~~^~
Ioi.cpp:122:51: warning: 'ptrBeg' may be used uninitialized in this function [-Wmaybe-uninitialized]
  122 |    achei[ val[ ord[ptrBeg-1] ] ] = Move(ord[ptrBeg-1]) ;
      |                                             ~~~~~~^~
#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...