답안 #361494

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
361494 2021-01-30T09:53:49 Z Thistle Amusement Park (JOI17_amusement_park) C++14
0 / 100
41 ms 9360 KB
#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:e[x]) if(~tr[g]){
        int leaf=-1;
        for(auto r:po[g]){
          if(r==g) continue;
          int sum=0;
          if(po[g].find(r)!=po[g].end()) sum++;
          if(sum==1) leaf=r;
        }
        for(auto r:po[g]){
          if(r!=leaf) po[x].insert(r);
          else num[x]=num[r];
        }
        tr[x]=0;
      }
    }
    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:e[x]) if(~tr[g]){
        int leaf=-1;
        for(auto r:po[g]){
          if(r==g) continue;
          int sum=0;
          if(po[g].find(r)!=po[g].end()) sum++;
          if(sum==1) leaf=r;
        }
        for(auto r:po[g]){
          if(r!=leaf) po[x].insert(r);
          else num[x]=num[r];
        }
        tr[x]=0;
      }
    }
    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;
}

Compilation message

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:65:3: note: in expansion of macro 'rep'
   65 |   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;
      |   ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1428 KB Output is correct
2 Incorrect 2 ms 1128 KB Wrong Answer [7]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 41 ms 9340 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1160 KB Output is correct
2 Correct 2 ms 1128 KB Output is correct
3 Incorrect 2 ms 1128 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 9132 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 9360 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -