답안 #289485

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
289485 2020-09-02T16:57:00 Z alexandra_udristoiu Amusement Park (JOI17_amusement_park) C++14
100 / 100
44 ms 4604 KB
#include<algorithm>
#include<vector>
#include "Joi.h"
#define DIM 10005
using namespace std;
static vector<int> v[DIM];
static int d[DIM], e[DIM], c[DIM], t[DIM], viz[DIM], dj[DIM], ind[DIM];
static int nr, k;
static void dfs(int nod, int tt){
    t[nod] = tt;
    viz[nod] = 1;
    for(int i = 0; i < v[nod].size(); i++){
        int vecin = v[nod][i];
        if(viz[vecin] == 0){
            d[vecin] = 1 + d[nod];
            dfs(vecin, nod);
            dj[nod] = max(dj[vecin] + 1, dj[nod]);
        }
    }
}
static void dfs2(int nod, int tip){
    if(ind[nod] == -1){
        if(k == 60){
            return;
        }
        ind[nod] = k++;
    }
    int i, vecin, x = -1;
    for(i = 0; i < v[nod].size(); i++){
        vecin = v[nod][i];
        if(t[vecin] == nod && dj[vecin] == dj[nod] - 1 && tip == 0){
            x = vecin;
            dfs2(vecin, tip);
            break;
        }
    }
    for(i = 0; i < v[nod].size(); i++){
        vecin = v[nod][i];
        if(t[vecin] == nod && vecin != x && k != 60){
            e[++nr] = nod;
            dfs2(vecin, 1);
        }
    }
    e[++nr] = nod;
}

void Joi(int n, int m, int a[], int b[], long long x, int aux) {
    int i, maxim = 0, nod, u;
    for(i = 0; i < m; i++){
        v[ a[i] ].push_back(b[i]);
        v[ b[i] ].push_back(a[i]);
    }
    dfs(0, -1);
    if(dj[0] + 1 >= 60){
        for(i = 0; i < n; i++){
            d[i] %= 60;
            MessageBoard(i, ( (x >> d[i]) & 1) );
        }
        return;
    }
    for(i = 0; i < n; i++){
        ind[i] = -1;
    }
    dfs2(0, 0);
    for(i = 0; i < n; i++){
        if(ind[i] != -1){
            MessageBoard(i, ( (x >> ind[i]) & 1) );
        }
        else{
            MessageBoard(i, 0);
        }
    }
}

#include "Ioi.h"
#include<algorithm>
#include<vector>
#define DIM 10005
using namespace std;
static vector<int> v[DIM];
static int d[DIM], e[DIM], c[DIM], t[DIM], ind[DIM], dj[DIM], viz[DIM];
static int nr, k;
static void dfs(int nod, int tt){
    t[nod] = tt;
    viz[nod] = 1;
    for(int i = 0; i < v[nod].size(); i++){
        int vecin = v[nod][i];
        if(viz[vecin] == 0){
            d[vecin] = 1 + d[nod];
            dfs(vecin, nod);
            dj[nod] = max(dj[vecin] + 1, dj[nod]);
        }
    }
}
static void dfs2(int nod, int tip){
    if(ind[nod] == -1){
        if(k == 60){
            return;
        }
        ind[nod] = k++;
    }
    int i, vecin, x = -1;
    for(i = 0; i < v[nod].size(); i++){
        vecin = v[nod][i];
        if(t[vecin] == nod && dj[vecin] == dj[nod] - 1 && tip == 0){
            x = vecin;
            dfs2(vecin, tip);
            break;
        }
    }
    for(i = 0; i < v[nod].size(); i++){
        vecin = v[nod][i];
        if(t[vecin] == nod && vecin != x && k != 60){
            e[++nr] = nod;
            dfs2(vecin, 1);
        }
    }
    e[++nr] = nod;
}

