Submission #237301

#TimeUsernameProblemLanguageResultExecution timeMemory
237301limabeansAmusement Park (JOI17_amusement_park)C++17
18 / 100
47 ms6432 KiB
#include "Joi.h" #include <bits/stdc++.h> using namespace std; template<typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl typedef long long ll; const int maxn = 10005; static vector<int> g[maxn]; static vector<int> path; static bool viz[maxn]; // void MessageBoard(int attr, int msg) { // } static void dfs(int at) { path.push_back(at); viz[at]=true; for (int to: g[at]) { if (viz[to]) continue; dfs(to); path.push_back(at); } } static bool check3(int n, int m, int a[], int b[]) { if (m != n-1) return false; for (int i=0; i<m; i++) { if (a[i]==i && b[i]==i+1) continue; return false; } return true; } void Joi(int n, int m, int a[], int b[], long long x, int t) { for (int i=0; i<=n; i++) { g[i].clear(); } path.clear(); memset(viz,false,sizeof(viz)); for (int i=0; i<m; i++) { g[a[i]].push_back(b[i]); g[b[i]].push_back(a[i]); } for (int i=0; i<n; i++) { sort(g[i].begin(), g[i].end()); } if (check3(n, m, a, b)) { for (int i=0; i<n; i++) { ll j=i%60; MessageBoard(i, x>>j&1); } return; } dfs(0); memset(viz,false,sizeof(viz)); ll j=0; for (int at: path) { if (viz[at]) continue; viz[at]=true; MessageBoard(at, x>>j&1); j++; } }
#include "Ioi.h" #include <bits/stdc++.h> using namespace std; template<typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl typedef long long ll; const ll mod = 1e9+7; const int maxn = 10005; const int inf = 1e9; static set<int> g[maxn]; static vector<int> path; static bool viz[maxn]; int nodes; // int Move(int dest) { // cout<<"Move: "<<dest<<endl; // return 1; // } static void dfs(int at) { path.push_back(at); viz[at]=true; for (int to: g[at]) { if (viz[to]) continue; dfs(to); path.push_back(at); } } vector<int> dij(int src) { int n = nodes; vector<int> dist(n, inf); vector<int> par(n, -1); dist[src] = 0; queue<int> qq; qq.push(src); while (qq.size()) { int at = qq.front(); qq.pop(); for (int to: g[at]) { if (dist[to]>1+dist[at]) { dist[to]=1+dist[at]; par[to]=at; qq.push(to); } } } vector<int> res; int at = 0; while (at != src) { res.push_back(at); at=par[at]; } reverse(res.begin(), res.end()); return res; } static bool check3(int n, int m, int a[], int b[]) { if (m != n-1) return false; for (int i=0; i<m; i++) { if (a[i]==i && b[i]==i+1) continue; return false; } return true; } long long Ioi(int n, int m, int a[], int b[], int p, int v, int t) { nodes = n; for (int i=0; i<=n; i++) { g[i].clear(); } path.clear(); memset(viz,false,sizeof(viz)); for (int i=0; i<m; i++) { g[a[i]].insert(b[i]); g[b[i]].insert(a[i]); } if (check3(n, m, a, b)) { ll res=0; int at=p; while (at%60 != 0) { assert(at-1>=0); v=Move(at-1); at--; } assert(at%60==0 && at>=0 && at<n); res=v; for (ll j=1; j<=min(n-1,59); j++) { ll val = Move(at+1); assert(at+1<n); res=res|(val<<j); at++; } return res; } int cur=p; vector<int> pathto0 = dij(cur); for (int x: pathto0) { assert(g[cur].count(x)); assert(x!=-1); Move(x); cur=x; } assert(cur==0); int to=*g[cur].begin(); Move(to); cur=to; dfs(0); memset(viz,false,sizeof(viz)); // for (int x: path) { // cout<<x<<" "; // } // cout<<endl; ll j=0; ll ans = 0; for (int nxt: path) { assert(g[cur].count(nxt)); ll val = Move(nxt); cur=nxt; if (viz[nxt]) { continue; } viz[nxt]=true; if (j>=60) { break; } ans = ans | (val<<j); j++; } return ans; } // int main() { // //long long Ioi(int n, int m, int a[], int b[], int p, int v, int t) { // int a[] = {0,1,2,2}; // int b[] = {1,2,0,3}; // ll res = Ioi(4,4,a,b,3,0,0); // watch(res); // return 0; // }
#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...