#include "Ali.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
string toBin(int n, int l) {
string s(l, '0');
for(int i=0;i<l;i++)
s[i] = !!(n & (1 << i)) + '0';
return s;
}
int toDec(string s) {
reverse(s.begin(),s.end());
int ans = 0;
for(auto i: s)
ans = (ans << 1) | (i & 1);
return ans;
}
vector<vector<int>> adj;
int euler[20'005], dist[10'005], n;
}
void Init(int N, std::vector<int> U, std::vector<int> V) {
n = N;
adj.clear();
adj.resize(N);
for(int i=0;i<N-1;i++) {
adj[U[i]].push_back(V[i]);
adj[V[i]].push_back(U[i]);
}
auto dfs = [&adj,cnt=0](auto &self, int x, int p) mutable -> void {
SetID(x, cnt);
euler[cnt++] = x;
for(auto i: adj[x])
if(i != p) {
self(self, i, x);
euler[cnt++] = x;
}
};
dfs(dfs, 0, -1);
}
std::string SendA(std::string S) {
int M = toDec(S);
int x = (M % 2858) * 7;
int y = (M / 2858) * 55;
string ret;
for(int i=0;i<7;i++) {
if(i + x > 2 * n - 2)
ret += '0';
else {
ret += '1';
for(int j=0;j<i;j++)
if(euler[i+x] == euler[j+x])
ret[i] = '0';
}
}
ret = ret.substr(2, 5);
for(int i=0;i<6;i++) {
if(x + i + 1 > 2 * n - 2)
ret += toBin(-1, 6);
else
for(int j=0;j<2*n-2;j++)
if(euler[j] == euler[x + i + 1] && euler[j + 1] == euler[x + i]) {
if(j >= y && j < y + 55)
ret += toBin(j - y, 6);
else
ret += toBin(-1, 6);
}
}
auto dfs = [&adj](auto &self, int x, int p) mutable -> void {
for(auto i: adj[x])
if(i != p) {
dist[i] = dist[x] + 1;
self(self, i, x);
}
};
dist[euler[y]] = 0;
dfs(dfs, euler[y], -1);
ret += toBin(dist[euler[x]], 14);
for(int i=1;i<7;i++)
if(x+i>2*n-2||dist[euler[x+i]]>dist[euler[x+i-1]])
ret += '1';
else
ret += '0';
dist[euler[x]] = 0;
dfs(dfs, euler[x], -1);
for(int i=0;i<min(54,2*n-2-y);i++)
ret += (dist[euler[y+i+1]]>dist[euler[y+i]]?'1':'0');
return ret;
}
#include "Benjamin.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
string toBin(int n, int l) {
string s(l, '0');
for(int i=0;i<l;i++)
s[i] = !!(n & (1 << i)) + '0';
return s;
}
int toDec(string s) {
reverse(s.begin(),s.end());
int ans = 0;
for(auto i: s)
ans = (ans << 1) | (i & 1);
return ans;
}
int x, y;
}
std::string SendB(int N, int X, int Y) {
x = X, y = Y;
return toBin((X / 7) + 2858 * (Y / 55), 20);
}
int Answer(std::string T) {
string st = "1" + T.substr(0,5);
bool same[6];
for(int i=0;i<6;i++) {
int cnt = 0;
for(int j=i;j<(x%7);j++)
cnt += (st[j]&1?1:-1);
same[i] = !cnt;
}
int cross[6];
for(int i=0;i<6;i++)
cross[i] = toDec(T.substr(5+6*i,6)) + 55 * (y / 55);
int ans = toDec(T.substr(41,14));
for(int i=0;i<(x%7);i++)
ans += (T[55+i]&1?1:-1);
for(int i=0;i<(y%55);i++) {
bool sm = 1;
if(i + 55 * (y / 55) >= 7 * (x / 7) && i + 55 * (y / 55) <= 7 * (x / 7) + 5 && !same[i + 55 * (y / 55) - 7 * (x / 7)])
sm = 0;
for(int j=0;j<6;j++)
if(i == cross[j] && !same[j])
sm = 0;
ans += ((T[i]&1)^(!sm)?1:-1);
}
return ans;
}
Compilation message (stderr)
# 1번째 컴파일 단계
Ali.cpp: In function 'void Init(int, std::vector<int>, std::vector<int>)':
Ali.cpp:31:22: warning: capture of variable '{anonymous}::adj' with non-automatic storage duration
31 | auto dfs = [&adj,cnt=0](auto &self, int x, int p) mutable -> void {
| ^~~
Ali.cpp:19:29: note: 'std::vector<std::vector<int> > {anonymous}::adj' declared here
19 | vector<vector<int>> adj;
| ^~~
Ali.cpp: In function 'std::string SendA(std::string)':
Ali.cpp:74:22: warning: capture of variable '{anonymous}::adj' with non-automatic storage duration
74 | auto dfs = [&adj](auto &self, int x, int p) mutable -> void {
| ^~~
Ali.cpp:19:29: note: 'std::vector<std::vector<int> > {anonymous}::adj' declared here
19 | vector<vector<int>> adj;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |