답안 #298992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
298992 2020-09-14T11:51:06 Z erd1 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
69 / 100
5000 ms 9208 KB
#include "garden.h"
#include "gardenlib.h"

#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back
typedef int64_t lld;
typedef pair<int, int> pii;

vector<pii> to;
vector<int> arr, arr2, tmp1, tmp2;

void calc(int n, int b){
  tmp2.resize(n); tmp1.resize(n);
  iota(all(tmp1), 0); arr2 = arr;
  do{
    //for(auto i: tmp1)cout << i << " "; cout << endl;
    //for(auto i: arr2)cout << i << " "; cout << endl;
    if(b&1)
      for(int i = 0; i < n; i++)tmp1[i] = arr2[tmp1[i]];
    for(int i = 0; i < n; i++)tmp2[i] = arr2[arr2[i]];
    arr2 = tmp2;
  }while(b>>=1);
}

void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
  to.resize(N, {-1, -1}); arr.resize(2*N);
  for(int i = 0; i < M; i++){
    if(to[R[i][0]].ff == -1)to[R[i][0]].ff = R[i][1];
    else if(to[R[i][0]].ss == -1)to[R[i][0]].ss = R[i][1];
    if(to[R[i][1]].ff == -1)to[R[i][1]].ff = R[i][0];
    else if(to[R[i][1]].ss == -1)to[R[i][1]].ss = R[i][0];
  }
  for(int i = 0; i < N; i++){
    if(to[i].ss == -1)to[i].ss = to[i].ff;
    arr[2*i] = 2*to[i].ff + (to[to[i].ff].ff == i);
    arr[2*i+1] = 2*to[i].ss + (to[to[i].ss].ff == i);
  }
  //for(auto i: to)cout << i.ff << " " << i.ss << "  "; cout << endl;
  //for(auto i: arr)cout << i << " "; cout << endl;
  for(int i=0; i<Q; i++){
    calc(2*N, G[i]);
    //for(auto i: tmp1)cout << i << " "; cout << endl;
    int ans = 0;
    for(int i = 0; i < N; i++)
      if(tmp1[2*i]/2 == P)ans++;
    answer(ans);
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 8 ms 1664 KB Output is correct
12 Correct 18 ms 2816 KB Output is correct
13 Correct 30 ms 5364 KB Output is correct
14 Correct 56 ms 8464 KB Output is correct
15 Correct 58 ms 8696 KB Output is correct
16 Correct 48 ms 6520 KB Output is correct
17 Correct 48 ms 6008 KB Output is correct
18 Correct 18 ms 2808 KB Output is correct
19 Correct 57 ms 8356 KB Output is correct
20 Correct 63 ms 8568 KB Output is correct
21 Correct 49 ms 6520 KB Output is correct
22 Correct 47 ms 5932 KB Output is correct
23 Correct 55 ms 9208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 8 ms 1664 KB Output is correct
12 Correct 18 ms 2816 KB Output is correct
13 Correct 30 ms 5364 KB Output is correct
14 Correct 56 ms 8464 KB Output is correct
15 Correct 58 ms 8696 KB Output is correct
16 Correct 48 ms 6520 KB Output is correct
17 Correct 48 ms 6008 KB Output is correct
18 Correct 18 ms 2808 KB Output is correct
19 Correct 57 ms 8356 KB Output is correct
20 Correct 63 ms 8568 KB Output is correct
21 Correct 49 ms 6520 KB Output is correct
22 Correct 47 ms 5932 KB Output is correct
23 Correct 55 ms 9208 KB Output is correct
24 Correct 8 ms 384 KB Output is correct
25 Correct 2646 ms 1792 KB Output is correct
26 Execution timed out 5081 ms 2940 KB Time limit exceeded
27 Halted 0 ms 0 KB -