long long Ioi(int n, int m, int a[], int b[], int p, int val, int aux) {
    long long x = 0;
    int i, maxim = 0, nod, u, j;
    for(i = 0; i < m; i++){
        v[ a[i] ].push_back(b[i]);
        v[ b[i] ].push_back(a[i]);
    }
    dfs(0, -1);
    if(dj[0] + 1 >= 60){
        if(d[p] + 1 >= 60){
            d[p] %= 60;
            x += (1LL << d[p]) * val;
            for(i = 1; i < 60; i++){
                val = Move(t[p]);
                p = t[p];
                d[p] %= 60;
                x += (1LL << d[p]) * val;
            }
        }
        else{
            while(p != 0){
                val = Move(t[p]);
                p = t[p];
            }
            x += val;
            for(i = 1; i < 60; i++){
                for(j = 0; j < v[p].size(); j++){
                    if(dj[ v[p][j] ] == dj[p] - 1){
                        p = v[p][j];
                        val = Move(p);
                        x += (1LL << i) * val;
                        break;
                    }
                }
            }
        }
    }
    else{
        for(i = 0; i < n; i++){
            ind[i] = -1;
        }
        dfs2(0, 0);
        while(p != 0){
            val = Move(t[p]);
            p = t[p];
        }
        x += val;
        for(i = nr - 1; i >= 1; i--){
            val = Move(e[i]);
            x |= (1LL << ind[ e[i] ]) * val;
        }
    }
    return x;
}

Compilation message

