#include "Ali.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
vector<vector<int>> adj;
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 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 / 50;
int k = (M % 50) * 400;
dist[euler[x]] = 0;
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);
}
};
dfs(dfs, euler[x], -1);
string ret = toBin(dist[euler[k]], 14);
for(int i=0;i<min(399,2*n-2-k);i++)
ret += (dist[euler[k+i+1]]>dist[euler[k+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(50 * X + (Y / 400), 20);
}
int Answer(std::string T) {
int ans = toDec(T.substr(0,14));
for(int i=0;i<(y%400);i++)
ans += (T[i+14]&1?1:-1);
return ans;
}
컴파일 시 표준 에러 (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:6:29: note: 'std::vector<std::vector<int> > {anonymous}::adj' declared here
6 | vector<vector<int>> adj;
| ^~~
Ali.cpp: In function 'std::string SendA(std::string)':
Ali.cpp:48:22: warning: capture of variable '{anonymous}::adj' with non-automatic storage duration
48 | auto dfs = [&adj](auto &self, int x, int p) mutable -> void {
| ^~~
Ali.cpp:6:29: note: 'std::vector<std::vector<int> > {anonymous}::adj' declared here
6 | vector<vector<int>> adj;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |