답안 #14806

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
14806 2015-06-27T12:53:55 Z gs14004 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
69 / 100
5000 ms 46480 KB
#include "garden.h"
#include "gardenlib.h"
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef pair<int,int> pi;

vector<pi> graph[150005];
int nxt[300005][30];
int low[150005];

void count_routes(int N, int M, int P, int R[][2], int Q, int G[])
{
    memset(low,0x3f,sizeof(low));
    for (int i=0; i<M; i++) {
        for (int j=0; j<2; j++) {
            low[R[i][j]] = min(low[R[i][j]],i);
        }
        graph[R[i][0]].push_back(pi(R[i][1],i));
        graph[R[i][1]].push_back(pi(R[i][0],i));
    }
    for (int i=0; i<N; i++) {
        if(low[graph[i][0].first] == graph[i][0].second){
            nxt[2*i][0] = graph[i][0].first * 2 + 1;
        }
        else{
            nxt[2*i][0] = graph[i][0].first * 2;
        }
        if(graph[i].size() == 1){
            nxt[2*i+1][0] = nxt[2*i][0];
        }
        else{
            if(low[graph[i][1].first] == graph[i][1].second){
                nxt[2*i+1][0] = graph[i][1].first * 2 + 1;
            }
            else{
                nxt[2*i+1][0] = graph[i][1].first * 2;
            }
        }
    }
    for (int i=1; i<30; i++) {
        for (int j=0; j<2*N; j++) {
            nxt[j][i] = nxt[nxt[j][i-1]][i-1];
        }
    }
    for (int i=0; i<Q; i++) {
        int time = G[i];
        int cnt = 0;
        for (int j=0; j<N; j++) {
            int pos = 2*j;
            for (int k=0; k<30; k++) {
                if((time >> k) & 1){
                    pos = nxt[pos][k];
                }
            }
            if(pos == 2*P || pos == 2*P+1){
                cnt++;
            }
        }
        answer(cnt);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4660 KB Output is correct
2 Correct 6 ms 4728 KB Output is correct
3 Correct 6 ms 4704 KB Output is correct
4 Correct 5 ms 4472 KB Output is correct
5 Correct 6 ms 4472 KB Output is correct
6 Correct 7 ms 4704 KB Output is correct
7 Correct 6 ms 4452 KB Output is correct
8 Correct 6 ms 4728 KB Output is correct
9 Correct 8 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4660 KB Output is correct
2 Correct 6 ms 4728 KB Output is correct
3 Correct 6 ms 4704 KB Output is correct
4 Correct 5 ms 4472 KB Output is correct
5 Correct 6 ms 4472 KB Output is correct
6 Correct 7 ms 4704 KB Output is correct
7 Correct 6 ms 4452 KB Output is correct
8 Correct 6 ms 4728 KB Output is correct
9 Correct 8 ms 4984 KB Output is correct
10 Correct 6 ms 4416 KB Output is correct
11 Correct 29 ms 10748 KB Output is correct
12 Correct 56 ms 15556 KB Output is correct
13 Correct 140 ms 27808 KB Output is correct
14 Correct 241 ms 42580 KB Output is correct
15 Correct 235 ms 43060 KB Output is correct
16 Correct 163 ms 31752 KB Output is correct
17 Correct 127 ms 28056 KB Output is correct
18 Correct 52 ms 15524 KB Output is correct
19 Correct 229 ms 42588 KB Output is correct
20 Correct 239 ms 43152 KB Output is correct
21 Correct 150 ms 31632 KB Output is correct
22 Correct 120 ms 27896 KB Output is correct
23 Correct 272 ms 46480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4660 KB Output is correct
2 Correct 6 ms 4728 KB Output is correct
3 Correct 6 ms 4704 KB Output is correct
4 Correct 5 ms 4472 KB Output is correct
5 Correct 6 ms 4472 KB Output is correct
6 Correct 7 ms 4704 KB Output is correct
7 Correct 6 ms 4452 KB Output is correct
8 Correct 6 ms 4728 KB Output is correct
9 Correct 8 ms 4984 KB Output is correct
10 Correct 6 ms 4416 KB Output is correct
11 Correct 29 ms 10748 KB Output is correct
12 Correct 56 ms 15556 KB Output is correct
13 Correct 140 ms 27808 KB Output is correct
14 Correct 241 ms 42580 KB Output is correct
15 Correct 235 ms 43060 KB Output is correct
16 Correct 163 ms 31752 KB Output is correct
17 Correct 127 ms 28056 KB Output is correct
18 Correct 52 ms 15524 KB Output is correct
19 Correct 229 ms 42588 KB Output is correct
20 Correct 239 ms 43152 KB Output is correct
21 Correct 150 ms 31632 KB Output is correct
22 Correct 120 ms 27896 KB Output is correct
23 Correct 272 ms 46480 KB Output is correct
24 Correct 14 ms 4444 KB Output is correct
25 Execution timed out 5055 ms 10748 KB Time limit exceeded
26 Halted 0 ms 0 KB -