답안 #26242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26242 2017-06-28T13:22:12 Z 카제비(#1106, kajebiii) Snowy Roads (JOI16_snowy) C++14
100 / 100
22 ms 4228 KB
#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];
//        printf("Sum[%d] = %d\n", i, Sum[i]);
    }
    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];
//        printf("send : %d -> %d\n", i, val);
        for(int k=0; k<10; k++) {
            cnt[k] = val & 1;
            val >>= 1;
        }
        for(int k=0; k<10; k++) {
//            printf("save at (%d) %d is %d\n", i, 500 + 10 * (i-1) + k, cnt[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);
//    for(int i=0; i<IN; i++) printf("%d %d\n", Nr[i].one, Nr[i].two); puts("");
    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];
//    printf("%d : %d\n", p, t * Ask(ix));
    return t * Ask(ix);
}
int Boris(int city) {
    int ix = Ix[ixP[city]].one;
//    printf("(line %d | %d)\n", ixP[city], ix);

    int ans = 0;
    if(ix - ix / 20 * 20 < 10) {
        ans = getG(ix / 20);
//        printf("left %d\n", ans);
        for(int i=ix/20*20; i<=ix; i++)
            ans += getVal(i);
    }else{
        ans = getG(ix / 20 + 1);
//        printf("right %d\n", ans);
        for(int i=ix+1; i < (ix/20 + 1) * 20; i++)
            ans -= getVal(i);
    }
//    printf("ans is %d\n", ans);
    return ans;
}

Compilation message

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]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4228 KB Output is correct
2 Correct 0 ms 4228 KB Output is correct
3 Correct 0 ms 4228 KB Output is correct
4 Correct 0 ms 4228 KB Output is correct
5 Correct 3 ms 4228 KB Output is correct
6 Correct 6 ms 4228 KB Output is correct
7 Correct 9 ms 4228 KB Output is correct
8 Correct 3 ms 4228 KB Output is correct
9 Correct 9 ms 4228 KB Output is correct
10 Correct 6 ms 4228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 4228 KB Output is correct
2 Correct 6 ms 4228 KB Output is correct
3 Correct 9 ms 4228 KB Output is correct
4 Correct 6 ms 4228 KB Output is correct
5 Correct 9 ms 4228 KB Output is correct
6 Correct 3 ms 4228 KB Output is correct
7 Correct 6 ms 4228 KB Output is correct
8 Correct 9 ms 4228 KB Output is correct
9 Correct 6 ms 4228 KB Output is correct
10 Correct 12 ms 4228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 4228 KB Output is correct
2 Correct 12 ms 4228 KB Output is correct
3 Correct 13 ms 4228 KB Output is correct
4 Correct 16 ms 4228 KB Output is correct
5 Correct 12 ms 4228 KB Output is correct
6 Correct 16 ms 4228 KB Output is correct
7 Correct 16 ms 4228 KB Output is correct
8 Correct 16 ms 4228 KB Output is correct
9 Correct 16 ms 4228 KB Output is correct
10 Correct 9 ms 4228 KB Output is correct
11 Correct 9 ms 4228 KB Output is correct
12 Correct 12 ms 4228 KB Output is correct
13 Correct 16 ms 4228 KB Output is correct
14 Correct 16 ms 4228 KB Output is correct
15 Correct 16 ms 4228 KB Output is correct
16 Correct 12 ms 4228 KB Output is correct
17 Correct 16 ms 4228 KB Output is correct
18 Correct 16 ms 4228 KB Output is correct
19 Correct 19 ms 4228 KB Output is correct
20 Correct 16 ms 4228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 4228 KB Output is correct
2 Correct 16 ms 4228 KB Output is correct
3 Correct 16 ms 4228 KB Output is correct
4 Correct 19 ms 4228 KB Output is correct
5 Correct 16 ms 4228 KB Output is correct
6 Correct 12 ms 4228 KB Output is correct
7 Correct 19 ms 4228 KB Output is correct
8 Correct 16 ms 4228 KB Output is correct
9 Correct 13 ms 4228 KB Output is correct
10 Correct 16 ms 4228 KB Output is correct
11 Correct 16 ms 4228 KB Output is correct
12 Correct 15 ms 4228 KB Output is correct
13 Correct 16 ms 4228 KB Output is correct
14 Correct 16 ms 4228 KB Output is correct
15 Correct 12 ms 4228 KB Output is correct
16 Correct 16 ms 4228 KB Output is correct
17 Correct 16 ms 4228 KB Output is correct
18 Correct 19 ms 4228 KB Output is correct
19 Correct 16 ms 4228 KB Output is correct
20 Correct 19 ms 4228 KB Output is correct
21 Correct 16 ms 4228 KB Output is correct
22 Correct 19 ms 4228 KB Output is correct
23 Correct 19 ms 4228 KB Output is correct
24 Correct 16 ms 4228 KB Output is correct
25 Correct 22 ms 4228 KB Output is correct
26 Correct 16 ms 4228 KB Output is correct
27 Correct 12 ms 4228 KB Output is correct
28 Correct 19 ms 4228 KB Output is correct
29 Correct 16 ms 4228 KB Output is correct
30 Correct 19 ms 4228 KB Output is correct
31 Correct 19 ms 4228 KB Output is correct
32 Correct 16 ms 4228 KB Output is correct
33 Correct 16 ms 4228 KB Output is correct
34 Correct 12 ms 4228 KB Output is correct
35 Correct 16 ms 4228 KB Output is correct
36 Correct 19 ms 4228 KB Output is correct
37 Correct 12 ms 4228 KB Output is correct
38 Correct 12 ms 4228 KB Output is correct
39 Correct 16 ms 4228 KB Output is correct
40 Correct 12 ms 4228 KB Output is correct
41 Correct 16 ms 4228 KB Output is correct
42 Correct 12 ms 4228 KB Output is correct
43 Correct 16 ms 4228 KB Output is correct
44 Correct 16 ms 4228 KB Output is correct
45 Correct 19 ms 4228 KB Output is correct
46 Correct 16 ms 4228 KB Output is correct
47 Correct 9 ms 4228 KB Output is correct
48 Correct 16 ms 4228 KB Output is correct
49 Correct 16 ms 4228 KB Output is correct
50 Correct 13 ms 4228 KB Output is correct