Submission #866215
Source Code Expand
#include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
// #define iter(a) __typeof(a.begin())
#define FOR(it, a) for (auto it = a.begin(); it != a.end(); ++it)
#define F first
#define S second
#define SZ(a) static_cast<int>((a).size())
#define sz(a) SZ(a)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef int64_t ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef uint64_t ull;
#ifdef ONLINE_JUDGE
#define PR(...) (void(0))
#else
#define PR(...) \
do { cerr << "line : " << __LINE__ << ", " << endl; \
pr(#__VA_ARGS__, __VA_ARGS__); } while (0)
template<class T>
void pr(const string& name, T t) {
cerr << name << ": " << t << endl;
}
template<typename T, typename ... Types>
void pr(const string& names, T t, Types ... rest) {
auto p = names.find(',');
cerr << names.substr(0, p) << ": " << t << ", ";
pr(string(names, p + 1), rest ...);
}
#endif
template<class T, class U> ostream& operator<<(
ostream& o, const pair<T, U>& v) {
return o << "(" << v.F << ", " << v.S << ")";
}
template<class T> ostream& operator<<(
ostream& o, const vector<T>& v) {
o << "{"; rep(i, SZ(v)) o << (i?", ":"") << v[i]; return o << "}"; }
template<class T, class U> ostream& operator<<(
ostream& o, const map<T, U>& v) {
o << "{"; for (const auto& e : v) o << e << ", "; return o << "}"; }
template<class T, class U> ostream& operator<<(
ostream& o, const unordered_map<T, U>& v) {
o << "{"; for (const auto& e : v) o << e << ", "; return o << "}"; }
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
o << "{"; for (const auto& e : v) o << e << ", "; return o << "}"; }
template<class T> string to_s(const T& v) {
ostringstream is; is << v; return is.str(); }
const int dx[]={0, 1, 0, -1, 1, 1, -1, -1, 0};
const int dy[]={1, 0, -1, 0, -1, 1, 1, -1, 0};
#define endl '\n'
vector<int> G[100000+100];
int main(int argc, char *argv[])
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
int ans = 0;
rep(i, n){
int a;
cin >> a;
if(i == 0){
ans += a != 1;
continue;
}
G[a].pb(i + 1);
}
vector<int> q;
q.pb(1);
while(true){
rep(i, k){
vector<int> nq;
for(auto v : q){
for(auto ne : G[v])
nq.pb(ne);
}
q = nq;
}
if(q.empty()) break;
for(auto a : q)
ans += SZ(G[a]);
}
cout << ans << endl;
}
Submission Info
Submission Time |
|
Task |
D - Teleporter |
User |
atetubou |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2844 Byte |
Status |
WA |
Exec Time |
1057 ms |
Memory |
5760 KB |
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 |
7 ms |
2560 KB |
0_01.txt |
AC |
7 ms |
2560 KB |
0_02.txt |
AC |
7 ms |
2560 KB |
1_00.txt |
AC |
7 ms |
2560 KB |
1_01.txt |
AC |
7 ms |
2560 KB |
1_02.txt |
AC |
47 ms |
5760 KB |
1_03.txt |
AC |
47 ms |
5760 KB |
1_04.txt |
AC |
47 ms |
5760 KB |
1_05.txt |
AC |
47 ms |
5760 KB |
1_06.txt |
AC |
46 ms |
5760 KB |
1_07.txt |
AC |
47 ms |
5760 KB |
1_08.txt |
AC |
47 ms |
5760 KB |
1_09.txt |
AC |
47 ms |
5760 KB |
1_10.txt |
AC |
46 ms |
5760 KB |
1_11.txt |
AC |
50 ms |
5760 KB |
1_12.txt |
AC |
47 ms |
5760 KB |
1_13.txt |
AC |
39 ms |
5760 KB |
1_14.txt |
AC |
38 ms |
5760 KB |
1_15.txt |
AC |
40 ms |
5760 KB |
1_16.txt |
AC |
31 ms |
5048 KB |
1_17.txt |
AC |
31 ms |
5048 KB |
1_18.txt |
AC |
34 ms |
5048 KB |
1_19.txt |
AC |
21 ms |
3960 KB |
1_20.txt |
AC |
21 ms |
3960 KB |
1_21.txt |
AC |
21 ms |
3960 KB |
1_22.txt |
AC |
38 ms |
4656 KB |
1_23.txt |
WA |
39 ms |
4656 KB |
1_24.txt |
WA |
38 ms |
4656 KB |
1_25.txt |
AC |
38 ms |
4344 KB |
1_26.txt |
WA |
38 ms |
4344 KB |
1_27.txt |
WA |
37 ms |
4344 KB |
1_28.txt |
AC |
26 ms |
4224 KB |
1_29.txt |
WA |
26 ms |
4224 KB |
1_30.txt |
AC |
26 ms |
4216 KB |
1_31.txt |
WA |
39 ms |
4480 KB |
1_32.txt |
AC |
39 ms |
4352 KB |
1_33.txt |
AC |
39 ms |
4476 KB |
1_34.txt |
TLE |
1057 ms |
4476 KB |
1_35.txt |
WA |
39 ms |
4608 KB |
1_36.txt |
AC |
39 ms |
4608 KB |
1_37.txt |
AC |
39 ms |
4608 KB |
1_38.txt |
TLE |
1053 ms |
4608 KB |
1_39.txt |
WA |
39 ms |
4608 KB |
1_40.txt |
WA |
40 ms |
4608 KB |
1_41.txt |
AC |
39 ms |
4608 KB |
1_42.txt |
TLE |
1053 ms |
4608 KB |
1_43.txt |
WA |
41 ms |
4608 KB |
1_44.txt |
WA |
41 ms |
4608 KB |
1_45.txt |
WA |
41 ms |
4608 KB |
1_46.txt |
AC |
470 ms |
4608 KB |
1_47.txt |
WA |
45 ms |
4736 KB |
1_48.txt |
WA |
45 ms |
4736 KB |
1_49.txt |
WA |
45 ms |
4736 KB |
1_50.txt |
TLE |
1053 ms |
4736 KB |
1_51.txt |
WA |
47 ms |
5376 KB |
1_52.txt |
WA |
47 ms |
5376 KB |
1_53.txt |
WA |
47 ms |
5376 KB |
1_54.txt |
AC |
549 ms |
5376 KB |