Joi.cpp: In function 'void dfs(int, int)':
Joi.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i = 0; i < v[nod].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~
Joi.cpp: In function 'void dfs2(int, int)':
Joi.cpp:29:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(i = 0; i < v[nod].size(); i++){
      |                ~~^~~~~~~~~~~~~~~
Joi.cpp:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(i = 0; i < v[nod].size(); i++){
      |                ~~^~~~~~~~~~~~~~~
Joi.cpp: In function 'void Joi(int, int, int*, int*, long long int, int)':
Joi.cpp:48:12: warning: unused variable 'maxim' [-Wunused-variable]
   48 |     int i, maxim = 0, nod, u;
      |            ^~~~~
Joi.cpp:48:23: warning: unused variable 'nod' [-Wunused-variable]
   48 |     int i, maxim = 0, nod, u;
      |                       ^~~
Joi.cpp:48:28: warning: unused variable 'u' [-Wunused-variable]
   48 |     int i, maxim = 0, nod, u;
      |                            ^
Joi.cpp: At global scope:
Joi.cpp:7:28: warning: 'c' defined but not used [-Wunused-variable]
    7 | static int d[DIM], e[DIM], c[DIM], t[DIM], viz[DIM], dj[DIM], ind[DIM];
      |                            ^

Ioi.cpp: In function 'void dfs(int, int)':
Ioi.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i = 0; i < v[nod].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~
Ioi.cpp: In function 'void dfs2(int, int)':
Ioi.cpp:29:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(i = 0; i < v[nod].size(); i++){
      |                ~~^~~~~~~~~~~~~~~
Ioi.cpp:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(i = 0; i < v[nod].size(); i++){
      |                ~~^~~~~~~~~~~~~~~
Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:73:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |                 for(j = 0; j < v[p].size(); j++){
      |                            ~~^~~~~~~~~~~~~
Ioi.cpp:49:12: warning: unused variable 'maxim' [-Wunused-variable]
   49 |     int i, maxim = 0, nod, u, j;
      |            ^~~~~
Ioi.cpp:49:23: warning: unused variable 'nod' [-Wunused-variable]
   49 |     int i, maxim = 0, nod, u, j;
      |                       ^~~
Ioi.cpp:49:28: warning: unused variable 'u' [-Wunused-variable]
   49 |     int i, maxim = 0, nod, u, j;
      |                            ^
Ioi.cpp: At global scope:
Ioi.cpp:7:28: warning: 'c' defined but not used [-Wunused-variable]
    7 | static int d[DIM], e[DIM], c[DIM], t[DIM], ind[DIM], dj[DIM], viz[DIM];
      |                            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1284 KB Output is correct
2 Correct 2 ms 1292 KB Output is correct
3 Correct 2 ms 1424 KB Output is correct
4 Correct 1 ms 1288 KB Output is correct
5 Correct 2 ms 1288 KB Output is correct
6 Correct 2 ms 1160 KB Output is correct
7 Correct 2 ms 1540 KB Output is correct
8 Correct 2 ms 1296 KB Output is correct
9 Correct 2 ms 1532 KB Output is correct
10 Correct 1 ms 1160 KB Output is correct
11 Correct 6 ms 1636 KB Output is correct
12 Correct 2 ms 1264 KB Output is correct
13 Correct 3 ms 1532 KB Output is correct
14 Correct 3 ms 1296 KB Output is correct
15 Correct 2 ms 1536 KB Output is correct
16 Correct 3 ms 1296 KB Output is correct
17 Correct 2 ms 1528 KB Output is correct
18 Correct 3 ms 1296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 4344 KB Output is correct
2 Correct 41 ms 4392 KB Output is correct
3 Correct 44 ms 4316 KB Output is correct
4 Correct 18 ms 3036 KB Output is correct
5 Correct 20 ms 3388 KB Output is correct
6 Correct 22 ms 3516 KB Output is correct
7 Correct 18 ms 3388 KB Output is correct
8 Correct 18 ms 3540 KB Output is correct
9 Correct 25 ms 3540 KB Output is correct
10 Correct 20 ms 3520 KB Output is correct
11 Correct 22 ms 3264 KB Output is correct
12 Correct 16 ms 3356 KB Output is correct
13 Correct 20 ms 3348 KB Output is correct
14 Correct 16 ms 3320 KB Output is correct
15 Correct 18 ms 3300 KB Output is correct
16 Correct 17 ms 3132 KB Output is correct
17 Correct 18 ms 3292 KB Output is correct
18 Correct 20 ms 3296 KB Output is correct
19 Correct 17 ms 3132 KB Output is correct
20 Correct 15 ms 3644 KB Output is correct
21 Correct 14 ms 3644 KB Output is correct
22 Correct 18 ms 3612 KB Output is correct
23 Correct 17 ms 3428 KB Output is correct
24 Correct 18 ms 3592 KB Output is correct
25 Correct 20 ms 3516 KB Output is correct
26 Correct 20 ms 3496 KB Output is correct
27 Correct 18 ms 3516 KB Output is correct
28 Correct 18 ms 3388 KB Output is correct
29 Correct 16 ms 3364 KB Output is correct
30 Correct 17 ms 3504 KB Output is correct
31 Correct 1 ms 1296 KB Output is correct
32 Correct 2 ms 1288 KB Output is correct
33 Correct 2 ms 1540 KB Output is correct
34 Correct 2 ms 1160 KB Output is correct
35 Correct 2 ms 1300 KB Output is correct
36 Correct 2 ms 1160 KB Output is correct
37 Correct 2 ms 1160 KB Output is correct
38 Correct 2 ms 1160 KB Output is correct
39 Correct 1 ms 1304 KB Output is correct
40 Correct 1 ms 1160 KB Output is correct
41 Correct 2 ms 1288 KB Output is correct
42 Correct 2 ms 1288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1296 KB Output is correct
2 Correct 2 ms 1156 KB Output is correct
3 Correct 2 ms 1156 KB Output is correct
4 Correct 3 ms 1572 KB Output is correct
5 Correct 4 ms 1768 KB Output is correct
6 Correct 4 ms 1764 KB Output is correct
7 Correct 4 ms 1572 KB Output is correct
8 Correct 4 ms 1572 KB Output is correct
9 Correct 15 ms 3916 KB Output is correct
10 Correct 15 ms 3840 KB Output is correct
11 Correct 18 ms 4036 KB Output is correct
12 Correct 1 ms 1160 KB Output is correct
13 Correct 2 ms 1536 KB Output is correct
14 Correct 2 ms 1372 KB Output is correct
15 Correct 1 ms 1160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 4588 KB Output is correct
2 Correct 30 ms 4596 KB Output is correct
3 Correct 34 ms 4576 KB Output is correct
4 Correct 20 ms 3304 KB Output is correct
5 Correct 20 ms 3900 KB Output is correct
6 Correct 18 ms 3540 KB Output is correct
7 Correct 20 ms 3388 KB Output is correct
8 Correct 18 ms 3496 KB Output is correct
9 Correct 18 ms 3592 KB Output is correct
10 Correct 17 ms 3264 KB Output is correct
11 Correct 16 ms 3328 KB Output is correct
12 Correct 19 ms 3348 KB Output is correct
13 Correct 23 ms 3352 KB Output is correct
14 Correct 17 ms 3248 KB Output is correct
15 Correct 20 ms 3260 KB Output is correct
16 Correct 17 ms 3172 KB Output is correct
17 Correct 20 ms 3304 KB Output is correct
18 Correct 18 ms 3296 KB Output is correct
19 Correct 18 ms 3292 KB Output is correct
20 Correct 15 ms 3760 KB Output is correct
21 Correct 15 ms 3768 KB Output is correct
22 Correct 18 ms 3556 KB Output is correct
23 Correct 18 ms 3568 KB Output is correct
24 Correct 17 ms 3580 KB Output is correct
25 Correct 17 ms 3388 KB Output is correct
26 Correct 17 ms 3600 KB Output is correct
27 Correct 17 ms 3716 KB Output is correct
28 Correct 18 ms 3596 KB Output is correct
29 Correct 20 ms 3240 KB Output is correct
30 Correct 20 ms 3580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 4604 KB Output is correct
2 Correct 33 ms 4424 KB Output is correct
3 Correct 28 ms 4596 KB Output is correct
4 Correct 17 ms 3100 KB Output is correct
5 Correct 17 ms 3900 KB Output is correct
6 Correct 17 ms 3516 KB Output is correct
7 Correct 17 ms 3616 KB Output is correct
8 Correct 17 ms 3808 KB Output is correct
9 Correct 17 ms 3564 KB Output is correct
10 Correct 17 ms 3264 KB Output is correct
11 Correct 16 ms 3392 KB Output is correct
12 Correct 16 ms 3236 KB Output is correct
13 Correct 15 ms 3108 KB Output is correct
14 Correct 16 ms 3376 KB Output is correct
15 Correct 18 ms 3312 KB Output is correct
16 Correct 17 ms 3304 KB Output is correct
17 Correct 19 ms 3260 KB Output is correct
18 Correct 17 ms 3296 KB Output is correct
19 Correct 17 ms 3260 KB Output is correct
20 Correct 14 ms 3748 KB Output is correct
21 Correct 15 ms 3768 KB Output is correct
22 Correct 19 ms 3564 KB Output is correct
23 Correct 17 ms 3596 KB Output is correct
24 Correct 17 ms 3388 KB Output is correct
25 Correct 17 ms 3584 KB Output is correct
26 Correct 17 ms 3516 KB Output is correct
27 Correct 17 ms 3644 KB Output is correct
28 Correct 17 ms 3708 KB Output is correct
29 Correct 16 ms 3488 KB Output is correct
30 Correct 17 ms 3580 KB Output is correct
31 Correct 1 ms 1416 KB Output is correct
32 Correct 2 ms 1288 KB Output is correct
33 Correct 2 ms 1532 KB Output is correct
34 Correct 2 ms 1288 KB Output is correct
35 Correct 1 ms 1288 KB Output is correct
36 Correct 1 ms 1160 KB Output is correct
37 Correct 1 ms 1548 KB Output is correct
38 Correct 2 ms 1300 KB Output is correct
39 Correct 2 ms 1288 KB Output is correct
40 Correct 2 ms 1296 KB Output is correct
41 Correct 2 ms 1424 KB Output is correct
42 Correct 1 ms 1300 KB Output is correct