#define _CRT_SECURE_NO_WARNINGS
#include "game.h"
#include <iostream>
#include <iomanip>
#include <array>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <iterator>
#include <numeric>
#include <complex>
#include <utility>
#include <random>
#include <fstream>
using namespace std;
/* -------------------- Typedefs -------------------- */
typedef int itn;
typedef long long ll;
typedef unsigned long long ull;
typedef float fl;
typedef double db;
typedef long double ld;
/* -------------------- Usings -------------------- */
using vi = vector<int>;
using vll = vector<ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
/* -------------------- Defines -------------------- */
#define ff first
#define ss second
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mpr make_pair
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define all(x) (x).begin(), (x).end()
/* -------------------- Constants -------------------- */
const int MAX = int(2e9 + 5);
const ll MAXL = ll(1e18 + 5);
const ll MOD = ll(1e9 + 7);
const ll MOD2 = ll(998244353);
//dp1->maximum gagaty voric karas gas, dp2->minimum gagaty vor hasanelia tvyal gagatic
const int max_N = 300005;
int n, k;
vi g[max_N], g_rev[max_N];
int dp1[max_N], dp2[max_N], used[max_N];
vi nodes;
void dfs1(int u) {
nodes.pub(u);
used[u] = 1;
for (auto to : g[u]) {
if (!used[to] && dp1[to] < dp1[u]) {
dp1[to] = dp1[u];
dfs1(to);
}
}
}
void dfs2(int u) {
nodes.pub(u);
used[u] = 1;
for (auto to : g_rev[u]) {
if (!used[to] && dp2[to] > dp2[u]) {
dp2[to] = dp2[u];
dfs2(to);
}
}
}
void init(int N, int K) {
n = N, k = K;
for (int i = 0; i < k - 1; ++i) {
g[i].pub(i + 1);
dp1[i] = dp2[i] = i;
g_rev[i + 1].pub(i);
}
dp1[k - 1] = dp2[k - 1] = k - 1;
for (int i = k; i < n; ++i) {
dp1[i] = -1;
dp2[i] = MAX;
}
}
int add_teleporter(int u, int v) {
if (dp1[u] >= dp2[v]) return 1;
g[u].pub(v);
g_rev[v].pub(u);
nodes.clear();
dfs1(u);
for (auto node : nodes) used[node] = 0;
nodes.clear();
dfs2(v);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
17752 KB |
Output is correct |
2 |
Correct |
6 ms |
17852 KB |
Output is correct |
3 |
Correct |
5 ms |
17752 KB |
Output is correct |
4 |
Correct |
4 ms |
17752 KB |
Output is correct |
5 |
Correct |
5 ms |
17752 KB |
Output is correct |
6 |
Correct |
5 ms |
17752 KB |
Output is correct |
7 |
Correct |
5 ms |
17752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
17752 KB |
Output is correct |
2 |
Correct |
6 ms |
17852 KB |
Output is correct |
3 |
Correct |
5 ms |
17752 KB |
Output is correct |
4 |
Correct |
4 ms |
17752 KB |
Output is correct |
5 |
Correct |
5 ms |
17752 KB |
Output is correct |
6 |
Correct |
5 ms |
17752 KB |
Output is correct |
7 |
Correct |
5 ms |
17752 KB |
Output is correct |
8 |
Correct |
5 ms |
17752 KB |
Output is correct |
9 |
Correct |
4 ms |
17752 KB |
Output is correct |
10 |
Correct |
4 ms |
17752 KB |
Output is correct |
11 |
Correct |
4 ms |
17752 KB |
Output is correct |
12 |
Incorrect |
4 ms |
17752 KB |
Wrong Answer[1] |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
17752 KB |
Output is correct |
2 |
Correct |
6 ms |
17852 KB |
Output is correct |
3 |
Correct |
5 ms |
17752 KB |
Output is correct |
4 |
Correct |
4 ms |
17752 KB |
Output is correct |
5 |
Correct |
5 ms |
17752 KB |
Output is correct |
6 |
Correct |
5 ms |
17752 KB |
Output is correct |
7 |
Correct |
5 ms |
17752 KB |
Output is correct |
8 |
Correct |
5 ms |
17752 KB |
Output is correct |
9 |
Correct |
4 ms |
17752 KB |
Output is correct |
10 |
Correct |
4 ms |
17752 KB |
Output is correct |
11 |
Correct |
4 ms |
17752 KB |
Output is correct |
12 |
Incorrect |
4 ms |
17752 KB |
Wrong Answer[1] |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
17752 KB |
Output is correct |
2 |
Correct |
6 ms |
17852 KB |
Output is correct |
3 |
Correct |
5 ms |
17752 KB |
Output is correct |
4 |
Correct |
4 ms |
17752 KB |
Output is correct |
5 |
Correct |
5 ms |
17752 KB |
Output is correct |
6 |
Correct |
5 ms |
17752 KB |
Output is correct |
7 |
Correct |
5 ms |
17752 KB |
Output is correct |
8 |
Correct |
5 ms |
17752 KB |
Output is correct |
9 |
Correct |
4 ms |
17752 KB |
Output is correct |
10 |
Correct |
4 ms |
17752 KB |
Output is correct |
11 |
Correct |
4 ms |
17752 KB |
Output is correct |
12 |
Incorrect |
4 ms |
17752 KB |
Wrong Answer[1] |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
17752 KB |
Output is correct |
2 |
Correct |
6 ms |
17852 KB |
Output is correct |
3 |
Correct |
5 ms |
17752 KB |
Output is correct |
4 |
Correct |
4 ms |
17752 KB |
Output is correct |
5 |
Correct |
5 ms |
17752 KB |
Output is correct |
6 |
Correct |
5 ms |
17752 KB |
Output is correct |
7 |
Correct |
5 ms |
17752 KB |
Output is correct |
8 |
Correct |
5 ms |
17752 KB |
Output is correct |
9 |
Correct |
4 ms |
17752 KB |
Output is correct |
10 |
Correct |
4 ms |
17752 KB |
Output is correct |
11 |
Correct |
4 ms |
17752 KB |
Output is correct |
12 |
Incorrect |
4 ms |
17752 KB |
Wrong Answer[1] |
13 |
Halted |
0 ms |
0 KB |
- |