답안 #776843

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
776843 2023-07-08T10:17:10 Z I_Love_EliskaM_ 열대 식물원 (Tropical Garden) (IOI11_garden) C++14
69 / 100
5000 ms 82280 KB
#include "gardenlib.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pi pair<int,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()

bool foo(pi a, pi b) {
  return a.s < b.s;
}

const int _N=2e5;
const int K=30;
int up[2][_N][K];
int z[2][_N][K];
vector<pi> adj[_N];

int jump(int u, int x) {
  int from=-1;
  for (int j=0; (1<<j)<=x; ++j) {
    if ((x>>j)&1) {
      if (from==adj[u][0].f) {
        from=z[1][u][j];
        u=up[1][u][j];
      } else {
        from=z[0][u][j];
        u=up[0][u][j];
      } 
    } 
  }
  return u;
}

void count_routes(int n, int m, int p, int r[][2], int q, int *g) {
  
  forn(i,m) {
    int u=r[i][0], v=r[i][1];
    adj[u].pb({v,i});
    adj[v].pb({u,i});
  }
  forn(i,n) sort(all(adj[i]),foo);

  forn(i,n) {
    if (adj[i].size()>1) {
      up[0][i][0]=adj[i][0].f;
      up[1][i][0]=adj[i][1].f;
    } else {
      up[0][i][0]=up[1][i][0]=adj[i][0].f;
    }
    z[0][i][0]=z[1][i][0]=i;
  }
  for (int j=1; j<K; ++j) {
    forn(i,n) {
      forn(c,2) {
        int u=i, v=up[c][i][j-1];
        if (z[c][i][j-1]==adj[v][0].f) {
          up[c][i][j] = up[1][v][j-1];
          z[c][i][j] = z[1][v][j-1];
        } else {
          up[c][i][j] = up[0][v][j-1];
          z[c][i][j] = z[0][v][j-1];
        }
      }
    }
  }

  vector<pi> v; forn(i,q) v.pb({g[i],i});
  map<int,int> mem;
  vector<int> ans(q);
  int last=0;
  forn(i,q) {
    int k=v[i].f;
    if (mem[k]) {
      ans[v[i].s]=mem[k]-1; continue;
    }
    int z=0;
    forn(j,n) z+=jump(j,k-last)==p;
    mem[k]=z+1;
    ans[v[i].s]=z;
  }
  forn(i,q) answer(ans[i]);
  
}

Compilation message

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:58:13: warning: unused variable 'u' [-Wunused-variable]
   58 |         int u=i, v=up[c][i][j-1];
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5460 KB Output is correct
2 Correct 3 ms 5460 KB Output is correct
3 Correct 4 ms 5460 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 5588 KB Output is correct
7 Correct 2 ms 5076 KB Output is correct
8 Correct 3 ms 5460 KB Output is correct
9 Correct 4 ms 5716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5460 KB Output is correct
2 Correct 3 ms 5460 KB Output is correct
3 Correct 4 ms 5460 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 5588 KB Output is correct
7 Correct 2 ms 5076 KB Output is correct
8 Correct 3 ms 5460 KB Output is correct
9 Correct 4 ms 5716 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 21 ms 16516 KB Output is correct
12 Correct 55 ms 24788 KB Output is correct
13 Correct 175 ms 48368 KB Output is correct
14 Correct 203 ms 74820 KB Output is correct
15 Correct 187 ms 75768 KB Output is correct
16 Correct 203 ms 53736 KB Output is correct
17 Correct 126 ms 46576 KB Output is correct
18 Correct 46 ms 24780 KB Output is correct
19 Correct 217 ms 74816 KB Output is correct
20 Correct 186 ms 75756 KB Output is correct
21 Correct 144 ms 53664 KB Output is correct
22 Correct 120 ms 46284 KB Output is correct
23 Correct 243 ms 82280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5460 KB Output is correct
2 Correct 3 ms 5460 KB Output is correct
3 Correct 4 ms 5460 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 3 ms 5588 KB Output is correct
7 Correct 2 ms 5076 KB Output is correct
8 Correct 3 ms 5460 KB Output is correct
9 Correct 4 ms 5716 KB Output is correct
10 Correct 3 ms 5076 KB Output is correct
11 Correct 21 ms 16516 KB Output is correct
12 Correct 55 ms 24788 KB Output is correct
13 Correct 175 ms 48368 KB Output is correct
14 Correct 203 ms 74820 KB Output is correct
15 Correct 187 ms 75768 KB Output is correct
16 Correct 203 ms 53736 KB Output is correct
17 Correct 126 ms 46576 KB Output is correct
18 Correct 46 ms 24780 KB Output is correct
19 Correct 217 ms 74816 KB Output is correct
20 Correct 186 ms 75756 KB Output is correct
21 Correct 144 ms 53664 KB Output is correct
22 Correct 120 ms 46284 KB Output is correct
23 Correct 243 ms 82280 KB Output is correct
24 Correct 11 ms 5204 KB Output is correct
25 Correct 3943 ms 17052 KB Output is correct
26 Execution timed out 5064 ms 25540 KB Time limit exceeded
27 Halted 0 ms 0 KB -