Submission #1837187
Source Code Expand
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <iostream> #include <sstream> #include <functional> #include <map> #include <string> #include <cstring> #include <vector> #include <queue> #include <stack> #include <deque> #include <set> #include <list> #include <numeric> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> P; const double PI = 3.14159265358979323846; const double EPS = 1e-12; const ll INF = 1LL<<29; const ll mod = 1e9+7; #define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i)) #define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d)) #define all(v) (v).begin(), (v).end() #define pb(x) push_back(x) #define mp(x,y) make_pair((x),(y)) #define mset(m,v) memset((m),(v),sizeof(m)) #define chmin(X,Y) ((X)>(Y)?X=(Y),true:false) #define chmax(X,Y) ((X)<(Y)?X=(Y),true:false) #define fst first #define snd second #define UNIQUE(x) (x).erase(unique(all(x)),(x).end()) template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;} #define N 100010 int n, k, a[N], d[N]; vector<int> g[N]; void dfs(int u, int x){ d[u] = x; for(auto &&v: g[u]) dfs(v, x+1); } int main(){ scanf("%d %d", &n, &k); rep(i, n) scanf("%d", a+i); rep(i, n) a[i]--; int res = 0; if(a[0]!=0){ a[0] = 0; res++; } rep(i, n-1) g[a[i+1]].push_back(i+1); dfs(0, 0); priority_queue<P> q; rep(i, n) if(d[i]>k) q.push(P(d[i], i)); while(!q.empty()){ int u = q.top().snd; q.pop(); if(d[u]<k) continue; res++; rep(_, k){ d[u] = 0; u = a[u]; } } printf("%d\n", res); return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Teleporter |
User | Lepton |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1735 Byte |
Status | WA |
Exec Time | 1056 ms |
Memory | 11764 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:48:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d", &n, &k); ^ ./Main.cpp:49:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] rep(i, n) scanf("%d", a+i); ^
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 800 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt, 1_46.txt, 1_47.txt, 1_48.txt, 1_49.txt, 1_50.txt, 1_51.txt, 1_52.txt, 1_53.txt, 1_54.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 2 ms | 2560 KB |
0_01.txt | AC | 2 ms | 2560 KB |
0_02.txt | AC | 2 ms | 2560 KB |
1_00.txt | AC | 2 ms | 2560 KB |
1_01.txt | AC | 2 ms | 2560 KB |
1_02.txt | AC | 40 ms | 11764 KB |
1_03.txt | AC | 40 ms | 11764 KB |
1_04.txt | AC | 41 ms | 11764 KB |
1_05.txt | AC | 41 ms | 11764 KB |
1_06.txt | AC | 33 ms | 10744 KB |
1_07.txt | AC | 32 ms | 10744 KB |
1_08.txt | AC | 26 ms | 9600 KB |
1_09.txt | AC | 25 ms | 9600 KB |
1_10.txt | AC | 39 ms | 10224 KB |
1_11.txt | AC | 40 ms | 10224 KB |
1_12.txt | AC | 40 ms | 10224 KB |
1_13.txt | AC | 39 ms | 8692 KB |
1_14.txt | AC | 40 ms | 8692 KB |
1_15.txt | AC | 40 ms | 8692 KB |
1_16.txt | AC | 24 ms | 6264 KB |
1_17.txt | AC | 17 ms | 5116 KB |
1_18.txt | AC | 17 ms | 5116 KB |
1_19.txt | AC | 11 ms | 3832 KB |
1_20.txt | AC | 11 ms | 3832 KB |
1_21.txt | AC | 11 ms | 3832 KB |
1_22.txt | AC | 37 ms | 7156 KB |
1_23.txt | WA | 38 ms | 7156 KB |
1_24.txt | WA | 38 ms | 7156 KB |
1_25.txt | AC | 35 ms | 6644 KB |
1_26.txt | WA | 36 ms | 6644 KB |
1_27.txt | WA | 37 ms | 6644 KB |
1_28.txt | AC | 27 ms | 6260 KB |
1_29.txt | WA | 16 ms | 4480 KB |
1_30.txt | AC | 14 ms | 4096 KB |
1_31.txt | WA | 40 ms | 7160 KB |
1_32.txt | AC | 22 ms | 4992 KB |
1_33.txt | AC | 22 ms | 4992 KB |
1_34.txt | AC | 22 ms | 4992 KB |
1_35.txt | WA | 41 ms | 7540 KB |
1_36.txt | AC | 23 ms | 5376 KB |
1_37.txt | AC | 23 ms | 5248 KB |
1_38.txt | AC | 23 ms | 5248 KB |
1_39.txt | WA | 40 ms | 7544 KB |
1_40.txt | WA | 57 ms | 7540 KB |
1_41.txt | AC | 24 ms | 5376 KB |
1_42.txt | AC | 23 ms | 5376 KB |
1_43.txt | WA | 40 ms | 7672 KB |
1_44.txt | WA | 47 ms | 7672 KB |
1_45.txt | TLE | 1056 ms | 7672 KB |
1_46.txt | AC | 23 ms | 5504 KB |
1_47.txt | WA | 40 ms | 8568 KB |
1_48.txt | WA | 42 ms | 8568 KB |
1_49.txt | TLE | 1056 ms | 8568 KB |
1_50.txt | AC | 23 ms | 6400 KB |
1_51.txt | WA | 40 ms | 10996 KB |
1_52.txt | WA | 41 ms | 10996 KB |
1_53.txt | WA | 680 ms | 10996 KB |
1_54.txt | AC | 25 ms | 8832 KB |