Submission #6385206


Source Code Expand

Copy
#pragma GCC optimize("O2")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdarg>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define whlie while
#define retunr return
#define reutrn return
#define reutnr return
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define inf 1001001001
#define infLL (1LL << 61)
#define MOD 1000000007
#define FOR(i,a,b) for(int (i)=(int)(a); (i)<(int)(b); (i)++) // [a,b)
#define rep(i,N) FOR((i), 0, (int)(N)) // [0,N)
#define FORR(i,a,b) for(int (i)=(int)(b) - 1; (i)>=(int)(a); (i)--)
#define repr(i,N) FORR((i), 0, (int)(N))
#define each(x,v) for(auto &x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it=v.begin();it!=v.end();it++)
#define vrepr(v,it) for(auto it=v.rbegin();it!=v.rend();it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) double __VA_ARGS__; in(__VA_ARGS__)
#define inpii(...) pii __VA_ARGS__; in(__VA_ARGS__)
#define rand mtrand
#define randinit random_device seed_gen; mt19937 mtrand(seed_gen()+2)

#ifdef LOCAL  
  #define trc(...) do { cout << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define stopif(val) assert( !(val) )
  #define trcv(v,...) do { cout << #v << " = "; vector_debug(v , ##__VA_ARGS__);cout << endl;} while(0)
#else
  #define trc(...)
  #define stopif(...)
  #define trcv(...)
#endif

using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector< vector<int> >;

struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15);} } iosetupnya;
/* 
int gcd(int a, int b){if(a>b) swap(a,b); return a==0 ? b : gcd(b%a,a);} ll gcd(ll a, ll b){if(a>b) swap(a,b); return a==0 ? b : gcd(b%a,a);}
ll lcm(int a, int b){return (1LL * a / gcd(a,b)) * b;} ll lcm(ll a, ll b){return (a / gcd(a,b)) * b;}
*/
inline ll pow(int a, int b){ll ans = 1; rep(i,b) ans *= a; return ans;} inline ll pow(ll a, ll b){ll ans = 1; rep(i,b) ans*= a; return ans;}
inline ll pow(int a, ll b){ll ans = 1; rep(i,b) ans *= a; return ans;} inline ll pow(ll a, int b){ll ans = 1; rep(i,b) ans*= a; return ans;}
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename C> inline void _cin(C &c){cin >> c;}
template<typename T,typename U> inline void _cin(pair<T,U> &p){cin >> p.fi; cin >> p.se;}
template<typename C> inline void _cout(const C &c){cout << c;}
template<typename T,typename U> inline void _cout(const pair<T,U> &p){cout << p.fi << ' ' << p.se;}
void in(){} template <typename T,class... U> void in(T &t,U &...u){ _cin(t); in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,U ...u){ _cout(t); if(sizeof...(u)) cout << ' '; out(u...);}
template<typename C> inline void in(vector<C> &v,int N=-1){if(sz(v) != 0){int M=(N == -1) ? sz(v) : N; rep(i,M) _cin(v[i]);}else{C c;rep(i,N) v.pb((_cin(c),c));}}
template<typename C> inline void in(C v[],int N){rep(i,N) _cin(v[i]);}
template<typename C> inline void out(const vector<C> &v,int N=-1){int M=(N == -1) ? sz(v) : N; rep(i,M) {cout<<( (i)?" ":"" ); _cout(v[i]);} cout<<"\n";}
template<typename C> inline void out(C v[],int N){rep(i,N) {cout<<( (i)?" ":"" ); _cout(v[i]);} cout<<"\n";}
template<typename C> inline void vector_debug(const vector<C> &v,int N=-1){cout << "{"; int M=(N == -1) ? sz(v) : N; rep(i,M) {cout<<( (i)?", ":"" ); _cout(v[i]);} cout<<"}";}
template<typename C> inline void vector_debug(C v[], int N){cout << "{"; rep(i,N) {cout<<((i)?", ":""); _cout(*(v+i));} cout<<"}";}
void dbg_out(){cout << endl;} template <typename T,class... U> void dbg_out(const T &t,U ...u){ _cout(t); if(sizeof...(u)) cout << ", "; dbg_out(u...);}
template<typename C,class... U> void dbg_out(const vector<C> &v,U ...u){vector_debug(v); if(sizeof...(u)) cout << ", "; dbg_out(u...);}
template<typename C,class... U> void dbg_out(const vector<vector<C>> &v,U ...u){cout << "{ "; rep(i,sz(v)) {if(i)cout<<", "; vector_debug(v[i]);} cout << " }"; if(sizeof...(u)) cout << ", "; dbg_out(u...);}
template<typename C> inline C vmax(const vector<C> &v){C n=v[0]; rep(i,sz(v)) amax(n,v[i]); return n;} template<typename C> inline C vmax(C v[], int N){C n=v[0]; rep( i , N ) amax(n,v[i]); return n;}
template<typename C> inline C vmin(const vector<C> &v){C n=v[0]; rep(i,sz(v)) amin(n,v[i]); return n;} template<typename C> inline C vmin(C v[], int N){C n=v[0]; rep( i , N ) amin(n,v[i]); return n;}
void die(string s){out(s); exit(0);}

////////////
/// main ///
////////////

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to) : src(-1) , to(to) , cost(0){}
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) { // edge e = n; とできる(e.to = n)
    to = x;
    return *this;
  }

  // int()をオーバーロードすることで重み付きグラフと普通のグラフでライブラリを共用できる
  operator int() const { return to; } // v[e]とできる ( v[e.to]に同じ )

};

// sort用 とりあえずcostの小さいほうが左としているが適宜書き換えて使いましょう
/**
template<typename T>
bool operator <(const edge<T>& e1,const edge<T>& e2){ 
  return e1.cost < e2.cost;
}//*/
template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UWG = vector< vector <int> >;

UWG g;
int N;
void ans(int cur){
  each(e ,g[cur]){
    out(cur , e);
    ans(e);
  }
}

int dfs(int src, int sum,int dst){
  trc(src,sum,dst);
  each(e,g[src]){
    int cursum = sum ^ ( (int(e)) % N);
    int cur_e = e;
    trc(cur_e,cursum);
    if(cursum == dst){
      return cur_e;
    }
    while(!g[cur_e].empty()){
      trc(cur_e,cursum);
      cur_e = g[cur_e][0];
      cursum = cursum ^ ( (int(cur_e)) % N);
      if(cursum == dst){
        return cur_e;
      }
    }
  }
  return -1;
}

int main(){
  in(N);
  if(__builtin_popcount(N) == 1) die("No");
  else out("Yes");
  g.resize(2 * N + 1);
  g[1].pb(2);
  g[2].pb(3);
  g[3].pb(N + 1);
  g[N + 1].pb(N + 2);
  g[N + 2].pb(N + 3);
  int cur = 3;
  trc("hoge");
  while( cur + 4 <= N ){
    g[1].pb(cur + 1);
    g[cur + 1].pb(cur + 2);
    g[cur + 2].pb(cur + 3);
    g[cur + 3].pb(cur + 4);
    g[cur + 4].pb(cur + 1 + N);
    g[cur + 1 + N].pb(cur + 2 + N);
    g[cur + 2 + N].pb(cur + 3 + N);
    g[cur + 3 + N].pb(cur + 4 + N);
    cur = cur + 4;
  }
  // たとえば11まで書いた...頭は8か9
  // hoge = 11
  trc("hogehoge",cur);
  int hoge = cur; 
  if(hoge == N){}
  else if(N % 4){
    g[1].pb(hoge + 1);
    g[hoge + 1].pb(hoge + 2);
    g[1].pb(hoge + 2 + N);
    g[hoge + 2 + N].pb(hoge + 1 + N);
    if(N % 4 == 2){
      g[hoge + 2 + N].pb(hoge  + 3 + N);
      g[2].pb(hoge + 3);
    }
  }
  else{
    g[1].pb(hoge + 1);
    int ret = dfs(1 , hoge - 3, hoge + 1);
    trc(ret);
    g[ret].pb(hoge + 1 + N);
  }
  /*
  while(cur + 1 <= N){
    int nya = dfs(1,hoge + 1,)
    cur = cur + 1;
  }
  */
  ans(1);
}

Submission Info

Submission Time
Task C - Skolem XOR Tree
User Nyaan
Language C++14 (GCC 5.4.1)
Score 0
Code Size 8035 Byte
Status WA
Exec Time 46 ms
Memory 12928 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 2
AC × 35
WA × 2
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, sample_01.txt, sample_02.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt
Case Name Status Exec Time Memory
hand_01.txt AC 1 ms 256 KB
hand_02.txt AC 1 ms 256 KB
hand_03.txt AC 1 ms 256 KB
hand_04.txt AC 1 ms 256 KB
hand_05.txt AC 1 ms 256 KB
hand_06.txt AC 1 ms 256 KB
hand_07.txt WA 1 ms 256 KB
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
test_01.txt AC 1 ms 256 KB
test_02.txt AC 1 ms 256 KB
test_03.txt AC 1 ms 256 KB
test_04.txt AC 1 ms 256 KB
test_05.txt AC 1 ms 256 KB
test_06.txt AC 1 ms 256 KB
test_07.txt AC 1 ms 256 KB
test_08.txt AC 1 ms 256 KB
test_09.txt AC 1 ms 256 KB
test_10.txt AC 1 ms 256 KB
test_11.txt AC 1 ms 256 KB
test_12.txt AC 1 ms 256 KB
test_13.txt AC 1 ms 256 KB
test_14.txt AC 1 ms 256 KB
test_15.txt AC 1 ms 256 KB
test_16.txt AC 1 ms 256 KB
test_17.txt WA 46 ms 12928 KB
test_18.txt AC 46 ms 12928 KB
test_19.txt AC 46 ms 12928 KB
test_20.txt AC 46 ms 12928 KB
test_21.txt AC 11 ms 3072 KB
test_22.txt AC 4 ms 1024 KB
test_23.txt AC 11 ms 3072 KB
test_24.txt AC 19 ms 5248 KB
test_25.txt AC 12 ms 3200 KB
test_26.txt AC 19 ms 5248 KB
test_27.txt AC 12 ms 3200 KB
test_28.txt AC 35 ms 9472 KB