# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1062415 | sleepntsheep | Flights (JOI22_flights) | C++17 | 222 ms | 3156 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "Ali.h"
#include <string>
#include <cassert>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
namespace {
const int N=30000;
std::vector<int> g[N];
int hld[N],par[N],sz[N],dep[N];
void dfs(int u,int p){
dep[u]=dep[par[u]=p]+1;int best=0;
sz[u]=1;for(auto &v:g[u])if(v-p){
dfs(v,u),sz[u]+=sz[v];
if(sz[v]>best)swap(v,g[u][0]),best=sz[v];
}
}
void efs(int u){
for(auto v:g[u])if(v-par[u])
hld[v]=(v==g[u][0])?hld[u]:v,efs(v);
}
int lca(int u,int v){ while(hld[u]-hld[v]){ if(dep[hld[u]]<dep[hld[v]])swap(u,v); u=par[hld[u]]; } return dep[u]<dep[v]?u:v; }
int dist(int u,int v){return dep[u]+dep[v]-2*dep[lca(u,v)];}
void write(string&s,int i,int x,int b=14){ for(int j=0;j<b;++j) s[i+j]=((x>>j)&1)+'0'; }
ll read(string&s,int i,int b=14){ int z=0; for(int j=0;j<b;++j)z|=((s[i+j]-'0'))<<j; return z; }
int nn;
ll valid_enc(ll enc){ return enc/10000<nn and enc%10000<nn; }
ll XX(ll enc){return enc/10000;}
ll YY(ll enc){return enc%10000;}
}
void Init(int N, std::vector<int> U, std::vector<int> V) {
::nn = N;
for(int i=0;i<N;++i)g[i].clear(),hld[i]=0,par[i]=0,sz[i]=0,dep[i]=0;
for(int i=0;i+1<N;++i)g[U[i]].push_back(V[i]),g[V[i]].push_back(U[i]);
for(int i=0;i<N;++i)SetID(i,i);
dfs(0,0);
hld[0]=0;efs(0);
}
std::string SendA(std::string S) {
ll enc=read(S,0,20);
string T(1268,'0');
int cnt=0;
for(ll j=0;j<(1<<7);++j){
ll enc2 = (enc&((1<<20)-1)) | (j<<20);
if(not valid_enc(enc2))continue;
int xx=XX(enc2),yy=YY(enc2);
while(cnt*14+14>=T.size())T+='0';
write(T,cnt*14,dist(xx,yy));
++cnt;
}
return T;
}
#include "Benjamin.h"
#include <string>
#include <vector>
using namespace std;
using ll = long long;
namespace {
void write(string&s,int i,ll x,int b=14){ for(ll j=0;j<b;++j) s[i+j]=((x>>j)&1)+'0'; }
ll read(string&s,int i,int b=14){ int z=0; for(ll j=0;j<b;++j)z|=((s[i+j]-'0'))<<j; return z; }
int yy,nn;
ll enc_;
ll XX(ll enc){return enc/10000;}
ll YY(ll enc){return enc%10000;}
ll valid_enc(ll enc){ return enc/10000<nn and enc%10000<nn; }
}
std::string SendB(int N, int X, int Y) {
::nn=N;
string S(20,'0');
ll enc=10000ll*X+Y;
for(ll j=0;j<20;++j)
S[j]=((enc>>j)&1)+'0';
yy=Y;
enc_=enc;
return S;
}
int Answer(std::string T) {
int cnt=0;
for(ll j=0;j<(1<<7);++j){
ll enc2 = (enc_&((1<<20)-1)) | (j<<20);
if(enc2 == enc_) return read(T,cnt*14);
if(valid_enc(enc2))++cnt;
}
return -1;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |