제출 #361504

#제출 시각아이디문제언어결과실행 시간메모리
361504ThistleAmusement Park (JOI17_amusement_park)C++14
100 / 100
867 ms65228 KiB
#include "Joi.h"
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define vec vector
#define vi vec<ll>
#define pb emplace_back
#define rng(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define rep(i,n) rng((i),0,(n))
#define siz(a) int((a).size())
#define all(a) (a).begin(), (a).end()


void Joi(int N, int M, int A[], int B[], long long X, int T) {
  int n=N;
  vec<vi>e(n,vi()),f(n,vi()),h(n,vi());
  rep(i,M){
    f[A[i]].pb(B[i]);
    f[B[i]].pb(A[i]);
  }
  vec<bool>used(n,0);
  auto dfs=[&](int x,auto& dfs)->void{
    used[x]=1;
    for(auto g:f[x]){
      if(!used[g]){
        e[x].pb(g);h[x].pb(g);h[g].pb(x);
        dfs(g,dfs);
      }
    }
  };
  dfs(0,dfs);
  queue<int>se;rep(i,60) se.push(i);
  set<int>se2;
  vec<set<int>>po(n,set<int>());
  vi num(n,0),tr(n,-1);
  auto dfs2=[&](int x,auto& dfs2)->void{
    if(!se.empty()) {
      num[x]=se.front();se.pop();
      tr[x]=0;
      se2.insert(x);
    }
    for(auto g:e[x]) dfs2(g,dfs2);
  };
  dfs2(0,dfs2);
  rep(i,n) if(!tr[i]) po[i]=se2;
  auto dfs3=[&](int x,auto& dfs3)->void{
    if(tr[x]<0){
      for(auto g:h[x]) if(~tr[g]){
        int leaf=-1;
        for(auto r:po[g]){
          if(r==g) continue;
          int sum=0;
          for(auto k:h[r]){
            if(po[g].find(k)!=po[g].end()) sum++;
          }
          if(sum==1){
            leaf=r;
          }
        }
        po[x].insert(x);
        for(auto r:po[g]){
          if(r!=leaf) po[x].insert(r);
          else num[x]=num[r];
        }
        tr[x]=0;
        break;
      }
    }
    for(auto g:e[x]) dfs3(g,dfs3);
  };dfs3(0,dfs3);
  rep(i,n) MessageBoard(i,(X>>num[i])&1);
}
#include "Ioi.h"
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define vec vector
#define vi vec<ll>
#define pb emplace_back
#define rng(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define rep(i,n) rng((i),0,(n))
#define siz(a) int((a).size())
#define all(a) (a).begin(), (a).end()


long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
  int n=N;
  vec<vi>e(n,vi()),f(n,vi()),h(n,vi());
  rep(i,M){
    f[A[i]].pb(B[i]);
    f[B[i]].pb(A[i]);
  }
  vec<bool>used(n,0);
  auto dfs=[&](int x,auto& dfs)->void{
    used[x]=1;
    for(auto g:f[x]){
      if(!used[g]){
        e[x].pb(g);h[x].pb(g);h[g].pb(x);
        dfs(g,dfs);
      }
    }
  };
  dfs(0,dfs);
  queue<int>se;rep(i,60) se.push(i);
  set<int>se2;
  vec<set<int>>po(n,set<int>());
  vi num(n,0),tr(n,-1);
  auto dfs2=[&](int x,auto& dfs2)->void{
    if(!se.empty()) {
      num[x]=se.front();se.pop();
      tr[x]=0;
      se2.insert(x);
    }
    for(auto g:e[x]) dfs2(g,dfs2);
  };
  dfs2(0,dfs2);
  rep(i,n) if(!tr[i]) po[i]=se2;
  auto dfs3=[&](int x,auto& dfs3)->void{
    if(tr[x]<0){
      for(auto g:h[x]) if(~tr[g]){
        int leaf=-1;
        for(auto r:po[g]){
          if(r==g) continue;
          int sum=0;
          for(auto k:h[r]){
            if(po[g].find(k)!=po[g].end()) sum++;
          }
          if(sum==1){
            leaf=r;
          }
        }
        po[x].insert(x);
        for(auto r:po[g]){
          if(r!=leaf) po[x].insert(r);
          else num[x]=num[r];
        }
        tr[x]=0;
        break;
      }
    }
    for(auto g:e[x]) dfs3(g,dfs3);
  };dfs3(0,dfs3);

  ll ans=ll(V)<<num[P];
  auto dfs5=[&](int x,int p,auto& dfs5)->void{
    for(auto g:h[x]){
      if(g==p||po[P].find(g)==po[P].end())continue;
      ll t=Move(g);
      ans|=(t<<num[g]);
      dfs5(g,x,dfs5);
    }
    if(~p) Move(p);
  };dfs5(P,-1,dfs5);
  return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

Joi.cpp: In function 'void Joi(int, int, int*, int*, long long int, int)':
Joi.cpp:8:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define rng(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
      |                           ^
Joi.cpp:9:18: note: in expansion of macro 'rng'
    9 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
Joi.cpp:17:3: note: in expansion of macro 'rep'
   17 |   rep(i,M){
      |   ^~~
Joi.cpp:8:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define rng(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
      |                           ^
Joi.cpp:9:18: note: in expansion of macro 'rng'
    9 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
Joi.cpp:32:16: note: in expansion of macro 'rep'
   32 |   queue<int>se;rep(i,60) se.push(i);
      |                ^~~
Joi.cpp:8:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define rng(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
      |                           ^
Joi.cpp:9:18: note: in expansion of macro 'rng'
    9 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
Joi.cpp:45:3: note: in expansion of macro 'rep'
   45 |   rep(i,n) if(!tr[i]) po[i]=se2;
      |   ^~~
Joi.cpp:8:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define rng(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
      |                           ^
Joi.cpp:9:18: note: in expansion of macro 'rng'
    9 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
Joi.cpp:71:3: note: in expansion of macro 'rep'
   71 |   rep(i,n) MessageBoard(i,(X>>num[i])&1);
      |   ^~~

Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:8:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define rng(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
      |                           ^
Ioi.cpp:9:18: note: in expansion of macro 'rng'
    9 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
Ioi.cpp:17:3: note: in expansion of macro 'rep'
   17 |   rep(i,M){
      |   ^~~
Ioi.cpp:8:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define rng(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
      |                           ^
Ioi.cpp:9:18: note: in expansion of macro 'rng'
    9 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
Ioi.cpp:32:16: note: in expansion of macro 'rep'
   32 |   queue<int>se;rep(i,60) se.push(i);
      |                ^~~
Ioi.cpp:8:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    8 | #define rng(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
      |                           ^
Ioi.cpp:9:18: note: in expansion of macro 'rng'
    9 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
Ioi.cpp:45:3: note: in expansion of macro 'rep'
   45 |   rep(i,n) if(!tr[i]) po[i]=se2;
      |   ^~~
#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...