This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "Anyalib.h"
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;
const int MAX_N = 1e3 + 50;
static vector<pi> Ed[MAX_N];
static int N;
static pi Ix[MAX_N], Nr[MAX_N];
static int IN;
static int dfs(int v, int p) {
for(pi &t : Ed[v]) {
int w, ix; tie(w, ix) = t;
if(w != p) {
int st = IN;
Nr[st] = pi(ix, +1); IN++;
dfs(w, v);
int en = IN;
Nr[en] = pi(ix, -1); IN++;
Ix[ix] = pi(st, en);
}
}
}
void InitAnya(int n, int a[], int b[]) {
N = n;
for(int i=0; i+1<n; i++) {
Ed[a[i]].push_back(pi(b[i], i));
Ed[b[i]].push_back(pi(a[i], i));
}
dfs(0, -1);
return;
}
static int Sum[MAX_N];
void Anya(int C[]) {
for(int i=0; i<IN/20*20+40; i++)
Sum[i] = 0;
for(int i=0; i+1<N; i++) {
int st, en; tie(st, en) = Ix[i];
if(C[i] == 0) continue;
Sum[st]++; Sum[en]--;
}
for(int i=1; i<IN/20*20+40; i++)
Sum[i] += Sum[i-1];
for(int i=0; i<N-1; i++)
Save(i, C[i]);
for(int i=1; i<=IN/20; i++) {
int cnt[10] = {0, };
int val = Sum[i*20-1];
for(int k=0; k<10; k++) {
cnt[k] = val & 1;
val >>= 1;
}
for(int k=0; k<10; k++)
Save(500 + 10 * (i-1) + k, cnt[k]);
}
}
#include "Borislib.h"
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;
const int MAX_N = 1e3 + 50;
static vector<pi> Ed[MAX_N];
static int N;
static pi Ix[MAX_N], Nr[MAX_N];
static int IN, ixP[MAX_N];
static int dfs(int v, int p) {
for(pi &t : Ed[v]) {
int w, ix; tie(w, ix) = t;
if(w != p) {
int st = IN;
Nr[st] = pi(ix, +1); IN++;
ixP[w] = ix;
dfs(w, v);
int en = IN;
Nr[en] = pi(ix, -1); IN++;
Ix[ix] = pi(st, en);
}
}
}
void InitBoris(int n, int a[] , int b[]) {
N = n;
for(int i=0; i+1<n; i++) {
Ed[a[i]].push_back(pi(b[i], i));
Ed[b[i]].push_back(pi(a[i], i));
}
dfs(0, -1);
return;
}
int getG(int g) {
if(g == 0) return 0;
if(g > IN / 20) return 0;
int res = 0;
for(int k=9; k>=0; k--) {
res *= 2;
res += Ask(500 + 10 * (g-1) + k);
}
return res;
}
int getVal(int p) {
if(p >= IN) return 0;
int ix, t; tie(ix, t) = Nr[p];
return t * Ask(ix);
}
int Boris(int city) {
int ix = Ix[ixP[city]].one;
int ans = 0;
if(ix - ix / 20 * 20 < 10) {
ans = getG(ix / 20);
for(int i=ix/20*20; i<=ix; i++)
ans += getVal(i);
}else{
ans = getG(ix / 20 + 1);
for(int i=ix+1; i < (ix/20 + 1) * 20; i++)
ans -= getVal(i);
}
return ans;
}
Compilation message (stderr)
Anya.cpp: In function 'int dfs(int, int)':
Anya.cpp:38:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
Boris.cpp: In function 'int dfs(int, int)':
Boris.cpp:39:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |