Submission #538687

# Submission time Handle Problem Language Result Execution time Memory
538687 2022-03-17T13:40:01 Z Mitsubachi None (JOI16_snowy) C++14
100 / 100
20 ms 1904 KB
//g++ 6.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include "Anyalib.h"

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;

#define fi first
#define se second
#define pb push_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

using P = pair<int,int>;

/*
vi server(1000,0);

void Save(int place,int bit){
  server[place]=bit;
  return;
}

int Ask(int place){
  return server[place];
}
*/

// Anya start

//recordAnyaのやつには答えを入れる 他のは親から+1されたかを入れる
int nAnya;
vvi gAnya(550);
vi seenAnya(550,0),distAnya(550),parentAnya(550,-1),addAnya(550),ansAnya(550),disAnya(550);
vector<P> edgeAnya(550),recordAnya;
int usedAnya=0;

int digitAnya(int x){
  int res=0;
  while(x>0){
    res++;
    x/=2;
  }
  return res;
}

void dfsAnya(int now,vvi &g,vi &seen,vi &dist,vi &parent,vector<P> &record,int bit){
  seen[now]=1;
  if(usedAnya==0&&bit>10){
    usedAnya=1;
    record.emplace_back(now,digitAnya(dist[now]));
    bit=digitAnya(dist[now]);
  }
  if(bit>20){
    usedAnya=1;
    record.emplace_back(now,digitAnya(dist[now]));
    bit=digitAnya(dist[now]);
  }
  for(int next:g[now]){
    if(seen[next]==1)continue;
    dist[next]=dist[now]+1;
    parent[next]=now;
    dfsAnya(next,g,seen,dist,parent,record,bit+1);
  }
}

void dfsAnya2(int now,vvi &g,vi &seen,vi &ans,vi &add){
  seen[now]=1;
  for(int next:g[now]){
    if(seen[next]==1)continue;
    ans[next]=ans[now];
    if(add[next]==1){
      ans[next]++;
    }
    dfsAnya2(next,g,seen,ans,add);
  }
}

void InitAnya(int N,int A[],int B[]){
  nAnya=N;
  rep(i,0,nAnya){
    disAnya[i]=1;
  }
  rep(i,0,nAnya-1){
    gAnya[A[i]].emplace_back(B[i]);
    gAnya[B[i]].emplace_back(A[i]);
    edgeAnya[i]={A[i],B[i]};
  }
  
  distAnya[0]=0;
  dfsAnya(0,gAnya,seenAnya,distAnya,parentAnya,recordAnya,0);
  
  sort(all(recordAnya));
  int need=nAnya;
  for(auto [place,bit]:recordAnya){
    need+=bit-1;
    disAnya[place]=0;
  }

  if(need>1000){
    recordAnya.clear();
    rep(i,0,nAnya){
      seenAnya[i]=0;
      disAnya[i]=1;
    }
    dfsAnya(0,gAnya,seenAnya,distAnya,parentAnya,recordAnya,0);
    need=nAnya;
    for(auto [place,bit]:recordAnya){
      need+=bit-1;
      disAnya[place]=0;
    }
  }
  return;
}

void Anya(int C[]){
  rep(i,0,nAnya){
    addAnya[i]=0;
    seenAnya[i]=0;
    ansAnya[i]=0;
  }
  rep(i,0,nAnya-1){
    if(C[i]==1){
      int u=edgeAnya[i].fi,v=edgeAnya[i].se;
      if(parentAnya[u]==v){
        addAnya[u]++;
      }
      else{
        addAnya[v]++;
      }
    }
  }

  dfsAnya2(0,gAnya,seenAnya,ansAnya,addAnya);

  int now=0;
  for(auto [place,bit]:recordAnya){
    int x=ansAnya[place];
    rep(i,0,bit){
      Save(now,x%2);
      now++;
      x/=2;
    }
  }
  rep(i,0,nAnya){
    if(disAnya[i]==1){
      Save(now,addAnya[i]);
      now++;
    }
  }

  return;
}

// Anya end
//g++ 6.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include "Borislib.h"

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;

#define fi first
#define se second
#define pb push_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

using P = pair<int,int>;

/*
vi server(1000,0);

void Save(int place,int bit){
  server[place]=bit;
  return;
}

int Ask(int place){
  return server[place];
}
*/

// Boris start

int nBoris;
vvi gBoris(550);
vi seenBoris(550,0),distBoris(550),parentBoris(550,-1),addBoris(550),ansBoris(550),disBoris(550);
vector<P> edgeBoris(550),recordBoris,placeBoris(550);
int usedBoris=0;

int digitBoris(int x){
  int res=0;
  while(x>0){
    res++;
    x/=2;
  }
  return res;
}

void dfsBoris(int now,vvi &g,vi &seen,vi &dist,vi &parent,vector<P> &record,int bit){
  seen[now]=1;
  if(usedBoris==0&&bit>10){
    usedBoris=1;
    record.emplace_back(now,digitBoris(dist[now]));
    bit=digitBoris(dist[now]);
  }
  if(bit>20){
    usedBoris=1;
    record.emplace_back(now,digitBoris(dist[now]));
    bit=digitBoris(dist[now]);
  }
  for(int next:g[now]){
    if(seen[next]==1)continue;
    dist[next]=dist[now]+1;
    parent[next]=now;
    dfsBoris(next,g,seen,dist,parent,record,bit+1);
  }
  return;
}

void InitBoris(int N,int A[],int B[]){
  nBoris=N;
  rep(i,0,nBoris){
    disBoris[i]=1;
  }
  rep(i,0,nBoris-1){
    gBoris[A[i]].emplace_back(B[i]);
    gBoris[B[i]].emplace_back(A[i]);
    edgeBoris[i]={A[i],B[i]};
  }

  distBoris[0]=0;
  dfsBoris(0,gBoris,seenBoris,distBoris,parentBoris,recordBoris,0);
  
  sort(all(recordBoris));
  int now=0;
  for(auto [place,bit]:recordBoris){
    disBoris[place]=0;
    placeBoris[place]={now,now+bit-1};
    now+=bit;
  }

  rep(i,0,nBoris){
    if(disBoris[i]==1){
      placeBoris[i]={now,now};
      now++;
    }
  }

  if(now>1000){
    now=0;
    recordBoris.clear();
    rep(i,0,nBoris){
      seenBoris[i]=0;
      disBoris[i]=1;
    }
    dfsBoris(0,gBoris,seenBoris,distBoris,parentBoris,recordBoris,0);
    for(auto [place,bit]:recordBoris){
      disBoris[place]=0;
      placeBoris[place]={now,now+bit-1};
      now+=bit;
    }
    rep(i,0,nBoris){
      if(disBoris[i]==1){
        placeBoris[i]={now,now};
        now++;
      }
    }
  }
  return;
}

int ans(int city){
  if(city==0){
    return 0;
  }
  auto [p,q]=placeBoris[city];
  if(disBoris[city]==0){
    int res=0,bit=1;
    rep(i,p,q+1){
      int x=Ask(i);
      res+=bit*x;
      bit*=2;
    }
    return res;
  }
  else{
    int x=Ask(p);
    return ans(parentBoris[city])+x;
  }
}

int Boris(int city){
  int res=ans(city);
  return res;
}

// Boris end

Compilation message

Anya.cpp: In function 'void InitAnya(int, int*, int*)':
Anya.cpp:108:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  108 |   for(auto [place,bit]:recordAnya){
      |            ^
Anya.cpp:121:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  121 |     for(auto [place,bit]:recordAnya){
      |              ^
Anya.cpp: In function 'void Anya(int*)':
Anya.cpp:150:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  150 |   for(auto [place,bit]:recordAnya){
      |            ^

Boris.cpp: In function 'void InitBoris(int, int*, int*)':
Boris.cpp:96:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   96 |   for(auto [place,bit]:recordBoris){
      |            ^
Boris.cpp:117:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  117 |     for(auto [place,bit]:recordBoris){
      |              ^
Boris.cpp: In function 'int ans(int)':
Boris.cpp:136:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  136 |   auto [p,q]=placeBoris[city];
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 784 KB Output is correct
2 Correct 2 ms 776 KB Output is correct
3 Correct 2 ms 828 KB Output is correct
4 Correct 4 ms 996 KB Output is correct
5 Correct 5 ms 1064 KB Output is correct
6 Correct 5 ms 1056 KB Output is correct
7 Correct 5 ms 1064 KB Output is correct
8 Correct 5 ms 1184 KB Output is correct
9 Correct 5 ms 1068 KB Output is correct
10 Correct 5 ms 1064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1216 KB Output is correct
2 Correct 7 ms 1228 KB Output is correct
3 Correct 7 ms 1236 KB Output is correct
4 Correct 7 ms 1220 KB Output is correct
5 Correct 7 ms 1236 KB Output is correct
6 Correct 7 ms 1228 KB Output is correct
7 Correct 8 ms 1208 KB Output is correct
8 Correct 7 ms 1208 KB Output is correct
9 Correct 7 ms 1260 KB Output is correct
10 Correct 8 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1724 KB Output is correct
2 Correct 17 ms 1708 KB Output is correct
3 Correct 17 ms 1692 KB Output is correct
4 Correct 18 ms 1700 KB Output is correct
5 Correct 18 ms 1692 KB Output is correct
6 Correct 15 ms 1708 KB Output is correct
7 Correct 16 ms 1732 KB Output is correct
8 Correct 16 ms 1688 KB Output is correct
9 Correct 15 ms 1688 KB Output is correct
10 Correct 17 ms 1688 KB Output is correct
11 Correct 14 ms 1712 KB Output is correct
12 Correct 18 ms 1664 KB Output is correct
13 Correct 18 ms 1720 KB Output is correct
14 Correct 18 ms 1696 KB Output is correct
15 Correct 18 ms 1676 KB Output is correct
16 Correct 18 ms 1624 KB Output is correct
17 Correct 16 ms 1732 KB Output is correct
18 Correct 16 ms 1688 KB Output is correct
19 Correct 15 ms 1708 KB Output is correct
20 Correct 16 ms 1732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 1748 KB Output is correct
2 Correct 17 ms 1680 KB Output is correct
3 Correct 17 ms 1688 KB Output is correct
4 Correct 17 ms 1680 KB Output is correct
5 Correct 19 ms 1676 KB Output is correct
6 Correct 17 ms 1612 KB Output is correct
7 Correct 19 ms 1644 KB Output is correct
8 Correct 19 ms 1684 KB Output is correct
9 Correct 20 ms 1692 KB Output is correct
10 Correct 19 ms 1496 KB Output is correct
11 Correct 19 ms 1668 KB Output is correct
12 Correct 18 ms 1880 KB Output is correct
13 Correct 19 ms 1676 KB Output is correct
14 Correct 18 ms 1692 KB Output is correct
15 Correct 19 ms 1648 KB Output is correct
16 Correct 16 ms 1656 KB Output is correct
17 Correct 19 ms 1676 KB Output is correct
18 Correct 19 ms 1672 KB Output is correct
19 Correct 18 ms 1904 KB Output is correct
20 Correct 18 ms 1676 KB Output is correct
21 Correct 19 ms 1632 KB Output is correct
22 Correct 19 ms 1708 KB Output is correct
23 Correct 18 ms 1672 KB Output is correct
24 Correct 18 ms 1596 KB Output is correct
25 Correct 17 ms 1688 KB Output is correct
26 Correct 18 ms 1684 KB Output is correct
27 Correct 18 ms 1720 KB Output is correct
28 Correct 18 ms 1684 KB Output is correct
29 Correct 18 ms 1632 KB Output is correct
30 Correct 17 ms 1636 KB Output is correct
31 Correct 17 ms 1680 KB Output is correct
32 Correct 19 ms 1668 KB Output is correct
33 Correct 19 ms 1688 KB Output is correct
34 Correct 18 ms 1640 KB Output is correct
35 Correct 18 ms 1692 KB Output is correct
36 Correct 19 ms 1704 KB Output is correct
37 Correct 18 ms 1744 KB Output is correct
38 Correct 19 ms 1688 KB Output is correct
39 Correct 19 ms 1684 KB Output is correct
40 Correct 17 ms 1620 KB Output is correct
41 Correct 17 ms 1680 KB Output is correct
42 Correct 18 ms 1740 KB Output is correct
43 Correct 17 ms 1648 KB Output is correct
44 Correct 17 ms 1696 KB Output is correct
45 Correct 18 ms 1684 KB Output is correct
46 Correct 17 ms 1676 KB Output is correct
47 Correct 20 ms 1528 KB Output is correct
48 Correct 17 ms 1684 KB Output is correct
49 Correct 17 ms 1624 KB Output is correct
50 Correct 17 ms 1684 KB Output is correct