problem_id stringlengths 6 6 | language stringclasses 2 values | original_status stringclasses 3 values | original_src stringlengths 19 243k | changed_src stringlengths 19 243k | change stringclasses 3 values | i1 int64 0 8.44k | i2 int64 0 8.44k | j1 int64 0 8.44k | j2 int64 0 8.44k | error stringclasses 270 values | stderr stringlengths 0 226k |
|---|---|---|---|---|---|---|---|---|---|---|---|
p03088 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr Int mod = 1e9 + 7;
string str{"AGCT"};
#define rep(i, n) for (int i = 0; i < n; ++i)
int main() {
Int N;
cin >> N;
Int dp[101][5][5] = {0};
for (int i = 0; i < N; ++i) {
for (int j = 0; j < str.size(); ++j) {
for (int k = 0; k < str.size(); ++k) {
char prev = str[k];
char lst = str[j];
dp[i][j][k] %= mod;
if (i == 0 and (j == 4 or k == 4))
continue;
Int now = (i ? dp[i][j][k] : 1);
if (now == 0)
continue;
if (lst == 'A' and prev == 'C') {
rep(l, 4) if (str[l] != 'G') dp[i + 1][k][l] += now;
} else if (lst == 'A' and prev == 'G') {
rep(l, 4) rep(m, 4) {
if (str[m] == 'C' or str[l] == 'C')
continue;
dp[i + 2][m][l] += now;
}
dp[i + 1][k][4] += now;
} else if (lst == 'G' and prev == 'A') {
rep(l, 4) if (str[l] != 'C') dp[i + 1][k][l] += now;
} else if (lst == 'A' and prev == 'T') {
rep(l, 4) rep(m, 4) {
if (str[l] == 'G' and str[m] == 'C')
continue;
dp[i + 2][l][m] += now;
}
dp[i + 1][3][4] += now;
} else {
rep(l, 4) dp[i + 1][k][l] += now;
}
}
}
}
Int ans = 0;
for (int j = 0; j < 4; ++j)
for (int k = 0; k < 4; ++k) {
ans += dp[N - 2][j][k];
ans %= mod;
}
ans += dp[N - 2][1][4] * 3;
ans += dp[N - 2][3][4] * 4;
ans %= mod;
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr Int mod = 1e9 + 7;
string str{"AGCT"};
#define rep(i, n) for (int i = 0; i < n; ++i)
int main() {
Int N;
cin >> N;
Int dp[106][5][5] = {0};
for (int i = 0; i < N; ++i) {
for (int j = 0; j < str.size(); ++j) {
for (int k = 0; k < str.size(); ++k) {
char prev = str[k];
char lst = str[j];
dp[i][j][k] %= mod;
if (i == 0 and (j == 4 or k == 4))
continue;
Int now = (i ? dp[i][j][k] : 1);
if (now == 0)
continue;
if (lst == 'A' and prev == 'C') {
rep(l, 4) if (str[l] != 'G') dp[i + 1][k][l] += now;
} else if (lst == 'A' and prev == 'G') {
rep(l, 4) rep(m, 4) {
if (str[m] == 'C' or str[l] == 'C')
continue;
dp[i + 2][m][l] += now;
}
dp[i + 1][k][4] += now;
} else if (lst == 'G' and prev == 'A') {
rep(l, 4) if (str[l] != 'C') dp[i + 1][k][l] += now;
} else if (lst == 'A' and prev == 'T') {
rep(l, 4) rep(m, 4) {
if (str[l] == 'G' and str[m] == 'C')
continue;
dp[i + 2][l][m] += now;
}
dp[i + 1][3][4] += now;
} else {
rep(l, 4) dp[i + 1][k][l] += now;
}
}
}
}
Int ans = 0;
for (int j = 0; j < 4; ++j)
for (int k = 0; k < 4; ++k) {
ans += dp[N - 2][j][k];
ans %= mod;
}
ans += dp[N - 2][1][4] * 3;
ans += dp[N - 2][3][4] * 4;
ans %= mod;
cout << ans << endl;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p03088 | C++ | Runtime Error | #define _GLIBCXX_DEBUG
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iterator>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, (n)-1)
typedef long long ll;
#define mod 1000000007
ll madd(ll a, ll b) { return (a + b) % mod; }
ll msub(ll a, ll b) { return (a + mod - b) % mod; }
ll mmul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll mpow(ll a, ll b) {
if (b == 0)
return 1;
else if (b == 1)
return a % mod;
else if (b % 2 == 0) {
ll hlf = mpow(a, b / 2);
return (hlf * hlf) % mod;
} else {
ll hlf = mpow(a, b / 2);
return (mmul(hlf, hlf) * a) % mod;
}
}
ll mdiv(ll a, ll b) { return mmul(a, mpow(b, mod - 2)); }
// AGC ... 021
bool isAGC(int a, int b, int c, int d) {
if (a == 0 && b == 2 && c == 1)
return true;
if (b == 0 && c == 2 && d == 1)
return true;
return false;
}
// A 0 C 1 G 2 T 3
bool islegal(int a, int b, int c, int d) {
if (isAGC(a, b, c, d))
return false;
if (isAGC(b, a, c, d))
return false;
if (isAGC(a, c, b, d))
return false;
if (isAGC(a, b, d, c))
return false;
return true;
}
ll ans[101][256];
int main() {
int N;
cin >> N;
if (N == 3) {
cout << "61" << endl;
return 0;
}
if (N == 4) {
cout << "230" << endl;
return 0;
}
// tmpの初期化
rep(i, 256) {
int a, b, c, d;
a = i / 64;
b = (i - a * 64) / 16;
c = (i - a * 64 - b * 16) / 4;
d = (i - a * 64 - b * 16 - c * 4);
if (islegal(a, b, c, d))
ans[4][i] = 1;
else
ans[4][i] = 0;
}
FOR(j, 5, N + 1) {
rep(i, 256) {
int a, b, c, d;
a = i / 64;
b = (i - a * 64) / 16;
c = (i - a * 64 - b * 16) / 4;
d = (i - a * 64 - b * 16 - c * 4);
ans[j][i] = 0;
if (ans[4][a * 64 + b * 16 + c * 4 + d] == 1) {
rep(k, 4) {
ans[j][i] = madd(ans[j][i], ans[j - 1][k * 64 + a * 16 + b * 4 + c]);
}
}
}
}
ll ans2 = 0;
rep(i, 256) ans2 = madd(ans2, ans[N][i]);
cout << ans2 << endl;
return 0;
} | #define _GLIBCXX_DEBUG
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iterator>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, (n)-1)
typedef long long ll;
#define mod 1000000007
ll madd(ll a, ll b) { return (a + b) % mod; }
ll msub(ll a, ll b) { return (a + mod - b) % mod; }
ll mmul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll mpow(ll a, ll b) {
if (b == 0)
return 1;
else if (b == 1)
return a % mod;
else if (b % 2 == 0) {
ll hlf = mpow(a, b / 2);
return (hlf * hlf) % mod;
} else {
ll hlf = mpow(a, b / 2);
return (mmul(hlf, hlf) * a) % mod;
}
}
ll mdiv(ll a, ll b) { return mmul(a, mpow(b, mod - 2)); }
// AGC ... 021
bool isAGC(int a, int b, int c, int d) {
if (a == 0 && b == 2 && c == 1)
return true;
if (b == 0 && c == 2 && d == 1)
return true;
return false;
}
// A 0 C 1 G 2 T 3
bool islegal(int a, int b, int c, int d) {
if (isAGC(a, b, c, d))
return false;
if (isAGC(b, a, c, d))
return false;
if (isAGC(a, c, b, d))
return false;
if (isAGC(a, b, d, c))
return false;
return true;
}
ll ans[103][256];
int main() {
int N;
cin >> N;
if (N == 3) {
cout << "61" << endl;
return 0;
}
if (N == 4) {
cout << "230" << endl;
return 0;
}
// tmpの初期化
rep(i, 256) {
int a, b, c, d;
a = i / 64;
b = (i - a * 64) / 16;
c = (i - a * 64 - b * 16) / 4;
d = (i - a * 64 - b * 16 - c * 4);
if (islegal(a, b, c, d))
ans[4][i] = 1;
else
ans[4][i] = 0;
}
FOR(j, 5, N + 1) {
rep(i, 256) {
int a, b, c, d;
a = i / 64;
b = (i - a * 64) / 16;
c = (i - a * 64 - b * 16) / 4;
d = (i - a * 64 - b * 16 - c * 4);
ans[j][i] = 0;
if (ans[4][a * 64 + b * 16 + c * 4 + d] == 1) {
rep(k, 4) {
ans[j][i] = madd(ans[j][i], ans[j - 1][k * 64 + a * 16 + b * 4 + c]);
}
}
}
}
ll ans2 = 0;
rep(i, 256) ans2 = madd(ans2, ans[N][i]);
cout << ans2 << endl;
return 0;
} | replace | 59 | 60 | 59 | 60 | 0 | |
p03088 | C++ | Time Limit Exceeded | #include <iostream>
#include <string.h>
using namespace std;
#define MAX_LENGTH 100
#define MOD 1000000007
int N;
long long memo[110][6][6][6][6];
// A = 0, C = 1, G = 2, T = 3
long long count(int cur, int c3, int c2, int c1, int input) {
// ?AGC
if (c2 == 0 && c1 == 2 && input == 1) {
return 0;
// AG?C
} else if (c3 == 0 && c2 == 2 && input == 1) {
return 0;
// ?GAC
} else if (c2 == 2 && c1 == 0 && input == 1) {
return 0;
// ?ACG
} else if (c2 == 0 && c1 == 1 && input == 2) {
return 0;
// A?GC
} else if (c3 == 0 && c1 == 2 && input == 1) {
return 0;
}
if (cur == N) {
return 1;
}
long long ans = 0;
for (int i = 0; i < 4; i++) {
ans += count(cur + 1, c2, c1, input, i);
}
memo[cur][c3][c2][c1][input] = ans % MOD;
return memo[cur][c3][c2][c1][input];
}
int main() {
memset(memo, -1, sizeof(memo));
cin >> N;
cout << count(0, 3, 3, 3, 3) << endl;
return 0;
} | #include <iostream>
#include <string.h>
using namespace std;
#define MAX_LENGTH 100
#define MOD 1000000007
int N;
long long memo[110][6][6][6][6];
// A = 0, C = 1, G = 2, T = 3
long long count(int cur, int c3, int c2, int c1, int input) {
if (memo[cur][c3][c2][c1][input] != -1) {
return memo[cur][c3][c2][c1][input];
}
// ?AGC
if (c2 == 0 && c1 == 2 && input == 1) {
return 0;
// AG?C
} else if (c3 == 0 && c2 == 2 && input == 1) {
return 0;
// ?GAC
} else if (c2 == 2 && c1 == 0 && input == 1) {
return 0;
// ?ACG
} else if (c2 == 0 && c1 == 1 && input == 2) {
return 0;
// A?GC
} else if (c3 == 0 && c1 == 2 && input == 1) {
return 0;
}
if (cur == N) {
return 1;
}
long long ans = 0;
for (int i = 0; i < 4; i++) {
ans += count(cur + 1, c2, c1, input, i);
}
memo[cur][c3][c2][c1][input] = ans % MOD;
return memo[cur][c3][c2][c1][input];
}
int main() {
memset(memo, -1, sizeof(memo));
cin >> N;
cout << count(0, 3, 3, 3, 3) << endl;
return 0;
}
| insert | 13 | 13 | 13 | 17 | TLE | |
p03088 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()
// #pragma GCC optimize ("-O3")
using namespace std;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
//---------------------------------------------------------------------------------------------------
template <int MOD> struct ModInt {
static const int Mod = MOD;
unsigned x;
ModInt() : x(0) {}
ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
int get() const { return (int)x; }
ModInt &operator+=(ModInt that) {
if ((x += that.x) >= MOD)
x -= MOD;
return *this;
}
ModInt &operator-=(ModInt that) {
if ((x += MOD - that.x) >= MOD)
x -= MOD;
return *this;
}
ModInt &operator*=(ModInt that) {
x = (unsigned long long)x * that.x % MOD;
return *this;
}
ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
ModInt inverse() const {
long long a = x, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
std::swap(a, b);
u -= t * v;
std::swap(u, v);
}
return ModInt(u);
}
bool operator==(ModInt that) const { return x == that.x; }
bool operator!=(ModInt that) const { return x != that.x; }
ModInt operator-() const {
ModInt t;
t.x = x == 0 ? 0 : Mod - x;
return t;
}
};
template <int MOD> ostream &operator<<(ostream &st, const ModInt<MOD> a) {
st << a.get();
return st;
};
template <int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
ModInt<MOD> r = 1;
while (k) {
if (k & 1)
r *= a;
a *= a;
k >>= 1;
}
return r;
}
typedef ModInt<1000000007> mint;
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N;
string S = "ACGT";
//---------------------------------------------------------------------------------------------------
bool contain(string s) {
int n = s.length();
if (n <= 2)
return false;
rep(i, 0, n - 2) {
string t = s.substr(i, 3);
if (t == "AGC")
return true;
}
return false;
}
string add(string s, char c) {
string res = s + c;
int n = res.length();
if (n <= 2)
return res;
if (contain(res))
return "";
rep(i, 0, n - 1) {
string tes = res;
swap(tes[i], tes[i + 1]);
if (contain(tes))
return "";
}
return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N;
map<string, mint> dp;
dp[""] = 1;
rep(i, 0, N) {
map<string, mint> pd;
fore(p, dp) {
fore(c, S) {
string nxt = add(p.first, c);
if (nxt != "")
pd[nxt] += p.second;
}
}
swap(dp, pd);
}
mint ans = 0;
fore(p, dp) ans += p.second;
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()
// #pragma GCC optimize ("-O3")
using namespace std;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
//---------------------------------------------------------------------------------------------------
template <int MOD> struct ModInt {
static const int Mod = MOD;
unsigned x;
ModInt() : x(0) {}
ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
int get() const { return (int)x; }
ModInt &operator+=(ModInt that) {
if ((x += that.x) >= MOD)
x -= MOD;
return *this;
}
ModInt &operator-=(ModInt that) {
if ((x += MOD - that.x) >= MOD)
x -= MOD;
return *this;
}
ModInt &operator*=(ModInt that) {
x = (unsigned long long)x * that.x % MOD;
return *this;
}
ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
ModInt inverse() const {
long long a = x, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
std::swap(a, b);
u -= t * v;
std::swap(u, v);
}
return ModInt(u);
}
bool operator==(ModInt that) const { return x == that.x; }
bool operator!=(ModInt that) const { return x != that.x; }
ModInt operator-() const {
ModInt t;
t.x = x == 0 ? 0 : Mod - x;
return t;
}
};
template <int MOD> ostream &operator<<(ostream &st, const ModInt<MOD> a) {
st << a.get();
return st;
};
template <int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
ModInt<MOD> r = 1;
while (k) {
if (k & 1)
r *= a;
a *= a;
k >>= 1;
}
return r;
}
typedef ModInt<1000000007> mint;
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N;
string S = "ACGT";
//---------------------------------------------------------------------------------------------------
bool contain(string s) {
int n = s.length();
if (n <= 2)
return false;
rep(i, 0, n - 2) {
string t = s.substr(i, 3);
if (t == "AGC")
return true;
}
return false;
}
string add(string s, char c) {
string res = s + c;
int n = res.length();
if (n <= 2)
return res;
if (contain(res))
return "";
rep(i, 0, n - 1) {
string tes = res;
swap(tes[i], tes[i + 1]);
if (contain(tes))
return "";
}
if (4 <= n)
res = res.substr(n - 3);
return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N;
map<string, mint> dp;
dp[""] = 1;
rep(i, 0, N) {
map<string, mint> pd;
fore(p, dp) {
fore(c, S) {
string nxt = add(p.first, c);
if (nxt != "")
pd[nxt] += p.second;
}
}
swap(dp, pd);
}
mint ans = 0;
fore(p, dp) ans += p.second;
cout << ans << endl;
} | insert | 134 | 134 | 134 | 137 | TLE | |
p03088 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return
// true; } return false; } template<class T> inline bool chmin(T& a, T b) { if
// (a > b) { a = b; return true; } return false; }
// long longのシフト演算には気をつけよう
int dp[101][4][4][4];
int main() {
int N;
cin >> N;
int mod = 1000000007;
dp[0][3][3][3] = 1;
for (int len = 0; len < N; len++) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
if (dp[len][i][j][k] == 0)
continue;
for (int a = 0; a < 4; i++) {
if (j == 0 && k == 1 && a == 2)
continue;
if (j == 1 && k == 0 && a == 2)
continue;
if (j == 0 && k == 2 && a == 1)
continue;
if (i == 0 && k == 1 && a == 2)
continue;
if (i == 0 && j == 1 && a == 2)
continue;
dp[len + 1][j][k][a] += dp[len][i][j][k];
dp[len + 1][j][k][a] %= mod;
}
}
}
}
}
int ans = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
ans += dp[N][i][j][k];
ans %= mod;
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return
// true; } return false; } template<class T> inline bool chmin(T& a, T b) { if
// (a > b) { a = b; return true; } return false; }
// long longのシフト演算には気をつけよう
int dp[101][4][4][4];
int main() {
int N;
cin >> N;
int mod = 1000000007;
dp[0][3][3][3] = 1;
for (int len = 0; len < N; len++) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
if (dp[len][i][j][k] == 0)
continue;
for (int a = 0; a < 4; a++) {
if (j == 0 && k == 1 && a == 2)
continue;
if (j == 1 && k == 0 && a == 2)
continue;
if (j == 0 && k == 2 && a == 1)
continue;
if (i == 0 && k == 1 && a == 2)
continue;
if (i == 0 && j == 1 && a == 2)
continue;
dp[len + 1][j][k][a] += dp[len][i][j][k];
dp[len + 1][j][k][a] %= mod;
}
}
}
}
}
int ans = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
ans += dp[N][i][j][k];
ans %= mod;
}
}
}
cout << ans << endl;
} | replace | 25 | 26 | 25 | 26 | -11 | |
p03088 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i, n) for (ll i = 0; i < n; i++)
ll gcd(ll a, ll b) {
if (a < b)
swap(a, b);
while (b > 0) {
ll p = a % b;
a = b;
b = p;
}
return a;
}
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return (a / g) * b;
}
int main() {
ll n;
cin >> n;
vector<vector<vector<vector<ll>>>> dp(
n + 1,
vector<vector<vector<ll>>>(4, vector<vector<ll>>(4, vector<ll>(4, 0))));
rep(j, 4) {
rep(k, 4) {
rep(l, 4) {
if (!((j == 0 && k == 1 && l == 2) || (j == 0 && k == 2 && l == 1) ||
(j == 1 && k == 0 && l == 2))) {
dp[3][j][k][l] = 1;
}
}
}
}
for (int i = 4; i < n + 1; i++) {
rep(j, 4) {
rep(k, 4) {
rep(l, 4) {
rep(m, 4) {
if (!((j == 0 && k == 1 && m == 2) ||
(j == 0 && l == 1 && m == 2) ||
(k == 0 && l == 1 && m == 2) ||
(k == 0 && l == 2 && m == 1) ||
(k == 1 && l == 0 && m == 2))) {
dp[i + 1][k][l][m] += dp[i][j][k][l];
dp[i + 1][k][l][m] %= mod;
}
}
}
}
}
}
ll sum = 0;
rep(j, 4) {
rep(k, 4) {
rep(l, 4) {
sum += dp[n][j][k][l];
sum %= mod;
}
}
}
cout << sum << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i, n) for (ll i = 0; i < n; i++)
ll gcd(ll a, ll b) {
if (a < b)
swap(a, b);
while (b > 0) {
ll p = a % b;
a = b;
b = p;
}
return a;
}
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return (a / g) * b;
}
int main() {
ll n;
cin >> n;
vector<vector<vector<vector<ll>>>> dp(
n + 1,
vector<vector<vector<ll>>>(4, vector<vector<ll>>(4, vector<ll>(4, 0))));
rep(j, 4) {
rep(k, 4) {
rep(l, 4) {
if (!((j == 0 && k == 1 && l == 2) || (j == 0 && k == 2 && l == 1) ||
(j == 1 && k == 0 && l == 2))) {
dp[3][j][k][l] = 1;
}
}
}
}
for (int i = 3; i < n; i++) {
rep(j, 4) {
rep(k, 4) {
rep(l, 4) {
rep(m, 4) {
if (!((j == 0 && k == 1 && m == 2) ||
(j == 0 && l == 1 && m == 2) ||
(k == 0 && l == 1 && m == 2) ||
(k == 0 && l == 2 && m == 1) ||
(k == 1 && l == 0 && m == 2))) {
dp[i + 1][k][l][m] += dp[i][j][k][l];
dp[i + 1][k][l][m] %= mod;
}
}
}
}
}
}
ll sum = 0;
rep(j, 4) {
rep(k, 4) {
rep(l, 4) {
sum += dp[n][j][k][l];
sum %= mod;
}
}
}
cout << sum << endl;
} | replace | 35 | 36 | 35 | 36 | 0 | |
p03089 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
static std::vector<int> as;
static std::vector<int> bs;
static int n;
bool solve(int z) {
if (z <= 0) {
return true;
}
int i = z - 1;
int j = n - 1;
for (; i >= 0; --i, --j) {
while (bs[j] < 0) {
--j;
}
if (bs[j] != i) {
continue;
}
bs[j] = -1;
if (solve(z - 1)) {
as[z - 1] = i + 1;
return true;
}
bs[j] = i;
}
return false;
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
std::cin >> n;
bs.resize(n);
for (int i = 0; i < n; ++i) {
int b;
std::cin >> b;
bs[i] = b - 1;
}
as.resize(n);
auto const found = solve(n);
if (!found) {
std::cout << -1 << std::endl;
return 0;
}
for (auto const a : as) {
std::cout << a << std::endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
static std::vector<int> as;
static std::vector<int> bs;
static int n;
bool solve(int z) {
if (z <= 0) {
return true;
}
int i = z - 1;
int j = n - 1;
for (; i >= 0; --i, --j) {
while (bs[j] < 0) {
--j;
}
if (bs[j] > i) {
return false;
}
}
i = z - 1;
j = n - 1;
for (; i >= 0; --i, --j) {
while (bs[j] < 0) {
--j;
}
if (bs[j] != i) {
continue;
}
bs[j] = -1;
if (solve(z - 1)) {
as[z - 1] = i + 1;
return true;
}
bs[j] = i;
}
return false;
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
std::cin >> n;
bs.resize(n);
for (int i = 0; i < n; ++i) {
int b;
std::cin >> b;
bs[i] = b - 1;
}
as.resize(n);
auto const found = solve(n);
if (!found) {
std::cout << -1 << std::endl;
return 0;
}
for (auto const a : as) {
std::cout << a << std::endl;
}
return 0;
}
| insert | 14 | 14 | 14 | 24 | TLE | |
p03089 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int n, a;
vector<int> b, ans;
int main(void) {
// Your code here!
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a;
b.push_back(a);
}
while (b.size() != 0) {
bool jud = false;
for (int i = b.size() - 1; i >= 0; i--) {
if (b[i] == i + 1) {
ans.push_back(b[i]);
b.erase(b.begin() + i);
jud = true;
break;
}
}
if (!jud) {
cout << -1 << endl;
return 1;
}
}
for (int i = ans.size() - 1; i >= 0; i--) {
cout << ans[i] << endl;
}
}
| #include <iostream>
#include <vector>
using namespace std;
int n, a;
vector<int> b, ans;
int main(void) {
// Your code here!
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a;
b.push_back(a);
}
while (b.size() != 0) {
bool jud = false;
for (int i = b.size() - 1; i >= 0; i--) {
if (b[i] == i + 1) {
ans.push_back(b[i]);
b.erase(b.begin() + i);
jud = true;
break;
}
}
if (!jud) {
cout << -1 << endl;
return 0;
}
}
for (int i = ans.size() - 1; i >= 0; i--) {
cout << ans[i] << endl;
}
}
| replace | 24 | 25 | 24 | 25 | 0 | |
p03089 | C++ | Time Limit Exceeded | #include <algorithm>
#include <complex>
#include <ctype.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout << (s) << endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
const ll mod = 1e9 + 7;
const ll inf = 1e18;
template <typename T> void vprint(T &V) {
for (auto v : V) {
cout << v << " ";
}
cout << endl;
}
// vectorからindex番目の要素を削除する
template <typename T> vector<T> remove(vector<T> A, ll index) {
A.erase(A.begin() + index);
return A;
}
vector<ll> dfs(ll N, vector<ll> A) {
vector<ll> ret;
if (N == 1) {
if (A[0] == 1) {
ret.push_back(1);
return ret;
} else {
return ret;
}
}
for (int i = N - 1; i >= 0; i--) {
if (A[i] == i + 1) {
auto list = dfs(N - 1, remove(A, i));
if (list.size() > 0) {
list.push_back(A[i]);
return list;
}
}
}
// fail
return ret;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// input
ll N;
cin >> N;
vector<ll> A(N);
FOR(i, 0, N) { cin >> A.at(i); }
auto list = dfs(N, A);
if (list.size() == 0) {
p(-1);
} else {
for (ll a : list) {
p(a);
}
}
return 0;
}
| #include <algorithm>
#include <complex>
#include <ctype.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout << (s) << endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
const ll mod = 1e9 + 7;
const ll inf = 1e18;
template <typename T> void vprint(T &V) {
for (auto v : V) {
cout << v << " ";
}
cout << endl;
}
// vectorからindex番目の要素を削除する
template <typename T> vector<T> remove(vector<T> A, ll index) {
A.erase(A.begin() + index);
return A;
}
vector<ll> dfs(ll N, vector<ll> A) {
vector<ll> ret;
if (N == 1) {
if (A[0] == 1) {
ret.push_back(1);
return ret;
} else {
return ret;
}
}
for (int i = N - 1; i >= 0; i--) {
if (A[i] == i + 1) {
auto list = dfs(N - 1, remove(A, i));
if (list.size() > 0) {
list.push_back(A[i]);
return list;
} else {
return ret;
}
}
}
// fail
return ret;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// input
ll N;
cin >> N;
vector<ll> A(N);
FOR(i, 0, N) { cin >> A.at(i); }
auto list = dfs(N, A);
if (list.size() == 0) {
p(-1);
} else {
for (ll a : list) {
p(a);
}
}
return 0;
}
| insert | 61 | 61 | 61 | 63 | TLE | |
p03089 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int search(int N, vector<int> b) {
for (int i = N; i >= 1; i--) {
if (b[i - 1] > i)
return -1;
if (b[i - 1] == i)
return i;
}
}
int main() {
int N;
cin >> N;
vector<int> b(N);
for (int i = 0; i < N; i++)
cin >> b[i];
vector<int> ans(N, 0);
for (int size = N; size >= 1; size--) {
int pos = search(size, b);
if (pos == -1) {
cout << -1 << endl;
return 1;
} else {
ans[size - 1] = pos;
b.erase(b.begin() + pos - 1);
}
}
for (int i = 0; i < N; i++) {
cout << ans[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int search(int N, vector<int> b) {
for (int i = N; i >= 1; i--) {
if (b[i - 1] > i)
return -1;
if (b[i - 1] == i)
return i;
}
}
int main() {
int N;
cin >> N;
vector<int> b(N);
for (int i = 0; i < N; i++)
cin >> b[i];
vector<int> ans(N, 0);
for (int size = N; size >= 1; size--) {
int pos = search(size, b);
if (pos == -1) {
cout << -1 << endl;
return 0;
} else {
ans[size - 1] = pos;
b.erase(b.begin() + pos - 1);
}
}
for (int i = 0; i < N; i++) {
cout << ans[i] << endl;
}
return 0;
} | replace | 26 | 27 | 26 | 27 | 0 | |
p03089 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n) \
{ \
REP(WW, n) cerr << v[WW] << ' '; \
cerr << endl << endl; \
}
#define SHOW2d(v, WW, HH) \
{ \
REP(W_, WW) { \
REP(H_, HH) cerr << v[W_][H_] << ' '; \
cerr << endl; \
} \
cerr << endl; \
}
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353
#define fastcin() \
cin.tie(0); \
ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll, ll> P;
int n;
int mp[111];
void out() {
REV(i, n) cout << mp[i] << endl;
exit(0);
}
void dfs(vector<int> &v, int dep) {
if (v.size() == 0) {
out();
}
REP(i, v.size()) {
if (v[i] == i + 1) {
mp[dep] = i + 1;
auto tmp = v;
tmp.erase(tmp.begin() + i);
dfs(tmp, dep + 1);
}
if (v[i] > i + 1)
return;
}
}
int main() {
cin >> n;
vector<int> v(n);
REP(i, n) cin >> v[i];
dfs(v, 0);
cout << -1 << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n) \
{ \
REP(WW, n) cerr << v[WW] << ' '; \
cerr << endl << endl; \
}
#define SHOW2d(v, WW, HH) \
{ \
REP(W_, WW) { \
REP(H_, HH) cerr << v[W_][H_] << ' '; \
cerr << endl; \
} \
cerr << endl; \
}
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353
#define fastcin() \
cin.tie(0); \
ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll, ll> P;
int n;
int mp[111];
void out() {
REV(i, n) cout << mp[i] << endl;
exit(0);
}
void dfs(vector<int> &v, int dep) {
if (v.size() == 0) {
out();
}
REV(i, v.size()) {
if (v[i] == i + 1) {
mp[dep] = i + 1;
auto tmp = v;
tmp.erase(tmp.begin() + i);
dfs(tmp, dep + 1);
}
if (v[i] > i + 1)
return;
}
}
int main() {
cin >> n;
vector<int> v(n);
REP(i, n) cin >> v[i];
dfs(v, 0);
cout << -1 << endl;
return 0;
}
| replace | 48 | 49 | 48 | 49 | TLE | |
p03089 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stdio.h>
#include <vector>
#define FORi(N) for (int i = 0; i < N; ++i)
#define FORj(N) for (int j = 0; j < N; ++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m, ll n) {
if (n == 0)
return abs(m);
return (gcd(n, m % n));
}
void putYN(bool b) {
if (b) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
vector<ll> dp(vector<ll> &b, ll n) { // n以下をとる
if (b.size() == 0)
return vector<ll>();
vector<ll> c, ret, d;
for (int i = n - 1; i >= 0; --i) {
if (b[i] == i + 1) {
c = b;
c.erase(c.begin() + i);
ret = dp(c, n - 1);
if (ret.size() == 1 && ret[0] == -1)
continue;
ret.push_back(i + 1);
return ret;
}
}
ret = vector<ll>{-1};
return ret;
}
int main() {
ll N;
cin >> N;
vector<ll> b(N);
FORi(N) { cin >> b[i]; }
vector<ll> ret = dp(b, N);
FORi(ret.size()) { cout << ret[i] << endl; }
return 0;
}
| #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stdio.h>
#include <vector>
#define FORi(N) for (int i = 0; i < N; ++i)
#define FORj(N) for (int j = 0; j < N; ++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m, ll n) {
if (n == 0)
return abs(m);
return (gcd(n, m % n));
}
void putYN(bool b) {
if (b) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
vector<ll> dp(vector<ll> &b, ll n) { // n以下をとる
if (b.size() == 0)
return vector<ll>();
vector<ll> c, ret, d;
for (int i = n - 1; i >= 0; --i) {
if (b[i] == i + 1) {
c = b;
c.erase(c.begin() + i);
ret = dp(c, n - 1);
if (ret.size() == 1 && ret[0] == -1)
break;
ret.push_back(i + 1);
return ret;
}
}
ret = vector<ll>{-1};
return ret;
}
int main() {
ll N;
cin >> N;
vector<ll> b(N);
FORi(N) { cin >> b[i]; }
vector<ll> ret = dp(b, N);
FORi(ret.size()) { cout << ret[i] << endl; }
return 0;
}
| replace | 38 | 39 | 38 | 39 | TLE | |
p03089 | C++ | Runtime Error | #include <bits/stdc++.h>
#define MOD 1e9 + 7
using namespace std;
#define pp push_back
#define po pop_back
#define mp make_pair
#define clr(a) memset(a, 0, sizeof(a))
#define neg(a) memset(a, -1, sizeof(a))
#define fas(a) memset(a, false, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define debug1(x) cout << #x << ": " << x << " "
#define rev(x) reverse(x.begin(), x.end())
#define int long long
#define F first
#define S second
// int a[2000];
void printvector(std::vector<int> v) {
for (int i = 0; i < v.size(); ++i) {
cout << v[i] << " ";
}
cout << "" << endl;
}
void printarray(int a[], int n) {
for (int i = 0; i < n; ++i) {
cout << a[i] << " ";
}
cout << "" << endl;
}
int get(std::vector<int> &v) {
// printvector(v);
int got = -1;
for (int i = v.size() - 1; i >= 0; i--) {
if (v[i] == i + 1) {
got = v[i];
for (int j = i; j <= (int)v.size() - 2; j++) {
// if(v.size()==9)debug(j);
v[j] = v[j + 1];
}
break;
}
}
v.pop_back();
return got;
}
void solve() {
int n;
cin >> n;
std::vector<int> v(n);
for (int i = 0; i < n; i++)
cin >> v[i];
std::vector<int> ans;
for (int j = 0; j < n; j++) {
int g = get(v);
if (g == -1) {
cout << -1 << endl;
return;
}
ans.pp(g);
}
rev(ans);
for (int i = 0; i < n; i++)
cout << ans[i] << endl;
}
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
} | #include <bits/stdc++.h>
#define MOD 1e9 + 7
using namespace std;
#define pp push_back
#define po pop_back
#define mp make_pair
#define clr(a) memset(a, 0, sizeof(a))
#define neg(a) memset(a, -1, sizeof(a))
#define fas(a) memset(a, false, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define debug1(x) cout << #x << ": " << x << " "
#define rev(x) reverse(x.begin(), x.end())
#define int long long
#define F first
#define S second
// int a[2000];
void printvector(std::vector<int> v) {
for (int i = 0; i < v.size(); ++i) {
cout << v[i] << " ";
}
cout << "" << endl;
}
void printarray(int a[], int n) {
for (int i = 0; i < n; ++i) {
cout << a[i] << " ";
}
cout << "" << endl;
}
int get(std::vector<int> &v) {
// printvector(v);
int got = -1;
for (int i = v.size() - 1; i >= 0; i--) {
if (v[i] == i + 1) {
got = v[i];
for (int j = i; j <= (int)v.size() - 2; j++) {
// if(v.size()==9)debug(j);
v[j] = v[j + 1];
}
break;
}
}
v.pop_back();
return got;
}
void solve() {
int n;
cin >> n;
std::vector<int> v(n);
for (int i = 0; i < n; i++)
cin >> v[i];
std::vector<int> ans;
for (int j = 0; j < n; j++) {
int g = get(v);
if (g == -1) {
cout << -1 << endl;
return;
}
ans.pp(g);
}
rev(ans);
for (int i = 0; i < n; i++)
cout << ans[i] << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
} | delete | 72 | 75 | 72 | 72 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03089 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
#include <vector>
#define RANGE(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
stack<ll> answer;
bool is_valid(const vector<ll> &in) {
ll in_size = in.size();
if (in_size == 0)
return true;
else {
vector<ll> possible;
RANGE(i, in_size) {
if (in[i] == i + 1)
possible.push_back(i);
}
for (ll poss : possible) {
answer.push(poss + 1);
vector<ll> next_vec;
RANGE(j, in_size) {
if (j == poss)
continue;
next_vec.push_back(in[j]);
}
if (is_valid(next_vec))
return true;
else
answer.pop();
}
return false;
}
}
signed main() {
int N;
cin >> N;
vector<ll> b;
for (int i = 0; i < N; i++) {
ll a;
cin >> a;
b.push_back(a);
}
if (is_valid(b)) {
while (!answer.empty()) {
cout << answer.top() << endl;
answer.pop();
}
} else {
cout << -1 << endl;
}
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <vector>
#define RANGE(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
stack<ll> answer;
bool is_valid(const vector<ll> &in) {
ll in_size = in.size();
if (in_size == 0)
return true;
else {
vector<ll> possible;
RANGE(i, in_size) {
if (in[i] == i + 1)
possible.push_back(i);
else if (in[i] > i + 1)
return false;
}
for (ll poss : possible) {
answer.push(poss + 1);
vector<ll> next_vec;
RANGE(j, in_size) {
if (j == poss)
continue;
next_vec.push_back(in[j]);
}
if (is_valid(next_vec))
return true;
else
answer.pop();
}
return false;
}
}
signed main() {
int N;
cin >> N;
vector<ll> b;
for (int i = 0; i < N; i++) {
ll a;
cin >> a;
b.push_back(a);
}
if (is_valid(b)) {
while (!answer.empty()) {
cout << answer.top() << endl;
answer.pop();
}
} else {
cout << -1 << endl;
}
}
| insert | 19 | 19 | 19 | 21 | TLE | |
p03089 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
#define ll long long
#define N 110
char getc() {
char c = getchar();
while ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && (c < '0' || c > '9'))
c = getchar();
return c;
}
int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); }
int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return x * f;
}
int n, a[N], ans[N];
signed main() {
#ifndef ONLINE_JUDGE
freopen("a.in", "r", stdin);
freopen("a.out", "w", stdout);
#endif
n = read();
for (int i = 1; i <= n; i++)
a[i] = read();
for (int i = n; i >= 1; i--)
for (int j = i; j >= 1; j--)
if (a[j] == j) {
for (int k = j; k < i; k++)
a[k] = a[k + 1];
ans[i] = j;
break;
}
for (int i = 1; i <= n; i++)
if (!ans[i]) {
cout << -1;
return 0;
}
for (int i = 1; i <= n; i++)
cout << ans[i] << endl;
return 0;
// NOTICE LONG LONG!!!!!
}
// 对于第i个位置上的a[i] 需要满足其之后有i-a[i]个比它小的数被放进去
// | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
#define ll long long
#define N 110
char getc() {
char c = getchar();
while ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && (c < '0' || c > '9'))
c = getchar();
return c;
}
int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); }
int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return x * f;
}
int n, a[N], ans[N];
signed main() {
n = read();
for (int i = 1; i <= n; i++)
a[i] = read();
for (int i = n; i >= 1; i--)
for (int j = i; j >= 1; j--)
if (a[j] == j) {
for (int k = j; k < i; k++)
a[k] = a[k + 1];
ans[i] = j;
break;
}
for (int i = 1; i <= n; i++)
if (!ans[i]) {
cout << -1;
return 0;
}
for (int i = 1; i <= n; i++)
cout << ans[i] << endl;
return 0;
// NOTICE LONG LONG!!!!!
}
// 对于第i个位置上的a[i] 需要满足其之后有i-a[i]个比它小的数被放进去
// | delete | 30 | 34 | 30 | 30 | TLE | |
p03089 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
vector<int> vet;
int n;
int main() {
cin >> n;
vet.resize(n);
for (int i = 0; i < n; i++) {
cin >> vet[i];
vet[i]--;
}
vector<int> ans;
bool f = 1;
while (f and vet.size()) {
bool f = 0;
for (int i = vet.size() - 1; i >= 0; i--) {
if (vet[i] == i) {
vet.erase(i + vet.begin());
ans.push_back(i + 1);
f = 1;
break;
}
}
}
if (vet.size())
cout << -1;
else {
reverse(ans.begin(), ans.end());
for (auto it : ans)
cout << it << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
vector<int> vet;
int n;
int main() {
cin >> n;
vet.resize(n);
for (int i = 0; i < n; i++) {
cin >> vet[i];
vet[i]--;
}
vector<int> ans;
bool f = 1;
while (f and vet.size()) {
f = 0;
for (int i = vet.size() - 1; i >= 0; i--) {
if (vet[i] == i) {
vet.erase(i + vet.begin());
ans.push_back(i + 1);
f = 1;
break;
}
}
}
if (vet.size())
cout << -1;
else {
reverse(ans.begin(), ans.end());
for (auto it : ans)
cout << it << endl;
}
} | replace | 15 | 16 | 15 | 16 | TLE | |
p03089 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template <typename T> using uset = unordered_set<T>;
template <typename T1, typename T2> using umap = unordered_map<T1, T2>;
constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
template <typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template <typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
for (auto &u : v)
os << u << endl;
return (os);
}
template <typename T>
istream &operator>>(istream &is, pair<vector<T> &, int> v) {
while (v.second--) {
T a;
v.first.push_back(is >> a, a);
}
return (is);
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &u : v)
is >> u;
return (is);
}
// 1 1
int main() {
int N;
cin >> N;
vint B(N);
cin >> B;
vint ans;
for (int i = 0; i < N; i++) {
int p = -1;
for (int j = 0; j < B.size(); j++) {
if (B[j] == j + 1) {
p = j;
}
}
ans.push_back(B[p]);
B.erase(begin(B) + p);
}
reverse(begin(ans), end(ans));
for (auto &v : ans)
cout << v << el;
return (0);
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template <typename T> using uset = unordered_set<T>;
template <typename T1, typename T2> using umap = unordered_map<T1, T2>;
constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
template <typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template <typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
for (auto &u : v)
os << u << endl;
return (os);
}
template <typename T>
istream &operator>>(istream &is, pair<vector<T> &, int> v) {
while (v.second--) {
T a;
v.first.push_back(is >> a, a);
}
return (is);
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &u : v)
is >> u;
return (is);
}
// 1 1
int main() {
int N;
cin >> N;
vint B(N);
cin >> B;
vint ans;
for (int i = 0; i < N; i++) {
int p = -1;
for (int j = 0; j < B.size(); j++) {
if (B[j] == j + 1) {
p = j;
}
}
if (p == -1) {
cout << -1 << endl;
return (0);
}
ans.push_back(B[p]);
B.erase(begin(B) + p);
}
reverse(begin(ans), end(ans));
for (auto &v : ans)
cout << v << el;
return (0);
}
| insert | 64 | 64 | 64 | 68 | 0 | |
p03089 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
// typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(), (c).end())
#define COUT(x) cout << x << endl
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
// constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF = 1e18;
const int dx[]{1, -1, 0, 0}, dy[]{0, 0, 1, -1};
// function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();
int main() {
LL n;
cin >> n;
VLL b(n);
REP(i, n) cin >> b[i];
VLL ans;
for (int i = b.size() - 1; i >= 0 && !b.empty();) {
if (b[i] == i + 1) {
// cout<<b[i]<<endl;
ans.PB(b[i]);
b.erase(b.begin() + i);
} else {
--i;
}
}
if (b.empty()) {
reverse(ALL(ans));
REP(i, n) COUT(ans[i]);
} else {
COUT(-1);
}
}
LL gcd(LL a, LL b) {
if (a == 0 || b == 0)
return 0;
if (a < b)
swap(a, b);
if (a % b == 0)
return b;
else
gcd(b, a % b);
}
bool isEven(LL a) { return !((bool)(a % 2)); }
void coutY() {
cout << "Yes" << endl;
return;
}
void coutN() {
cout << "No" << endl;
return;
}
| #include "bits/stdc++.h"
using namespace std;
// typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(), (c).end())
#define COUT(x) cout << x << endl
// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
// constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF = 1e18;
const int dx[]{1, -1, 0, 0}, dy[]{0, 0, 1, -1};
// function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();
int main() {
LL n;
cin >> n;
VLL b(n);
REP(i, n) cin >> b[i];
VLL ans;
while (b[0] == 1 && !b.empty()) {
for (int i = b.size() - 1; i >= 0 && !b.empty();) {
if (b[i] == i + 1) {
ans.PB(b[i]);
b.erase(b.begin() + i);
i = (int)b.size() - 1;
} else {
i--;
}
}
}
if (b.empty()) {
reverse(ALL(ans));
REP(i, n) COUT(ans[i]);
} else {
COUT(-1);
}
}
LL gcd(LL a, LL b) {
if (a == 0 || b == 0)
return 0;
if (a < b)
swap(a, b);
if (a % b == 0)
return b;
else
gcd(b, a % b);
}
bool isEven(LL a) { return !((bool)(a % 2)); }
void coutY() {
cout << "Yes" << endl;
return;
}
void coutN() {
cout << "No" << endl;
return;
} | replace | 45 | 52 | 45 | 54 | 0 | |
p03089 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] " << endl;
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
vector<int> bfs(vector<int> v, vector<int> now, int last) {
if (v.empty()) {
return now;
}
int i = v.size();
for (auto itr = v.end() - 1; itr != v.begin() - 1; itr--) {
auto _v = v;
if (i == *itr) {
_v.erase(_v.begin() + i - 1);
now.push_back(i);
vector<int> res = bfs(_v, now, i - 1);
if (res[0] != -1)
return res;
now.pop_back();
}
i--;
}
vector<int> ret = {-1};
return ret;
}
int main(int argc, char const *argv[]) {
int n;
cin >> n;
vector<int> b;
rep(i, n) {
int t;
cin >> t;
b.push_back(t);
}
auto res = bfs(b, {}, 0);
reverse(res.begin(), res.end());
for (int ans : res) {
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] " << endl;
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
vector<int> bfs(vector<int> v, vector<int> now, int last) {
if (v.empty()) {
return now;
}
int i = v.size();
for (auto itr = v.end() - 1; itr != v.begin() - 1; itr--) {
auto _v = v;
if (i == *itr) {
_v.erase(_v.begin() + i - 1);
now.push_back(i);
vector<int> res = bfs(_v, now, i - 1);
if (res[0] != -1)
return res;
now.pop_back();
}
i--;
}
vector<int> ret = {-1};
return ret;
}
int main(int argc, char const *argv[]) {
int n;
cin >> n;
vector<int> b;
rep(i, n) {
int t;
cin >> t;
b.push_back(t);
}
rep(i, n) {
if (b[i] > i + 1) {
cout << -1 << endl;
return 0;
}
}
auto res = bfs(b, {}, 0);
reverse(res.begin(), res.end());
for (int ans : res) {
cout << ans << endl;
}
return 0;
}
| insert | 50 | 50 | 50 | 56 | TLE | |
p03089 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007
int main() {
ll n;
cin >> n;
vector<ll> a;
for (int i = 0; i < n; i++) {
ll x;
cin >> x;
a.push_back(x);
}
vector<ll> b;
while (a.size() != 0) {
for (int i = a.size() - 1; i >= 0; i--) {
ll now = a[i];
if (now == i + 1) {
b.push_back(now);
a.erase(a.begin() + i);
break;
}
if (now < a[i]) {
cout << -1;
return 0;
}
}
}
reverse(b.begin(), b.end());
for (int i = 0; i < n; i++) {
cout << b[i] << " ";
}
// your code goes here
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007
int main() {
ll n;
cin >> n;
vector<ll> a;
for (int i = 0; i < n; i++) {
ll x;
cin >> x;
a.push_back(x);
}
vector<ll> b;
while (a.size() != 0) {
for (int i = a.size() - 1; i >= 0; i--) {
ll now = a[i];
if (now == i + 1) {
b.push_back(now);
a.erase(a.begin() + i);
break;
}
if (now > i + 1) {
cout << -1;
return 0;
}
}
}
reverse(b.begin(), b.end());
for (int i = 0; i < n; i++) {
cout << b[i] << " ";
}
// your code goes here
return 0;
} | replace | 24 | 25 | 24 | 25 | TLE | |
p03089 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
vector<int> tejun;
vector<int> solve(vector<int> v) {
/*REP(i,v.size()){
cout<<v[i]<<" ";
}
cout<<endl;*/
if (v.size() == 1 && v[0] == 1) {
tejun.pb(1);
return v; // 現場へお返ししまーす
}
REP(i, v.size()) {
if (v[i] == i + 1) {
vector<int> v2;
copy(v.begin(), v.end(), back_inserter(v2));
v2.erase(v2.begin() + i);
vector<int> res = solve(v2);
if (res.size() == 0) {
// だめだった。。。
} else {
tejun.pb(i + 1);
return v;
}
}
}
// ダメだった時
vector<int> dame;
return dame;
}
int main() {
int n;
cin >> n;
vector<int> v;
REP(i, n) {
int t;
cin >> t;
v.pb(t);
}
REP(i, n) {
if (v[i] > i + 1) {
cout << -1 << endl;
return 0;
}
}
solve(v);
if (tejun.size() == 0) {
cout << -1 << endl;
return 0;
}
REP(i, n) { cout << tejun[i] << endl; }
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
vector<int> tejun;
vector<int> solve(vector<int> v) {
/*REP(i,v.size()){
cout<<v[i]<<" ";
}
cout<<endl;*/
REP(i, v.size()) {
if (v[i] > i + 1) {
vector<int> dame;
return dame;
}
}
if (v.size() == 1 && v[0] == 1) {
tejun.pb(1);
return v; // 現場へお返ししまーす
}
REP(i, v.size()) {
if (v[i] == i + 1) {
vector<int> v2;
copy(v.begin(), v.end(), back_inserter(v2));
v2.erase(v2.begin() + i);
vector<int> res = solve(v2);
if (res.size() == 0) {
// だめだった。。。
} else {
tejun.pb(i + 1);
return v;
}
}
}
// ダメだった時
vector<int> dame;
return dame;
}
int main() {
int n;
cin >> n;
vector<int> v;
REP(i, n) {
int t;
cin >> t;
v.pb(t);
}
REP(i, n) {
if (v[i] > i + 1) {
cout << -1 << endl;
return 0;
}
}
solve(v);
if (tejun.size() == 0) {
cout << -1 << endl;
return 0;
}
REP(i, n) { cout << tejun[i] << endl; }
return 0;
} | insert | 26 | 26 | 26 | 32 | TLE | |
p03089 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0);
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
// vector print(debug or stdout)
template <class Iit> void vout(const Iit &begin, const Iit &end, ostream &out) {
for (auto it = begin; it != end; it++) {
auto tmp = it;
if (++tmp == end)
out << *it << '\n';
else
out << *it << " ";
}
}
int main(void) {
IOS int N;
cin >> N;
list<int> B;
REP(i, N) {
int b;
cin >> b;
B.push_back(b);
}
vector<int> ans;
REP(i, N) {
// vout(ALL(ans),cerr);
auto it = B.end();
it--;
RREP(j, N - i) {
if (j == 0) {
OUT(-1)
return 0;
}
if (*it == j) {
ans.insert(ans.begin() + j - 1, j);
B.erase(it);
break;
}
it--;
}
}
reverse(ALL(ans));
REP(i, N)
OUT(ans[i])
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0);
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
// vector print(debug or stdout)
template <class Iit> void vout(const Iit &begin, const Iit &end, ostream &out) {
for (auto it = begin; it != end; it++) {
auto tmp = it;
if (++tmp == end)
out << *it << '\n';
else
out << *it << " ";
}
}
int main(void) {
IOS int N;
cin >> N;
list<int> B;
REP(i, N) {
int b;
cin >> b;
B.push_back(b);
}
vector<int> ans;
REP(i, N) {
// vout(ALL(ans),cerr);
auto it = B.end();
it--;
RREP(j, N - i) {
if (j == 0) {
OUT(-1)
return 0;
}
if (*it == j) {
ans.push_back(j);
B.erase(it);
break;
}
it--;
}
}
reverse(ALL(ans));
REP(i, N)
OUT(ans[i])
return 0;
} | replace | 50 | 51 | 50 | 51 | -11 | |
p03089 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout << n << endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
// vector<tuple<long long, long long, long long>>vec;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
const llong inf = 100000000;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> b(n, 0);
REP(i, n) { cin >> b[i], --b[i]; }
vector<int> ans;
for (int j = 0; j < n; j++) {
int cnt = -1;
for (int i = n - 1; i >= 0; --i) {
if (b[i] == i) {
cnt = i;
break;
}
}
if (cnt == -1) {
cout << -1 << endl;
return 0;
}
ans.push_back(cnt + 1);
b.erase(b.begin() + cnt);
}
reverse(ans.begin(), ans.end());
for (auto v : ans)
cout << v << endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout << n << endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
// vector<tuple<long long, long long, long long>>vec;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
const llong inf = 100000000;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> b(n, 0);
REP(i, n) { cin >> b[i], --b[i]; }
vector<int> ans;
for (int j = 0; j < n; j++) {
int cnt = -1;
for (int i = (int)b.size() - 1; i >= 0; --i) // b.size()が毎回切り替わる
{
if (b[i] == i) {
cnt = i;
break;
}
}
if (cnt == -1) {
cout << -1 << endl;
return 0;
}
ans.push_back(cnt + 1);
b.erase(b.begin() + cnt);
}
reverse(ans.begin(), ans.end());
for (auto v : ans)
cout << v << endl;
return 0;
} | replace | 54 | 55 | 54 | 56 | 0 | |
p03089 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll, ll>;
using str = string;
using vpl4 = vector<pair<ll, ll>>;
#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define llin(x) \
ll(x); \
cin >> (x);
#define stin(x) \
str(x); \
cin >> (x);
#define vllin(x, n) \
vll(x)(n); \
FOR(i, 0, n - 1) { cin >> (x)[i]; }
#define vllin2(a, b, n) \
vll(a)(n); \
vll(b)(n); \
FOR(i, 0, n - 1) { cin >> (a)[i] >> b[i]; }
#define vpl4in(x, n) \
vpl4(x)((n), mp(0, 0)); \
FOR(i, 0, n - 1) { cin >> x[i].fi >> x[i].se; }
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define rFOR(i, b, a) for (ll i = a; i >= b; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define says(x) cout << (x) << (' ');
#define sas cout << (' ');
#define sayR(x) cout << fixed << setprecision(10) << (x);
#define salR(x) cout << fixed << setprecision(10) << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
#define pow(a, b) ll(pow(a, b))
ll MOD = 1000000007;
signed main() {
llin(n);
vllin(b, n);
ll l = 0;
vll c(n, 0);
rFOR(i, 0, n - 1) {
rFOR(j, 0, i) {
if (b[j] == j + 1) {
l = 1;
b.erase(b.be + j);
c[i] = j + 1;
break;
}
}
if (l == 0) {
return (-1);
}
l = 0;
}
FOR(i, 0, n - 1) { sal(c[i]); }
} | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll, ll>;
using str = string;
using vpl4 = vector<pair<ll, ll>>;
#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define llin(x) \
ll(x); \
cin >> (x);
#define stin(x) \
str(x); \
cin >> (x);
#define vllin(x, n) \
vll(x)(n); \
FOR(i, 0, n - 1) { cin >> (x)[i]; }
#define vllin2(a, b, n) \
vll(a)(n); \
vll(b)(n); \
FOR(i, 0, n - 1) { cin >> (a)[i] >> b[i]; }
#define vpl4in(x, n) \
vpl4(x)((n), mp(0, 0)); \
FOR(i, 0, n - 1) { cin >> x[i].fi >> x[i].se; }
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define rFOR(i, b, a) for (ll i = a; i >= b; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define says(x) cout << (x) << (' ');
#define sas cout << (' ');
#define sayR(x) cout << fixed << setprecision(10) << (x);
#define salR(x) cout << fixed << setprecision(10) << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
#define pow(a, b) ll(pow(a, b))
ll MOD = 1000000007;
signed main() {
llin(n);
vllin(b, n);
ll l = 0;
vll c(n, 0);
rFOR(i, 0, n - 1) {
rFOR(j, 0, i) {
if (b[j] == j + 1) {
l = 1;
b.erase(b.be + j);
c[i] = j + 1;
break;
}
}
if (l == 0) {
sal(-1);
return 0;
}
l = 0;
}
FOR(i, 0, n - 1) { sal(c[i]); }
} | replace | 68 | 69 | 68 | 70 | 0 | |
p03089 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int N;
bool fin = false;
int search(vector<int> xx, vector<int> ans) {
// int check = 1;
// bool flag = false;
if (xx.size() == 1) {
for (int i = ans.size() - 1; i >= 0; i--) {
cout << ans.at(i) << endl;
}
fin = true;
return 0;
}
for (int i = xx.size() - 1; i > 0; i--) {
if (fin) {
return 0;
}
if (xx.at(i) == i) {
// erase
// flag = true;
vector<int> new_xx = xx;
new_xx.erase(new_xx.begin() + i);
ans.push_back(i);
search(new_xx, ans);
// check *= search(new_xx, ans);
ans.pop_back();
}
}
return 0;
}
int main() {
cin >> N;
vector<int> b = vector<int>(N + 1);
for (int i = 1; i < N + 1; i++) {
cin >> b.at(i);
}
vector<int> ans;
search(b, ans);
if (fin == false) {
cout << -1 << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int N;
bool fin = false;
int search(vector<int> xx, vector<int> ans) {
// int check = 1;
// bool flag = false;
for (int i = 1; i < xx.size(); i++) {
if (xx.at(i) > i) {
cout << -1 << endl;
fin = true;
return 0;
}
}
if (xx.size() == 1) {
for (int i = ans.size() - 1; i >= 0; i--) {
cout << ans.at(i) << endl;
}
fin = true;
return 0;
}
for (int i = xx.size() - 1; i > 0; i--) {
if (fin) {
return 0;
}
if (xx.at(i) == i) {
// erase
// flag = true;
vector<int> new_xx = xx;
new_xx.erase(new_xx.begin() + i);
ans.push_back(i);
search(new_xx, ans);
// check *= search(new_xx, ans);
ans.pop_back();
}
}
return 0;
}
int main() {
cin >> N;
vector<int> b = vector<int>(N + 1);
for (int i = 1; i < N + 1; i++) {
cin >> b.at(i);
}
vector<int> ans;
search(b, ans);
if (fin == false) {
cout << -1 << endl;
}
return 0;
}
| insert | 8 | 8 | 8 | 15 | TLE | |
p03089 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repf(i, f, l) for (int i = f; i < (int)l; ++i)
#define repit(it, t) \
for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++)
#define endl "\n"
#define pb emplace_back
#define lb lower_bound
#define int long long
#define ul unsigned long
#define ull unsigned long long
#define ll long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second
#define DBG0(x) \
{ cout << #x << ": " << x << "\t"; }
#define DBG(x) \
{ \
DBG0(x); \
cout << endl; \
}
#define DBG2(x, y) \
{ \
DBG0(x); \
DBG(y); \
}
#define DBG3(x, y, z) \
{ \
DBG0(x); \
DBG2(y, z); \
}
#define DBG4(w, x, y, z) \
{ \
DBG0(w); \
DBG3(x, y, z); \
}
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef vector<bool> vbl;
typedef pair<int, int> pii;
void print(vint as) {
rep(i, as.size()) cout << as[i] << " ";
cout << endl;
}
vint solve(vint cur) {
if (cur.size() == 1 && cur[0] == 1) {
vint ans;
ans.pb(1);
return ans;
}
rep(i, cur.size()) {
if (cur[i] != i + 1) {
continue;
}
vint ccur;
rep(j, cur.size()) {
if (j != i) {
ccur.pb(cur[j]);
}
}
vint ret = solve(ccur);
if (ret.size() == ccur.size()) {
ret.pb(i + 1);
return ret;
}
}
return vint();
}
signed main(void) {
ios::sync_with_stdio(false);
int n;
cin >> n;
vint as = vint(n);
rep(i, n) cin >> as[i];
vint ans = solve(as);
if (ans.size() != as.size()) {
cout << -1 << endl;
return 0;
}
rep(i, ans.size()) cout << ans[i] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repf(i, f, l) for (int i = f; i < (int)l; ++i)
#define repit(it, t) \
for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++)
#define endl "\n"
#define pb emplace_back
#define lb lower_bound
#define int long long
#define ul unsigned long
#define ull unsigned long long
#define ll long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second
#define DBG0(x) \
{ cout << #x << ": " << x << "\t"; }
#define DBG(x) \
{ \
DBG0(x); \
cout << endl; \
}
#define DBG2(x, y) \
{ \
DBG0(x); \
DBG(y); \
}
#define DBG3(x, y, z) \
{ \
DBG0(x); \
DBG2(y, z); \
}
#define DBG4(w, x, y, z) \
{ \
DBG0(w); \
DBG3(x, y, z); \
}
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef vector<bool> vbl;
typedef pair<int, int> pii;
void print(vint as) {
rep(i, as.size()) cout << as[i] << " ";
cout << endl;
}
vint solve(vint cur) {
rep(i, cur.size()) {
if (cur[i] > i + 1)
return vint();
}
if (cur.size() == 1 && cur[0] == 1) {
vint ans;
ans.pb(1);
return ans;
}
rep(i, cur.size()) {
if (cur[i] != i + 1) {
continue;
}
vint ccur;
rep(j, cur.size()) {
if (j != i) {
ccur.pb(cur[j]);
}
}
vint ret = solve(ccur);
if (ret.size() == ccur.size()) {
ret.pb(i + 1);
return ret;
}
}
return vint();
}
signed main(void) {
ios::sync_with_stdio(false);
int n;
cin >> n;
vint as = vint(n);
rep(i, n) cin >> as[i];
vint ans = solve(as);
if (ans.size() != as.size()) {
cout << -1 << endl;
return 0;
}
rep(i, ans.size()) cout << ans[i] << endl;
return 0;
}
| insert | 54 | 54 | 54 | 58 | TLE | |
p03089 | C++ | Time Limit Exceeded | // Robs Code
/***********HEADER***************/
#include <bits/stdc++.h>
/***********MACROS***************/
#define ll long long int
#define fri(l, k) for (i = l; i <= k; i++)
#define frj(l, k) for (j = l; j >= k; j--)
#define fij(a, b, l, k) \
for (i = a; i <= b; i++) \
for (j = l; j <= k; j++)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 10000007
#define mxval 1e9
#define grt [](auto x, auto y) { return x > y; }
#define pii pair<ll, ll>
/*********VARIABLE****************/
using namespace std;
ll i, j, n, m, k, l, q, t, a, b, sum[3], tot[3], cnt[3];
/***********MAIN******************/
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
vector<ll> v(n);
for (i = 0; i < n; i++)
cin >> v[i];
stack<ll> st;
bool flag = 0;
while (v.size()) {
flag = 0;
for (i = v.size() - 1; i >= 0; i--) {
if (v[i] == i + 1) {
flag = 1;
st.push(i + 1);
v.erase(v.begin() + i);
break;
}
}
}
if (flag == 0) {
cout << -1;
return 0;
}
while (!st.empty()) {
cout << st.top() << "\n";
st.pop();
}
return 0;
}
//......... | // Robs Code
/***********HEADER***************/
#include <bits/stdc++.h>
/***********MACROS***************/
#define ll long long int
#define fri(l, k) for (i = l; i <= k; i++)
#define frj(l, k) for (j = l; j >= k; j--)
#define fij(a, b, l, k) \
for (i = a; i <= b; i++) \
for (j = l; j <= k; j++)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 10000007
#define mxval 1e9
#define grt [](auto x, auto y) { return x > y; }
#define pii pair<ll, ll>
/*********VARIABLE****************/
using namespace std;
ll i, j, n, m, k, l, q, t, a, b, sum[3], tot[3], cnt[3];
/***********MAIN******************/
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
vector<ll> v(n);
for (i = 0; i < n; i++)
cin >> v[i];
stack<ll> st;
bool flag = 0;
while (v.size()) {
flag = 0;
for (i = v.size() - 1; i >= 0; i--) {
if (v[i] == i + 1) {
flag = 1;
st.push(i + 1);
v.erase(v.begin() + i);
break;
}
}
if (flag == 0) {
cout << -1;
return 0;
}
}
while (!st.empty()) {
cout << st.top() << "\n";
st.pop();
}
return 0;
}
//......... | replace | 44 | 48 | 44 | 48 | TLE | |
p03089 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> v(N);
for (int i = 0; i < N; i++)
cin >> v[i];
vector<int> r(N);
for (int i = N - 1; i >= 0; i--) {
int p = -1;
for (int j = 0; j < N; j++) {
if (v[j] == j + 1)
p = j;
}
if (p == -1) {
cout << -1 << endl;
return 0;
}
r[i] = p + 1;
v.erase(v.begin() + p);
}
for (int i = 0; i < N; i++)
cout << r[i] << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> v(N);
for (int i = 0; i < N; i++)
cin >> v[i];
vector<int> r(N);
for (int i = N - 1; i >= 0; i--) {
int p = -1;
for (int j = 0; j < v.size(); j++) {
if (v[j] == j + 1)
p = j;
}
if (p == -1) {
cout << -1 << endl;
return 0;
}
r[i] = p + 1;
v.erase(v.begin() + p);
}
for (int i = 0; i < N; i++)
cout << r[i] << endl;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p03089 | C++ | Runtime Error | #include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define rerepi(i, a, b) for (int i = int(a) - 1; i >= b; --i)
#define rerep(i, n) rerepi(i, n, 0)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T>
inline void remove(std::vector<T> &vector, unsigned int index) {
vector.erase(vector.begin() + index);
}
const long long INF = 1LL << 60;
// ここから開始だよ!
ll N, mark;
vector<ll> B, ans;
int main() {
// 呪文エリア
cin.tie(0);
ios::sync_with_stdio(false);
// 詠唱完了
cin >> N;
rep(i, N) {
ll tmp;
cin >> tmp;
B.push_back(tmp);
}
while (!B.empty()) {
mark = -1;
rep(i, B.size()) {
if (B[i] == i + 1 && mark < i + 1) {
mark = i + 1;
}
}
if (mark == -1) {
cout << -1 << endl;
return 0;
} else {
remove(B, mark);
ans.push_back(mark);
}
}
rerep(i, ans.size()) { cout << ans[i] << endl; }
return 0;
}
| #include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define rerepi(i, a, b) for (int i = int(a) - 1; i >= b; --i)
#define rerep(i, n) rerepi(i, n, 0)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T>
inline void remove(std::vector<T> &vector, unsigned int index) {
vector.erase(vector.begin() + index);
}
const long long INF = 1LL << 60;
// ここから開始だよ!
ll N, mark;
vector<ll> B, ans;
int main() {
// 呪文エリア
cin.tie(0);
ios::sync_with_stdio(false);
// 詠唱完了
cin >> N;
rep(i, N) {
ll tmp;
cin >> tmp;
B.push_back(tmp);
}
while (!B.empty()) {
mark = -1;
rep(i, B.size()) {
if (B[i] == i + 1 && mark < i + 1) {
mark = i + 1;
}
}
if (mark == -1) {
cout << -1 << endl;
return 0;
} else {
remove(B, mark - 1);
ans.push_back(mark);
}
}
rerep(i, ans.size()) { cout << ans[i] << endl; }
return 0;
}
| replace | 60 | 61 | 60 | 61 | -6 | munmap_chunk(): invalid pointer
|
p03089 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>
#define MAX_N 100
using namespace std;
int main() {
int N;
scanf("%d", &N);
int b[N], ans[MAX_N] = {0};
vector<int> bvec;
for (int i = 0; i < N; i++) {
scanf("%d", b + i);
bvec.push_back(b[i]);
}
sort(b, b + N, greater<int>());
for (int i = 0; i < N; i++) {
int a = b[i],
n = (int)(lower_bound(bvec.begin(), bvec.end(), a) - bvec.begin());
bvec.erase(bvec.begin() + n);
int count = 0;
bool inserted = false;
for (int j = N - 1; j >= 0; j--) {
if (ans[j] != 0)
continue;
if (count == n - a + 1) {
ans[j] = a;
inserted = true;
break;
}
count++;
}
if (!inserted) {
printf("-1\n");
return 0;
}
}
for (int i = 0; i < N; i++)
printf("%d\n", ans[i]);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>
#define MAX_N 100
using namespace std;
int main() {
int N;
scanf("%d", &N);
int b[N], ans[MAX_N] = {0};
vector<int> bvec;
for (int i = 0; i < N; i++) {
scanf("%d", b + i);
bvec.push_back(b[i]);
}
sort(b, b + N, greater<int>());
for (int i = 0; i < N; i++) {
int a = b[i],
n = (int)(bvec.rend() - find(bvec.rbegin(), bvec.rend(), a)) - 1;
bvec.erase(bvec.begin() + n);
int count = 0;
bool inserted = false;
for (int j = N - 1; j >= 0; j--) {
if (ans[j] != 0)
continue;
if (count == n - a + 1) {
ans[j] = a;
inserted = true;
break;
}
count++;
}
if (!inserted) {
printf("-1\n");
return 0;
}
}
for (int i = 0; i < N; i++)
printf("%d\n", ans[i]);
return 0;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p03089 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
void Solve();
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20) << fixed;
Solve();
}
/****************************************\
| Thank you for viewing my code:) |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka |
\****************************************/
void Solve() {
int n;
scanf("%d", &n);
vector<int> A(n);
for (int i = 0; i < n; i++) {
scanf("%d", &A[i]);
}
vector<int> B(n);
for (int i = n; i >= 0; i--) {
for (int j = i; j >= 0; j--) {
if (A[j - 1] == j) {
B[i - 1] = j;
A.erase(A.begin() + j - 1);
break;
}
}
}
if (B[0] == 0) {
printf("%d\n", -1);
return;
}
for (int i = 0; i < n; i++) {
printf("%d\n", B[i]);
}
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
void Solve();
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20) << fixed;
Solve();
}
/****************************************\
| Thank you for viewing my code:) |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka |
\****************************************/
void Solve() {
int n;
scanf("%d", &n);
vector<int> A(n);
for (int i = 0; i < n; i++) {
scanf("%d", &A[i]);
}
vector<int> B(n);
for (int i = n; i > 0; i--) {
for (int j = i; j > 0; j--) {
if (A[j - 1] == j) {
B[i - 1] = j;
A.erase(A.begin() + j - 1);
break;
}
}
}
if (B[0] == 0) {
printf("%d\n", -1);
return;
}
for (int i = 0; i < n; i++) {
printf("%d\n", B[i]);
}
} | replace | 29 | 31 | 29 | 31 | 0 | |
p03089 | C++ | Runtime Error | // In the name of God
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
vector<int> ans;
for (int i = 0; i < n; i++) {
ans.insert(ans.begin() + v[i] - 1, v[i]);
}
for (int i = 0; i < n; i++)
cout << ans[i] << endl;
return 0;
}
| // In the name of God
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
vector<int> ans;
for (int i = 0; i < n; i++) {
if (ans.size() < v[i] - 1) {
cout << -1;
exit(0);
}
ans.insert(ans.begin() + v[i] - 1, v[i]);
}
for (int i = 0; i < n; i++)
cout << ans[i] << endl;
return 0;
}
| insert | 17 | 17 | 17 | 21 | 0 | |
p03089 | C++ | Runtime Error | #pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
vector<int> V, ans;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
for (; ch < '0' || ch > '9'; ch = getchar())
if (ch == '-')
f = -1;
for (; ch >= '0' && ch <= '9'; ch = getchar())
x = (x << 1) + (x << 3) + ch - '0';
return x * f;
}
int main() {
int n = read();
for (int i = 1; i <= n; i++)
V.push_back(read() - 1);
for (int i = 1; i <= n; i++) {
bool flag = 0;
for (int j = V.size(); ~j; j--)
if (V[j] == j) {
flag = 1;
ans.push_back(j + 1);
V.erase(V.begin() + j);
break;
}
if (!flag) {
puts("-1");
return 0;
}
}
for (int i = ans.size() - 1; ~i; i--)
printf("%d\n", ans[i]);
return 0;
}
| #pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
vector<int> V, ans;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
for (; ch < '0' || ch > '9'; ch = getchar())
if (ch == '-')
f = -1;
for (; ch >= '0' && ch <= '9'; ch = getchar())
x = (x << 1) + (x << 3) + ch - '0';
return x * f;
}
int main() {
int n = read();
for (int i = 1; i <= n; i++)
V.push_back(read() - 1);
for (int i = 1; i <= n; i++) {
bool flag = 0;
for (int j = V.size() - 1; ~j; j--)
if (V[j] == j) {
flag = 1;
ans.push_back(j + 1);
V.erase(V.begin() + j);
break;
}
if (!flag) {
puts("-1");
return 0;
}
}
for (int i = ans.size() - 1; ~i; i--)
printf("%d\n", ans[i]);
return 0;
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p03089 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
const int INF = 1e9;
vector<int> check(vector<int> b, int n) {
if (n == 1) {
vector<int> ret;
if (b[0] == 1)
ret.push_back(1);
return ret;
}
vector<int> ans;
if (b[0] != 1) {
return ans;
}
int max = *max_element(b.begin(), b.end());
if (max > n) {
return ans;
}
for (int i = 1; i <= n; i++) {
if (b[i - 1] == i) {
vector<int> b2 = b;
b2.erase(b2.begin() + i - 1);
ans = check(b2, n - 1);
if (ans.size() != 0) {
ans.push_back(i);
return ans;
}
}
}
return ans;
}
int main() {
int n;
cin >> n;
vector<int> b(n);
for (int i = 0; i < n; i++) {
cin >> b[i];
}
vector<int> ans = check(b, n);
if (ans.size() != 0) {
for (int i = 0; i < n; i++) {
cout << ans[i] << endl;
}
} else {
cout << -1 << endl;
}
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
const int INF = 1e9;
vector<int> check(vector<int> b, int n) {
if (n == 1) {
vector<int> ret;
if (b[0] == 1)
ret.push_back(1);
return ret;
}
vector<int> ans;
for (int i = 0; i < n; i++) {
if (b[i] > i + 1)
return ans;
}
for (int i = 1; i <= n; i++) {
if (b[i - 1] == i) {
vector<int> b2 = b;
b2.erase(b2.begin() + i - 1);
ans = check(b2, n - 1);
if (ans.size() != 0) {
ans.push_back(i);
return ans;
}
}
}
return ans;
}
int main() {
int n;
cin >> n;
vector<int> b(n);
for (int i = 0; i < n; i++) {
cin >> b[i];
}
vector<int> ans = check(b, n);
if (ans.size() != 0) {
for (int i = 0; i < n; i++) {
cout << ans[i] << endl;
}
} else {
cout << -1 << endl;
}
}
| replace | 19 | 25 | 19 | 22 | TLE | |
p03089 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long int
using namespace std;
map<vector<int>, vector<int>> memo;
vector<int> f(vector<int> &a) {
int n = a.size();
// for (int i = 0; i < n; i++) {
// cout << a[i] << " ";
// }
// cout << endl;
vector<int> res;
if (n == 1) {
return res;
}
if (memo[a].size() > 0 && memo[a][0] < 0) {
return vector<int>();
} else if (memo[a].size() > 0) {
return memo[a];
}
for (int i = n - 1; 0 < i; i--) {
if (i == a[i]) {
vector<int> aa = a;
aa.erase(aa.begin() + i);
res = f(aa);
if (res.size() == n - 2) {
res.push_back(i);
memo[a] = res;
return res;
} else if (i == n - 1) {
break;
}
}
}
// for (int i = 0; i < res.size(); i++) {
// cout << res[i] << " ";
// }
// cout << endl;
memo[a] = vector<int>{-1};
return vector<int>();
}
int main(void) {
int n;
cin >> n;
vector<int> b(n + 1);
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
vector<int> res = f(b);
if (res.size() == n) {
for (int i = 0; i < n; i++) {
cout << res[i] << endl;
}
} else {
cout << -1 << endl;
}
// for (auto a:memo) {
// for (int i = 0; i < a.first.size(); i++) {
// cout << a.first[i] << " ";
// }
// cout << endl;
// for (int i = 0; i < a.second.size(); i++) {
// cout << a.second[i] << " ";
// }
// cout << endl;
// }
return 0;
}
| #include <bits/stdc++.h>
#define ll long long int
using namespace std;
map<vector<int>, vector<int>> memo;
vector<int> f(vector<int> &a) {
int n = a.size();
// for (int i = 0; i < n; i++) {
// cout << a[i] << " ";
// }
// cout << endl;
vector<int> res;
if (n == 1) {
return res;
}
if (memo[a].size() > 0 && memo[a][0] < 0) {
return vector<int>();
} else if (memo[a].size() > 0) {
return memo[a];
}
for (int i = n - 1; 0 < i; i--) {
if (i == a[i]) {
vector<int> aa = a;
aa.erase(aa.begin() + i);
res = f(aa);
if (res.size() == n - 2) {
res.push_back(i);
memo[a] = res;
return res;
} else {
break;
}
}
}
// for (int i = 0; i < res.size(); i++) {
// cout << res[i] << " ";
// }
// cout << endl;
memo[a] = vector<int>{-1};
return vector<int>();
}
int main(void) {
int n;
cin >> n;
vector<int> b(n + 1);
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
vector<int> res = f(b);
if (res.size() == n) {
for (int i = 0; i < n; i++) {
cout << res[i] << endl;
}
} else {
cout << -1 << endl;
}
// for (auto a:memo) {
// for (int i = 0; i < a.first.size(); i++) {
// cout << a.first[i] << " ";
// }
// cout << endl;
// for (int i = 0; i < a.second.size(); i++) {
// cout << a.second[i] << " ";
// }
// cout << endl;
// }
return 0;
}
| replace | 33 | 34 | 33 | 34 | TLE | |
p03089 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i, x, y) \
for (i64 i = i64(x), i##_max_for_repmacro = i64(y); \
i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
void solve() {
// const i64 mod = 1'000'000'007;
i64 N;
cin >> N;
vector<i64> b(N);
rep(i, 0, N) {
cin >> b[i];
--b[i];
}
vector<i64> cnt(N);
rep(i, 0, N) { ++cnt[b[i]]; }
rep(i, 0, N) {
if (cnt[i] > N - i) {
cout << -1 << endl;
return;
}
}
vector<i64> v = b, ans;
rep(i, 0, N) {
i64 maxi = -1, pos = -1;
rep(j, 0, v.size()) {
if (j != v[j])
continue;
if (maxi < v[j]) {
maxi = v[j];
pos = j;
}
}
if (maxi > N - 1 - i) {
cout << -1 << endl;
return;
}
ans.emplace_back(v[pos]);
v.erase(begin(v) + pos);
}
reverse(begin(ans), end(ans));
rep(i, 0, N) { cout << ans[i] + 1 << endl; }
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i, x, y) \
for (i64 i = i64(x), i##_max_for_repmacro = i64(y); \
i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
void solve() {
// const i64 mod = 1'000'000'007;
i64 N;
cin >> N;
vector<i64> b(N);
rep(i, 0, N) {
cin >> b[i];
--b[i];
}
vector<i64> cnt(N);
rep(i, 0, N) { ++cnt[b[i]]; }
rep(i, 0, N) {
if (cnt[i] > N - i) {
cout << -1 << endl;
return;
}
}
vector<i64> v = b, ans;
rep(i, 0, N) {
i64 maxi = -1, pos = -1;
rep(j, 0, v.size()) {
if (j != v[j])
continue;
if (maxi < v[j]) {
maxi = v[j];
pos = j;
}
}
if (maxi > N - 1 - i or pos == -1) {
cout << -1 << endl;
return;
}
ans.emplace_back(v[pos]);
v.erase(begin(v) + pos);
}
reverse(begin(ans), end(ans));
rep(i, 0, N) { cout << ans[i] + 1 << endl; }
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
return 0;
}
| replace | 84 | 85 | 84 | 85 | 0 | |
p03089 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
vector<int> v;
int n, x, i;
int main() {
cin >> n;
for (i = 0; ++i <= n;) {
cin >> x;
if (x > i)
return puts("-1");
v.insert(v.begin() + x - 1, x);
}
for (i = -1; ++i < n;)
cout << v[i] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
vector<int> v;
int n, x, i;
int main() {
cin >> n;
for (i = 0; ++i <= n;) {
cin >> x;
if (x > i)
return 0 * puts("-1");
v.insert(v.begin() + x - 1, x);
}
for (i = -1; ++i < n;)
cout << v[i] << endl;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p03089 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
void prnt(vector<int> b) {
for (int i = 0; i < b.size(); i++) {
cout << b[i] << endl;
}
return;
}
void ok(vector<int> &b, vector<int> &ans, int *bo) {
// prnt(b);
// cout<<"size="<<b.size()<<endl;
if (b.size() == 1 && b[0] == 1) {
// cout<<"hoge\n";
ans.push_back(1);
*bo = 1;
return;
}
for (int i = b.size() - 1; i >= 0; i--) {
if (b[i] == i + 1) {
// cout<<"ho\n";
b.erase(b.begin() + i);
ans.push_back(i + 1);
ok(b, ans, bo);
if (*bo == 1)
return;
ans.pop_back();
b.insert(b.begin() + i, i + 1);
}
}
return;
}
int main() {
int n;
cin >> n;
vector<int> b(n, 0);
vector<int> ans;
for (int i = 0; i < n; i++) {
cin >> b[i];
}
int bo = 0;
ok(b, ans, &bo);
// cout<<"bo="<<bo<<endl;
if (bo == 1) {
for (int i = 0; i < ans.size(); i++) {
cout << ans[ans.size() - i - 1] << endl;
}
} else {
cout << -1 << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
void prnt(vector<int> b) {
for (int i = 0; i < b.size(); i++) {
cout << b[i] << endl;
}
return;
}
void ok(vector<int> &b, vector<int> &ans, int *bo) {
// prnt(b);
// cout<<"size="<<b.size()<<endl;
if (b.size() == 1 && b[0] == 1) {
// cout<<"hoge\n";
ans.push_back(1);
*bo = 1;
return;
}
for (int i = b.size() - 1; i >= 0; i--) {
if (b[i] == i + 1) {
// cout<<"ho\n";
b.erase(b.begin() + i);
ans.push_back(i + 1);
ok(b, ans, bo);
if (*bo == 1)
return;
ans.pop_back();
b.insert(b.begin() + i, i + 1);
break;
}
}
return;
}
int main() {
int n;
cin >> n;
vector<int> b(n, 0);
vector<int> ans;
for (int i = 0; i < n; i++) {
cin >> b[i];
}
int bo = 0;
ok(b, ans, &bo);
// cout<<"bo="<<bo<<endl;
if (bo == 1) {
for (int i = 0; i < ans.size(); i++) {
cout << ans[ans.size() - i - 1] << endl;
}
} else {
cout << -1 << endl;
}
return 0;
} | insert | 29 | 29 | 29 | 30 | TLE | |
p03089 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1000000007;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <typename T> vector<T> gen_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto gen_v(size_t a, Ts... ts) {
return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
vector<int> dfs(vector<int> b) {
if (b.size() == 0)
return vector<int>{-1};
dump(b);
rep(j, 0, b.size()) {
if (b[j] > j + 1)
return vector<int>();
if (b[j] == j + 1) {
vector<int> c = b;
c.erase(c.begin() + j);
auto res = dfs(c);
if (res.size() == 0)
continue;
res.push_back(j);
return res;
}
}
return vector<int>();
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> b(N);
rep(i, 0, N) { cin >> b[i]; }
vector<int> a = dfs(b);
dump(a);
if (a.size()) {
rep(i, 1, a.size()) { cout << a[i] + 1 << endl; }
} else {
cout << -1 << endl;
}
return 0;
} | #include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1000000007;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <typename T> vector<T> gen_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto gen_v(size_t a, Ts... ts) {
return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
vector<int> dfs(vector<int> b) {
if (b.size() == 0)
return vector<int>{-1};
dump(b);
rep(j, 0, b.size()) {
if (b[j] > j + 1)
return vector<int>();
}
rep(j, 0, b.size()) {
if (b[j] == j + 1) {
vector<int> c = b;
c.erase(c.begin() + j);
auto res = dfs(c);
if (res.size() == 0)
continue;
res.push_back(j);
return res;
}
}
return vector<int>();
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> b(N);
rep(i, 0, N) { cin >> b[i]; }
vector<int> a = dfs(b);
dump(a);
if (a.size()) {
rep(i, 1, a.size()) { cout << a[i] + 1 << endl; }
} else {
cout << -1 << endl;
}
return 0;
} | insert | 51 | 51 | 51 | 53 | TLE | |
p03089 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> b(N);
vector<int> ans(N);
ans[0] = 1;
for (int i = 0; i < N; i++) {
cin >> b[i];
}
int j = N - 1;
for (int i = 0; i < N; i++) {
if (b[i] > i + 1) {
cout << -1;
return 0;
}
}
while (b.size() != 1) {
for (int i = N - 1; i > -1; i--) {
if (b[i] == i + 1) {
ans[j] = b[i];
j--;
b.erase(b.begin() + i);
break;
}
}
}
for (int i = 0; i < N; i++) {
cout << ans[i] << endl;
}
return 0;
}
| #include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> b(N);
vector<int> ans(N);
ans[0] = 1;
for (int i = 0; i < N; i++) {
cin >> b[i];
}
int j = N - 1;
for (int i = 0; i < N; i++) {
if (b[i] > i + 1) {
cout << -1;
return 0;
}
}
while (b.size() != 1) {
for (int i = b.size() - 1; i > -1; i--) {
if (b[i] == i + 1) {
ans[j] = b[i];
j--;
b.erase(b.begin() + i);
break;
}
}
}
for (int i = 0; i < N; i++) {
cout << ans[i] << endl;
}
return 0;
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p03089 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> b(n), a(n);
for (int i = 0; i < n; i++)
cin >> b[i];
for (int j = 0; j < n; j++) {
for (int i = n - 1; i >= 0; i--) {
if (i + 1 == b[i]) {
a[j] = b[i];
b.erase(b.begin() + i);
break;
}
}
}
if (a[n - 1] != 1)
cout << -1 << endl;
else {
for (int i = n - 1; i >= 0; i--)
cout << a[i] << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> b(n), a(n);
for (int i = 0; i < n; i++)
cin >> b[i];
for (int j = 0; j < n; j++) {
for (int i = b.size() - 1; i >= 0; i--) {
if (i + 1 == b[i]) {
a[j] = b[i];
b.erase(b.begin() + i);
break;
}
}
}
if (a[n - 1] != 1)
cout << -1 << endl;
else {
for (int i = n - 1; i >= 0; i--)
cout << a[i] << endl;
}
} | replace | 9 | 10 | 9 | 10 | 0 | |
p03089 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define FOR(i, n) for (int i = 0; i < n; i++)
#define error(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
clock_t startTime;
long double getTime() {
return (long double)(clock() - startTime) / CLOCKS_PER_SEC;
}
int n;
int *b;
vector<int> v;
void solve(int x, int y) {
if (x > y)
;
else if (x == y)
cout << b[x] << "\n";
else {
int mina = n + 1;
for (int i = x; i <= y; i++)
mina = min(b[i], mina);
int posmin = y;
while (b[posmin] != mina)
posmin--;
cout << mina << "\n";
solve(posmin + 1, y);
solve(x, posmin - 1);
}
}
int solve1() {
int i = n - 1;
if (i == -1)
return 1;
while (i >= 0 && b[i] != (i + 1))
i--;
if (i == -1)
return 0;
else {
v.eb(i + 1);
for (int j = i + 1; j < n; j++)
b[j - 1] = b[j];
n--;
solve1();
}
}
int main() {
startTime = clock();
// int n;
cin >> n;
b = new int[n];
bool flag = true;
FOR(i, n) { cin >> b[i]; }
if (solve1()) {
for (int i = v.size() - 1; i >= 0; i--)
cout << v[i] << "\n";
} else {
cout << -1;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define FOR(i, n) for (int i = 0; i < n; i++)
#define error(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
clock_t startTime;
long double getTime() {
return (long double)(clock() - startTime) / CLOCKS_PER_SEC;
}
int n;
int *b;
vector<int> v;
void solve(int x, int y) {
if (x > y)
;
else if (x == y)
cout << b[x] << "\n";
else {
int mina = n + 1;
for (int i = x; i <= y; i++)
mina = min(b[i], mina);
int posmin = y;
while (b[posmin] != mina)
posmin--;
cout << mina << "\n";
solve(posmin + 1, y);
solve(x, posmin - 1);
}
}
int solve1() {
int i = n - 1;
if (i == -1)
return 1;
while (i >= 0 && b[i] != (i + 1))
i--;
if (i == -1)
return 0;
else {
v.eb(i + 1);
for (int j = i + 1; j < n; j++)
b[j - 1] = b[j];
n--;
return solve1();
}
}
int main() {
startTime = clock();
// int n;
cin >> n;
b = new int[n];
bool flag = true;
FOR(i, n) { cin >> b[i]; }
if (solve1()) {
for (int i = v.size() - 1; i >= 0; i--)
cout << v[i] << "\n";
} else {
cout << -1;
}
return 0;
} | replace | 75 | 76 | 75 | 76 | 0 | |
p03089 | C++ | Runtime Error | // todo 文字数を少なくする
// #pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
using namespace std;
//@起動時
struct initon {
initon() {
cin.tie(0);
ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
srand((unsigned)clock() + (unsigned)time(NULL));
};
} __initon;
// 衝突対策
#define ws ___ws
//@必須構造
struct T {
int f, s, t;
T() { f = -1, s = -1, t = -1; }
T(int f, int s, int t) : f(f), s(s), t(t) {}
bool operator<(const T &r) const {
return f != r.f ? f < r.f : s != r.s ? s < r.s : t < r.t;
// return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 大きい順
}
bool operator>(const T &r) const {
return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t;
// return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 小さい順
}
bool operator==(const T &r) const { return f == r.f && s == r.s && t == r.t; }
bool operator!=(const T &r) const { return f != r.f || s != r.s || t != r.t; }
int operator[](int i) {
assert(i < 3);
return i == 0 ? f : i == 1 ? s : t;
}
};
struct F {
int a, b, c, d;
F() { a = -1, b = -1, c = -1, d = -1; }
F(int a, int b, int c, int d) : a(a), b(b), c(c), d(d) {}
bool operator<(const F &r) const {
return a != r.a ? a < r.a
: b != r.b ? b < r.b
: c != r.c ? c < r.c
: d < r.d;
// return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c >
// r.c : d > r.d;
}
bool operator>(const F &r) const {
return a != r.a ? a > r.a
: b != r.b ? b > r.b
: c != r.c ? c > r.c
: d > r.d;
// return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c <
// r.c : d < r.d;
}
bool operator==(const F &r) const {
return a == r.a && b == r.b && c == r.c && d == r.d;
}
bool operator!=(const F &r) const {
return a != r.a || b != r.b || c != r.c || d != r.d;
}
int operator[](int i) {
assert(i < 4);
return i == 0 ? a : i == 1 ? b : i == 2 ? c : d;
}
};
T mt(int a, int b, int c) { return T(a, b, c); }
//@マクロ省略系 型,構造
#define int long long
#define ll long long
#define double long double
#define ull unsigned long long
using dou = double;
using itn = int;
using str = string;
using bo = bool;
#define au auto
using P = pair<ll, ll>;
#define fi first
#define se second
#define vec vector
#define beg begin
#define rbeg rbegin
#define con continue
#define bre break
#define brk break
#define is ==
// マクロ省略系 コンテナ
using vi = vector<int>;
#define _overloadvvi(_1, _2, _3, _4, name, ...) name
#define vvi0() vec<vi>
#define vvi1(a) vec<vi> a
#define vvi2(a, b) vec<vi> a(b)
#define vvi3(a, b, c) vec<vi> a(b, vi(c))
#define vvi4(a, b, c, d) vec<vi> a(b, vi(c, d))
#define vvi(...) \
_overloadvvi(__VA_ARGS__, vvi4, vvi3, vvi2, vvi1, vvi0)(__VA_ARGS__)
using vl = vector<ll>;
#define _overloadvvl(_1, _2, _3, _4, name, ...) name
#define vvl1(a) vec<vl> a
#define vvl2(a, b) vec<vl> a(b)
#define vvl3(a, b, c) vec<vl> a(b, vl(c))
#define vvl4(a, b, c, d) vec<vl> a(b, vl(c, d))
#define vvl(...) _overloadvvl(__VA_ARGS__, vvl4, vvl3, vvl2, vvl1)(__VA_ARGS__)
using vb = vector<bool>;
#define _overloadvvb(_1, _2, _3, _4, name, ...) name
#define vvb1(a) vec<vb> a
#define vvb2(a, b) vec<vb> a(b)
#define vvb3(a, b, c) vec<vb> a(b, vb(c))
#define vvb4(a, b, c, d) vec<vb> a(b, vb(c, d))
#define vvb(...) _overloadvvb(__VA_ARGS__, vvb4, vvb3, vvb2, vvb1)(__VA_ARGS__)
using vs = vector<string>;
#define _overloadvvs(_1, _2, _3, _4, name, ...) name
#define vvs1(a) vec<vs> a
#define vvs2(a, b) vec<vs> a(b)
#define vvs3(a, b, c) vec<vs> a(b, vs(c))
#define vvs4(a, b, c, d) vec<vs> a(b, vs(c, d))
#define vvs(...) _overloadvvs(__VA_ARGS__, vvs4, vvs3, vvs2, vvs1)(__VA_ARGS__)
using vd = vector<double>;
#define _overloadvvd(_1, _2, _3, _4, name, ...) name
#define vvd1(a) vec<vd> a
#define vvd2(a, b) vec<vd> a(b)
#define vvd3(a, b, c) vec<vd> a(b, vd(c))
#define vvd4(a, b, c, d) vec<vd> a(b, vd(c, d))
#define vvd(...) _overloadvvd(__VA_ARGS__, vvd4, vvd3, vvd2, vvd1)(__VA_ARGS__)
using vc = vector<char>;
#define _overloadvvc(_1, _2, _3, _4, name, ...) name
#define vvc1(a) vec<vc> a
#define vvc2(a, b) vec<vc> a(b)
#define vvc3(a, b, c) vec<vc> a(b, vc(c))
#define vvc4(a, b, c, d) vec<vc> a(b, vc(c, d))
#define vvc(...) _overloadvvc(__VA_ARGS__, vvc4, vvc3, vvc2, vvc1)(__VA_ARGS__)
using vp = vector<P>;
#define _overloadvvp(_1, _2, _3, _4, name, ...) name
#define vvp1(a) vec<vp> a
#define vvp2(a, b) vec<vp> a(b)
#define vvp3(a, b, c) vec<vp> a(b, vp(c))
#define vvp4(a, b, c, d) vec<vp> a(b, vp(c, d))
using vt = vector<T>;
#define _overloadvvt(_1, _2, _3, _4, name, ...) name
#define vvt1(a) vec<vt> a
#define vvt2(a, b) vec<vt> a(b)
#define vvt3(a, b, c) vec<vt> a(b, vt(c))
#define vvt4(a, b, c, d) vec<vt> a(b, vt(c, d))
#define v3i(a, b, c, d) vector<vector<vi>> a(b, vector<vi>(c, vi(d)))
#define v3d(a, b, c, d) vector<vector<vd>> a(b, vector<vd>(c, vd(d)))
#define v3m(a, b, c, d) vector<vector<vm>> a(b, vector<vm>(c, vm(d)))
#define _vvi vector<vi>
#define _vvl vector<vl>
#define _vvb vector<vb>
#define _vvs vector<vs>
#define _vvd vector<vd>
#define _vvc vector<vc>
#define _vvp vector<vp>
#define PQ priority_queue<ll, vector<ll>, greater<ll>>
#define tos to_string
using mapi = map<int, int>;
using mapd = map<dou, int>;
using mapc = map<char, int>;
using maps = map<str, int>;
using seti = set<int>;
using setd = set<dou>;
using setc = set<char>;
using sets = set<str>;
using qui = queue<int>;
#define bset bitset
#define uset unordered_set
#define mset multiset
#define umap unordered_map
#define umapi unordered_map<int, int>
#define umapp unordered_map<P, int>
#define mmap multimap
// マクロ 繰り返し
#define _overloadrep(_1, _2, _3, _4, name, ...) name
#define _rep(i, n) for (int i = 0, _lim = n; i < _lim; i++)
#define repi(i, m, n) for (int i = m, _lim = n; i < _lim; i++)
#define repadd(i, m, n, ad) for (int i = m, _lim = n; i < _lim; i += ad)
#define rep(...) _overloadrep(__VA_ARGS__, repadd, repi, _rep, )(__VA_ARGS__)
#define _rer(i, n) for (int i = n; i >= 0; i--)
#define reri(i, m, n) for (int i = m, _lim = n; i >= _lim; i--)
#define rerdec(i, m, n, dec) for (int i = m, _lim = n; i >= _lim; i -= dec)
#define rer(...) _overloadrep(__VA_ARGS__, rerdec, reri, _rer, )(__VA_ARGS__)
#define fora(a, b) for (auto &&a : b)
#define forg(gi, ve) \
for (int gi = 0, f, t, c; gi < ve.size() && (f = ve[gi].from, t = ve[gi].to, \
c = ve[gi].cost, true); \
gi++)
#define fort(gi, ve) \
for (int gi = 0, f, t, c; gi < ve.size() && (f = ve[gi].from, t = ve[gi].to, \
c = ve[gi].cost, true); \
gi++) \
if (t != p)
// #define fort(gi, ve) for (int gi = 0, f, t, c;gi<ve.size()&& (gi+=
// (ve[gi].to==p))< ve.size() && (f = ve[gi].from,t=ve[gi].to, c =
// ve[gi].cost,true); gi++)
// マクロ 定数
#define k3 1010
#define k4 10101
#define k5 101010
#define k6 1010101
#define k7 10101010
const int inf = (int)1e9 + 100;
const ll linf = (ll)1e18 + 100;
const double eps = 1e-9;
const double PI = 3.1415926535897932384626433832795029L;
ll ma = numeric_limits<ll>::min();
ll mi = numeric_limits<ll>::max();
const int y4[] = {-1, 1, 0, 0};
const int x4[] = {0, 0, -1, 1};
const int y8[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int x8[] = {1, 0, -1, 0, 1, -1, 1, -1};
// マクロ省略形 関数等
#define arsz(a) (sizeof(a) / sizeof(a[0]))
#define sz(a) ((int)(a).size())
#define rs resize
#define mp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
//@拡張系 こう出来るべきというもの
// 埋め込み 存在を意識せずに機能を増やされているもの
namespace std {
template <> class hash<std::pair<signed, signed>> {
public:
size_t operator()(const std::pair<signed, signed> &x) const {
return hash<ll>()(((ll)x.first << 32) + x.second);
}
};
template <> class hash<std::pair<ll, ll>> {
public:
// 大きいllが渡されると、<<32でオーバーフローするがとりあえず問題ないと判断
size_t operator()(const std::pair<ll, ll> &x) const {
return hash<ll>()(((ll)x.first << 32) + x.second);
}
};
} // namespace std
istream &operator>>(istream &iss, P &a) {
iss >> a.first >> a.second;
return iss;
}
template <typename T> istream &operator>>(istream &iss, vector<T> &vec) {
for (T &x : vec)
iss >> x;
return iss;
}
ostream &operator<<(ostream &os, P p) {
os << p.fi << " " << p.se << endl;
return os;
}
ostream &operator<<(ostream &os, T p) {
os << p.f << " " << p.s << " " << p.t;
return os;
}
ostream &operator<<(ostream &os, F p) {
os << p.a << " " << p.b << " " << p.c << " " << p.d;
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
for (int i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<vector<T>> &vec) {
for (int i = 0; i < vec.size(); i++) {
for (int j = 0; j < vec[0].size(); j++) {
os << vec[i][j];
}
os << endl;
}
return os;
}
template <typename V, typename H> void resize(vector<V> &vec, const H head) {
vec.resize(head);
}
template <typename V, typename H, typename... T>
void resize(vector<V> &vec, const H &head, const T... tail) {
vec.resize(head);
for (auto &v : vec)
resize(v, tail...);
}
template <typename T, typename _Pr>
bool all_of(const vector<T> &vec, _Pr pred) {
return std::all_of(vec.begin(), vec.end(), pred);
}
template <typename T, typename _Pr>
bool any_of(const vector<T> &vec, _Pr pred) {
return std::any_of(vec.begin(), vec.end(), pred);
}
template <typename T, typename _Pr>
bool none_of(const vector<T> &vec, _Pr pred) {
return std::none_of(vec.begin(), vec.end(), pred);
}
template <typename T, typename _Pr>
const typename vector<T>::const_iterator find_if(const vector<T> &vec,
_Pr pred) {
return std::find_if(vec.begin(), vec.end(), pred);
}
template <typename T> bool contains(const vector<T> &vec, const T &val) {
return std::find(vec.begin(), vec.end(), val) != vec.end();
}
template <typename T, typename _Pr>
bool contains_if(const vector<T> &vec, _Pr pred) {
return std::find_if(vec.begin(), vec.end(), pred) != vec.end();
}
template <class T> void replace(vector<T> &a, T key, T v) {
replace(a.begin(), a.end(), key, v);
}
template <class T> bool includes(vector<T> &a, vector<T> &b) {
vi c = a;
vi d = b;
sort(all(c));
sort(all(d));
return includes(all(c), all(d));
}
template <class T> bool is_permutation(vector<T> &a, vector<T> &b) {
return is_permutation(all(a), all(b));
}
template <class T> bool next_permutation(vector<T> &a) {
return next_permutation(all(a));
}
template <class T> T pop(set<T> &set) {
T res = *set.begin();
set.erase(set.find(res));
return res;
}
template <class T> T pop(mset<T> &set) {
T res = *set.begin();
set.erase(set.find(res));
return res;
}
template <class T> T popBack(set<T> &set) {
T res = *set.rbegin();
set.erase(set.find(res));
return res;
}
template <class T> T popBack(mset<T> &set) {
T res = *set.rbegin();
set.erase(set.find(res));
return res;
}
inline void sort(string &a) { sort(a.begin(), a.end()); }
template <class T> inline void sort(vector<T> &a) { sort(a.begin(), a.end()); };
template <class T> inline void sort(vector<T> &a, int len) {
sort(a.begin(), a.begin() + len);
};
template <class T, class F> inline void sort(vector<T> &a, F f) {
sort(a.begin(), a.end(), [&](T l, T r) { return f(l) < f(r); });
};
enum ___pcomparator { fisi, fisd, fdsi, fdsd, sifi, sifd, sdfi, sdfd };
inline void sort(vector<P> &a, ___pcomparator type) {
switch (type) {
case fisi:
sort(all(a),
[&](P l, P r) { return l.fi != r.fi ? l.fi < r.fi : l.se < r.se; });
break;
case fisd:
sort(all(a),
[&](P l, P r) { return l.fi != r.fi ? l.fi < r.fi : l.se > r.se; });
break;
case fdsi:
sort(all(a),
[&](P l, P r) { return l.fi != r.fi ? l.fi > r.fi : l.se < r.se; });
break;
case fdsd:
sort(all(a),
[&](P l, P r) { return l.fi != r.fi ? l.fi > r.fi : l.se > r.se; });
break;
case sifi:
sort(all(a),
[&](P l, P r) { return l.se != r.se ? l.se < r.se : l.fi < r.fi; });
break;
case sifd:
sort(all(a),
[&](P l, P r) { return l.se != r.se ? l.se < r.se : l.fi > r.fi; });
break;
case sdfi:
sort(all(a),
[&](P l, P r) { return l.se != r.se ? l.se > r.se : l.fi < r.fi; });
break;
case sdfd:
sort(all(a),
[&](P l, P r) { return l.se != r.se ? l.se > r.se : l.fi > r.fi; });
break;
}
};
inline void sort(vector<T> &a, ___pcomparator type) {
switch (type) {
case fisi:
sort(all(a), [&](T l, T r) { return l.f != r.f ? l.f < r.f : l.s < r.s; });
break;
case fisd:
sort(all(a), [&](T l, T r) { return l.f != r.f ? l.f < r.f : l.s > r.s; });
break;
case fdsi:
sort(all(a), [&](T l, T r) { return l.f != r.f ? l.f > r.f : l.s < r.s; });
break;
case fdsd:
sort(all(a), [&](T l, T r) { return l.f != r.f ? l.f > r.f : l.s > r.s; });
break;
case sifi:
sort(all(a), [&](T l, T r) { return l.s != r.s ? l.s < r.s : l.f < r.f; });
break;
case sifd:
sort(all(a), [&](T l, T r) { return l.s != r.s ? l.s < r.s : l.f > r.f; });
break;
case sdfi:
sort(all(a), [&](T l, T r) { return l.s != r.s ? l.s > r.s : l.f < r.f; });
break;
case sdfd:
sort(all(a), [&](T l, T r) { return l.s != r.s ? l.s > r.s : l.f > r.f; });
break;
}
};
template <class T> inline void rsort(vector<T> &a) {
sort(a.begin(), a.end(), greater<T>());
};
template <class T> inline void rsort(vector<T> &a, int len) {
sort(a.begin(), a.begin() + len, greater<T>());
};
template <class U, class F> inline void rsort(vector<U> &a, F f) {
sort(a.begin(), a.end(), [&](U l, U r) { return f(l) > f(r); });
};
template <class U> inline void sortp(vector<U> &a, vector<U> &b) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
sort(c);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
;
}
};
// F = T<T>
// 例えばreturn p.fi + p.se;
template <class U, class F> inline void sortp(vector<U> &a, vector<U> &b, F f) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
sort(c, f);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
}
};
template <class U, class F>
inline void sortp(vector<U> &a, vector<U> &b, char type) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
sort(c, type);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
}
};
template <class U> inline void rsortp(vector<U> &a, vector<U> &b) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
rsort(c);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
}
};
template <class U, class F>
inline void rsortp(vector<U> &a, vector<U> &b, F f) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
rsort(c, f);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
}
};
template <class U> inline void sortt(vector<U> &a, vector<U> &b, vector<U> &c) {
vt r;
int n = sz(a);
assert(n == sz(b));
assert(n == sz(c));
rep(i, n) r.eb(a[i], b[i], c[i]);
sort(r);
rep(i, n) {
a[i] = r[i].f;
b[i] = r[i].s;
c[i] = r[i].t;
}
};
template <class U, class F>
inline void sortt(vector<U> &a, vector<U> &b, vector<U> &c, F f) {
vt r;
int n = sz(a);
assert(n == sz(b));
assert(n == sz(c));
rep(i, n) r.eb(a[i], b[i], c[i]);
sort(r, f);
rep(i, n) {
a[i] = r[i].f;
b[i] = r[i].s;
c[i] = r[i].t;
}
};
template <class U, class F>
inline void rsortt(vector<U> &a, vector<U> &b, vector<U> &c, F f) {
vt r;
int n = sz(a);
assert(n == sz(b));
assert(n == sz(c));
rep(i, n) r.eb(a[i], b[i], c[i]);
rsort(r, f);
rep(i, n) {
a[i] = r[i].f;
b[i] = r[i].s;
c[i] = r[i].t;
}
};
template <class T> inline void sort2(vector<vector<T>> &a) {
for (int i = 0, n = a.size(); i < n; i++)
sort(a[i]);
}
template <class T> inline void rsort2(vector<vector<T>> &a) {
for (int i = 0, n = a.size(); i < n; i++)
rsort(a[i]);
}
template <typename A, size_t N, typename T> void fill(A (&a)[N], const T &v) {
rep(i, N) a[i] = v;
}
template <typename A, size_t N, size_t O, typename T>
void fill(A (&a)[N][O], const T &v) {
rep(i, N) rep(j, O) a[i][j] = v;
}
template <typename A, size_t N, size_t O, size_t P, typename T>
void fill(A (&a)[N][O][P], const T &v) {
rep(i, N) rep(j, O) rep(k, P) a[i][j][k] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, typename T>
void fill(A (&a)[N][O][P][Q], const T &v) {
rep(i, N) rep(j, O) rep(k, P) rep(l, Q) a[i][j][k][l] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
typename T>
void fill(A (&a)[N][O][P][Q][R], const T &v) {
rep(i, N) rep(j, O) rep(k, P) rep(l, Q) rep(m, R) a[i][j][k][l][m] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
size_t S, typename T>
void fill(A (&a)[N][O][P][Q][R][S], const T &v) {
rep(i, N) rep(j, O) rep(k, P) rep(l, Q) rep(m, R) rep(n, S)
a[i][j][k][l][m][n] = v;
}
template <typename V, typename T> void fill(V &xx, const T vall) { xx = vall; }
template <typename V, typename T> void fill(vector<V> &vecc, const T vall) {
for (auto &&vx : vecc)
fill(vx, vall);
}
//@汎用便利関数 入力
template <typename T = int> T _in() {
T x;
cin >> x;
return (x);
}
#define _overloadin(_1, _2, _3, _4, name, ...) name
#define in0() _in()
#define in1(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define in4(a, b, c, d) cin >> a >> b >> c >> d
#define in(...) _overloadin(__VA_ARGS__, in4, in3, in2, in1, in0)(__VA_ARGS__)
#define _overloaddin(_1, _2, _3, _4, name, ...) name
#define din1(a) \
int a; \
cin >> a
#define din2(a, b) \
int a, b; \
cin >> a >> b
#define din3(a, b, c) \
int a, b, c; \
cin >> a >> b >> c
#define din4(a, b, c, d) \
int a, b, c, d; \
cin >> a >> b >> c >> d
#define din(...) _overloadin(__VA_ARGS__, din4, din3, din2, din1)(__VA_ARGS__)
#define _overloaddind(_1, _2, _3, _4, name, ...) name
#define din1d(a) \
int a; \
cin >> a; \
a--
#define din2d(a, b) \
int a, b; \
cin >> a >> b; \
a--, b--
#define din3d(a, b, c) \
int a, b, c; \
cin >> a >> b >> c; \
a--, b--, c--
#define din4d(a, b, c, d) \
int a, b, c, d; \
cin >> a >> b >> c >> d; \
; \
a--, b--, c--, d--
#define dind(...) \
_overloaddind(__VA_ARGS__, din4d, din3d, din2d, din1d)(__VA_ARGS__)
#define _overloadout(_1, _2, _3, _4, name, ...) name
#define out1(a) cout << a << endl
#define out2(a, b) cout << a << " " << b << endl
#define out3(a, b, c) cout << a << " " << b << " " << c << endl
#define out4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define out(...) _overloadout(__VA_ARGS__, out4, out3, out2, out1)(__VA_ARGS__)
string sin() { return _in<string>(); }
ll lin() { return _in<ll>(); }
#define na(a, n) \
a.resize(n); \
rep(i, n) cin >> a[i];
#define nao(a, n) \
a.resize(n + 1); \
rep(i, n) cin >> a[i + 1];
#define nad(a, n) \
a.resize(n); \
rep(i, n) { \
cin >> a[i]; \
a[i]--; \
}
#define na2(a, b, n) \
a.resize(n), b.resize(n); \
rep(i, n) cin >> a[i] >> b[i];
#define na2d(a, b, n) \
a.resize(n), b.resize(n); \
rep(i, n) { \
cin >> a[i] >> b[i]; \
a[i]--, b[i]--; \
}
#define na3(a, b, c, n) \
a.resize(n), b.resize(n), c.resize(n); \
rep(i, n) cin >> a[i] >> b[i] >> c[i];
#define na3d(a, b, c, n) \
a.resize(n), b.resize(n), c.resize(n); \
rep(i, n) { \
cin >> a[i] >> b[i] >> c[i]; \
a[i]--, b[i]--, c[i]--; \
}
#define nt(a, h, w) \
resize(a, h, w); \
rep(hi, h) rep(wi, w) cin >> a[hi][wi];
#define ntd(a, h, w) \
rs(a, h, w); \
rep(hi, h) rep(wi, w) cin >> a[hi][wi], a[hi][wi]--;
#define ntp(a, h, w) \
fill(a, '#'); \
rep(hi, 1, h + 1) rep(wi, 1, w + 1) cin >> a[hi][wi];
// デバッグ
#define sp << " " <<
#define debugName(VariableName) #VariableName
#define _deb1(x) cerr << debugName(x) << " = " << x << endl
#define _deb2(x, y) \
cerr << debugName(x) << " = " << x << ", " << debugName(y) << " = " << y \
<< endl
#define _deb3(x, y, z) \
cerr << debugName(x) << " = " << x << ", " << debugName(y) << " = " << y \
<< ", " debugName(z) << " = " << z << endl
#define _deb4(x, y, z, a) \
cerr << debugName(x) << " = " << x << ", " << debugName(y) << " = " << y \
<< ", " << debugName(z) << " = " << z << ", " << debugName(a) << " = " \
<< a << endl
#define _deb5(x, y, z, a, b) \
cerr << debugName(x) << " = " << x << ", " << debugName(y) << " = " << y \
<< ", " << debugName(z) << " = " << z << ", " << debugName(a) << " = " \
<< a << ", " << debugName(b) << " = " << b << endl
#define _overloadebug(_1, _2, _3, _4, _5, name, ...) name
#define debug(...) \
_overloadebug(__VA_ARGS__, _deb5, _deb4, _deb3, _deb2, _deb1)(__VA_ARGS__)
#define deb(...) \
_overloadebug(__VA_ARGS__, _deb5, _deb4, _deb3, _deb2, _deb1)(__VA_ARGS__)
#define debugline(x) \
cerr << x << " " \
<< "(L:" << __LINE__ << ")" << '\n'
// よく使うクラス、構造体
class UnionFind {
public:
vi par, rank, sizes;
int n, trees;
UnionFind(int n) : n(n), trees(n) {
par.resize(n), rank.resize(n), sizes.resize(n);
rep(i, n) par[i] = i, sizes[i] = 1;
}
int root(int x) {
if (par[x] == x)
return x;
else
return par[x] = root(par[x]);
}
int find(int x) { return root(x); }
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return;
if (rank[x] < rank[y])
swap(x, y);
trees--;
par[y] = x;
sizes[x] += sizes[y];
if (rank[x] == rank[y])
rank[x]++;
}
bool same(int x, int y) { return root(x) == root(y); }
int size(int x) { return sizes[root(x)]; }
// 順不同 umapなので
vec<vi> sets() {
vec<vi> res(trees);
umap<int, vi> map;
rep(i, n) map[root(i)].push_back(i);
int i = 0;
for (auto &&p : map) {
int r = p.fi;
res[i].push_back(r);
for (auto &&v : p.se) {
if (r == v)
continue;
res[i].push_back(v);
}
i++;
}
return res;
}
};
using bint = __int128;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
if (s) {
__uint128_t tmp = value < 0 ? -value : value;
char buffer[128];
char *d = std::end(buffer);
do {
--d;
*d = "0123456789"[tmp % 10];
tmp /= 10;
} while (tmp != 0);
if (value < 0) {
--d;
*d = '-';
}
int len = std::end(buffer) - d;
if (dest.rdbuf()->sputn(d, len) != len) {
dest.setstate(std::ios_base::badbit);
}
}
return dest;
}
__int128 toi128(string &s) {
__int128 ret = 0;
for (int i = 0; i < s.length(); i++)
if ('0' <= s[i] && s[i] <= '9')
ret = 10 * ret + s[i] - '0';
return ret;
}
template <typename T> T minv(T a, T m);
template <typename T> class Modular {
public:
using Type = typename decay<decltype(T::value)>::type;
constexpr Modular() : value() {}
template <typename U> Modular(const U &x) { value = normalize(x); }
template <typename U> static Type normalize(const U &x) {
Type v;
if (-mod() <= x && x < mod())
v = static_cast<Type>(x);
else
v = static_cast<Type>(x % mod());
if (v < 0)
v += mod();
return v;
}
const Type &operator()() const { return value; }
template <typename U> explicit operator U() const {
return static_cast<U>(value);
}
constexpr static Type mod() { return T::value; }
Modular &operator+=(const Modular &other) {
if ((value += other.value) >= mod())
value -= mod();
return *this;
}
Modular &operator-=(const Modular &other) {
if ((value -= other.value) < 0)
value += mod();
return *this;
}
template <typename U> Modular &operator+=(const U &other) {
return *this += Modular(other);
}
template <typename U> Modular &operator-=(const U &other) {
return *this -= Modular(other);
}
Modular &operator++() { return *this += 1; }
Modular &operator--() { return *this -= 1; }
Modular operator++(signed) {
Modular result(*this);
*this += 1;
return result;
}
Modular operator--(signed) {
Modular result(*this);
*this -= 1;
return result;
}
Modular operator-() const { return Modular(-value); }
template <typename U = T>
typename enable_if<is_same<typename Modular<U>::Type, signed>::value,
Modular>::type &
operator*=(const Modular &rhs) {
#ifdef _WIN32
uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);
uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x),
d, m;
asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(mod()));
value = m;
#else
value = normalize(static_cast<int64_t>(value) *
static_cast<int64_t>(rhs.value));
#endif
return *this;
}
template <typename U = T>
typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value,
Modular>::type &
operator*=(const Modular &rhs) {
int64_t q =
static_cast<int64_t>(static_cast<double>(value) * rhs.value / mod());
value = normalize(value * rhs.value - q * mod());
return *this;
}
template <typename U = T>
typename enable_if<!is_integral<typename Modular<U>::Type>::value,
Modular>::type &
operator*=(const Modular &rhs) {
value = normalize(value * rhs.value);
return *this;
}
Modular &operator/=(const Modular &other) {
return *this *= Modular(minv(other.value, mod()));
}
template <typename U>
friend bool operator==(const Modular<U> &lhs, const Modular<U> &rhs);
template <typename U>
friend bool operator<(const Modular<U> &lhs, const Modular<U> &rhs);
template <typename U>
friend std::istream &operator>>(std::istream &stream, Modular<U> &number);
private:
Type value;
};
template <typename T>
bool operator==(const Modular<T> &lhs, const Modular<T> &rhs) {
return lhs.value == rhs.value;
}
template <typename T, typename U>
bool operator==(const Modular<T> &lhs, U rhs) {
return lhs == Modular<T>(rhs);
}
template <typename T, typename U>
bool operator==(U lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) == rhs;
}
template <typename T>
bool operator!=(const Modular<T> &lhs, const Modular<T> &rhs) {
return !(lhs == rhs);
}
template <typename T, typename U>
bool operator!=(const Modular<T> &lhs, U rhs) {
return !(lhs == rhs);
}
template <typename T, typename U>
bool operator!=(U lhs, const Modular<T> &rhs) {
return !(lhs == rhs);
}
template <typename T>
bool operator<(const Modular<T> &lhs, const Modular<T> &rhs) {
return lhs.value < rhs.value;
}
template <typename T>
Modular<T> operator+(const Modular<T> &lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) += rhs;
}
template <typename T, typename U>
Modular<T> operator+(const Modular<T> &lhs, U rhs) {
return Modular<T>(lhs) += rhs;
}
template <typename T, typename U>
Modular<T> operator+(U lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) += rhs;
}
template <typename T>
Modular<T> operator-(const Modular<T> &lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) -= rhs;
}
template <typename T, typename U>
Modular<T> operator-(const Modular<T> &lhs, U rhs) {
return Modular<T>(lhs) -= rhs;
}
template <typename T, typename U>
Modular<T> operator-(U lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) -= rhs;
}
template <typename T>
Modular<T> operator*(const Modular<T> &lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) *= rhs;
}
template <typename T, typename U>
Modular<T> operator*(const Modular<T> &lhs, U rhs) {
return Modular<T>(lhs) *= rhs;
}
template <typename T, typename U>
Modular<T> operator*(U lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) *= rhs;
}
template <typename T>
Modular<T> operator/(const Modular<T> &lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) /= rhs;
}
template <typename T, typename U>
Modular<T> operator/(const Modular<T> &lhs, U rhs) {
return Modular<T>(lhs) /= rhs;
}
template <typename T, typename U>
Modular<T> operator/(U lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) /= rhs;
}
constexpr signed MOD = 1000000007;
using mint = Modular<std::integral_constant<decay<decltype(MOD)>::type, MOD>>;
mint com(int n, int r) {
const int NUM_ = 1400001;
static ll fac[NUM_ + 1], finv[NUM_ + 1], inv[NUM_ + 1];
if (fac[0] == 0) {
inv[1] = fac[0] = finv[0] = 1;
for (int i = 2; i <= NUM_; ++i)
inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
for (int i = 1; i <= NUM_; ++i)
fac[i] = fac[i - 1] * i % MOD, finv[i] = finv[i - 1] * inv[i] % MOD;
}
if (r < 0 || r > n)
return 0;
return mint(finv[r] * fac[n] % MOD * finv[n - r]);
}
mint ncr(int n, int r) { return com(n, r); }
mint nhr(int n, int r) { return com(n + r - 1, r); }
template <typename T> T minv(T a, T m) {
T u = 0, v = 1;
while (a != 0) {
T t = m / a;
m -= t * a;
swap(a, m);
u -= t * v;
swap(u, v);
}
assert(m == 1);
return u;
}
template <typename T, typename U>
Modular<T> mpow(const Modular<T> &a, const U &b) {
assert(b >= 0);
int x = a(), res = 1;
U p = b;
while (p > 0) {
if (p & 1)
(res *= x) %= MOD;
(x *= x) %= MOD;
p >>= 1;
}
return res;
}
template <typename T, typename U> Modular<T> mpow(const T &a, const U &b) {
assert(b >= 0);
int x = a, res = 1;
U p = b;
while (p > 0) {
if (p & 1)
(res *= x) %= MOD;
(x *= x) %= MOD;
p >>= 1;
}
return res;
}
template <typename T> string to_string(const Modular<T> &number) {
return to_string(number());
}
template <typename T>
std::ostream &operator<<(std::ostream &stream, const Modular<T> &number) {
return stream << number();
}
template <typename T>
std::istream &operator>>(std::istream &stream, Modular<T> &number) {
typename common_type<typename Modular<T>::Type, int64_t>::type x;
stream >> x;
number.value = Modular<T>::normalize(x);
return stream;
}
using PM = pair<mint, mint>;
using vm = vector<mint>;
#define _overloadvvm(_1, _2, _3, _4, name, ...) name
#define vvm1(a) vec<vm> a
#define vvm2(a, b) vec<vm> a(b)
#define vvm3(a, b, c) vec<vm> a(b, vm(c))
#define vvm4(a, b, c, d) vec<vm> a(b, vm(c, d))
#define vvm(...) _overloadvvm(__VA_ARGS__, vvm4, vvm3, vvm2, vvm1)(__VA_ARGS__)
vb isPrime;
vi primes;
void setPrime() {
int len = 4010101;
isPrime.resize(4010101);
fill(isPrime, true);
isPrime[0] = isPrime[1] = false;
for (int i = 2; i <= sqrt(len) + 5; ++i) {
if (!isPrime[i])
continue;
for (int j = 2; i * j < len; ++j) {
isPrime[i * j] = false;
}
}
rep(i, len) if (isPrime[i]) primes.pb(i);
}
// 幾何 Pをcomplexとして扱う
bool eq(double a, double b) { return fabs(a - b) < eps; }
using C = complex<double>;
C rot(C &a, dou th) { return a * C(cos(th), sin(th)); }
dou inpro(C &a, C &b) { return real(a * conj(b)); }
// 90度回転させて内積が0なら平行
bool line(C a, C b, C c) {
C ab = b - a;
C ac = c - a;
// 複素数の掛け算は回転
ab *= C(0, 1);
return eq(inpro(ab, ac), 0);
}
bool line(P a, P b, P c) {
return line(C(a.fi, a.se), C(b.fi, b.se), C(c.fi, c.se));
}
bool line(int xa, int ya, int xb, int yb, int xc, int yc) {
C a = C(xa, ya);
C b = C(xb, yb);
C c = C(xc, yc);
return line(a, b, c);
}
// 便利関数
// テスト用
char ranc() { return (char)('a' + rand() % 26); }
int rand(int min, int max) {
assert(min <= max);
if (min >= 0 && max >= 0) {
return rand() % (max + 1 - min) + min;
} else if (max < 0) {
return -rand(-max, -min);
} else {
//+
if (rand() % 2) {
return rand(0, max);
//-
} else {
return -rand(0, -min);
}
}
}
vi ranv(int n, int min, int max) {
vi v(n);
rep(i, n) v[i] = rand(min, max);
return v;
}
// 単調増加
vi ranvi(int n, int min, int max) {
vi v(n);
bool bad = 1;
while (bad) {
bad = 0;
v.resize(n);
rep(i, n) {
if (i && min > max - v[i - 1]) {
bad = 1;
break;
}
if (i)
v[i] = v[i - 1] + rand(min, max - v[i - 1]);
else
v[i] = rand(min, max);
}
}
return v;
}
void ranvlr(int n, int min, int max, vi &l, vi &r) {
l.resize(n);
r.resize(n);
rep(i, n) {
l[i] = rand(min, max);
r[i] = l[i] + rand(0, max - l[i]);
}
}
// 便利 汎用
// strを整数として比較
string smax(str &a, str b) {
if (sz(a) < sz(b)) {
return b;
} else if (sz(a) > sz(b)) {
return a;
} else {
rep(i, sz(a)) {
if (a[i] < b[i]) {
return b;
} else if (a[i] > b[i])
return a;
}
}
return a;
}
// strを整数として比較
string smin(str &a, str b) {
if (sz(a) < sz(b)) {
return a;
} else if (sz(a) > sz(b)) {
return b;
} else {
rep(i, sz(a)) {
if (a[i] < b[i]) {
return a;
} else if (a[i] > b[i])
return b;
}
}
return a;
}
template <typename V, typename T> int find(vector<V> &a, const T key) {
rep(i, sz(a)) if (a[i] == key) return i;
return -1;
}
template <typename V, typename T> P find(vector<vector<V>> &a, const T key) {
rep(i, sz(a)) rep(j, sz(a[0])) if (a[i][j] == key) return mp(i, j);
return mp(-1, -1);
}
template <typename V, typename U>
T find(vector<vector<vector<V>>> &a, const U key) {
rep(i, sz(a)) rep(j, sz(a[0]))
rep(k, sz(a[0][0])) if (a[i][j][k] == key) return mt(i, j, k);
return mt(-1, -1, -1);
}
template <typename V, typename T> int count(V &a, const T k) { return a == k; }
template <typename V, typename T> int count(vector<V> &a, const T k) {
int ret = 0;
fora(v, a) ret += count(v, k);
return ret;
}
template <typename V> int count_odd(V &a) { return a % 2; }
template <typename V> int count_odd(vector<V> &a) {
int ret = 0;
fora(v, a) ret += count_odd(v);
return ret;
}
template <typename V> int count_even(V &a) { return a % 2 == 0; }
template <typename V> int count_even(vector<V> &a) {
int ret = 0;
fora(v, a) ret += count_even(v);
return ret;
}
// algorythm
void iota(vector<int> &ve, int s, int n) {
ve.resize(n);
iota(all(ve), s);
}
vi iota(int s, int n) {
vi ve(n);
iota(all(ve), s);
return ve;
}
// 便利 数学
int mod(int a, int m) { return (a % m + m) % m; }
int pow(int a) { return a * a; };
ll fact(int v) { return v <= 1 ? 1 : v * fact(v - 1); }
ll comi(int n, int r) {
assert(n < 100);
static vvi(pas, 100, 100);
if (pas[0][0])
return pas[n][r];
pas[0][0] = 1;
rep(i, 1, 100) {
pas[i][0] = 1;
rep(j, 1, i + 1) pas[i][j] = pas[i - 1][j - 1] + pas[i - 1][j];
}
return pas[n][r];
}
void ole() {
#ifdef _DEBUG
debugline("ole");
exit(0);
#endif
string a = "a";
rep(i, 30) a += a;
rep(i, 1 << 17) cout << a << endl;
cout << "OLE 出力長制限超過" << endl;
exit(0);
}
void tle() {
while (inf)
cout << inf << endl;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll gcd(vi b) {
ll res = b[0];
for (auto &&v : b)
res = gcd(v, res);
return res;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll rev(ll a) {
ll res = 0;
while (a) {
res *= 10;
res += a % 10;
a /= 10;
}
return res;
}
template <class T> vector<T> rev(vector<T> &a) {
vector<T> ret = a;
reverse(all(ret));
return ret;
}
ll ceil(ll a, ll b) {
if (b == 0) {
debugline("ceil");
deb(a, b);
ole();
return -1;
} else
return (a + b - 1) / b;
}
ll sqrt(ll a) {
if (a < 0) {
debugline("sqrt");
deb(a);
ole();
}
ll res = (ll)std::sqrt(a);
while (res * res < a)
res++;
return res;
}
double log(double e, double x) { return log(x) / log(e); }
ll sig(ll t) { return (1 + t) * t / 2; }
ll sig(ll s, ll t) { return (s + t) * (t - s + 1) / 2; }
vi divisors(int v) {
vi res;
double lim = std::sqrt(v);
for (int i = 1; i <= lim; ++i) {
if (v % i == 0) {
res.pb(i);
if (i != v / i)
res.pb(v / i);
}
}
return res;
}
vi factorization(int v) {
int tv = v;
vi res;
if (isPrime.size() == 0)
setPrime();
for (auto &&p : primes) {
if (v % p == 0)
res.push_back(p);
while (v % p == 0) {
v /= p;
}
if (v == 1 || p * p > tv)
break;
}
if (v > 1)
res.pb(v);
return res;
}
unordered_map<int, int> factorizationMap(int v) {
int tv = v;
unordered_map<int, int> res;
if (isPrime.size() == 0)
setPrime();
for (auto &&p : primes) {
while (v % p == 0) {
res[p]++;
v /= p;
}
if (v == 1 || p * p > tv)
break;
}
if (v > 1)
res[v]++;
return res;
}
int get(int a, int keta) { return (a / (int)pow(10, keta)) % 10; }
int keta(int v) {
int cou = 0;
while (v) {
cou++, v %= 10;
}
return cou;
}
int dsum(int v) {
int ret = 0;
for (; v; v /= 10)
ret += v % 10;
return ret;
}
int sumd(int v) { return dsum(v); }
// 変換系
template <class T, class U> vector<T> keys(vector<pair<T, U>> a) {
vector<T> res;
for (auto &&k : a)
res.pb(k.fi);
return res;
}
template <class T, class U> vector<U> keys(map<T, U> a) {
vector<U> res;
for (auto &&k : a)
res.pb(k.fi);
return res;
}
template <class T, class U> vector<U> keys(umap<T, U> a) {
vector<U> res;
for (auto &&k : a)
res.pb(k.fi);
return res;
}
template <class T, class U> vector<U> values(vector<pair<T, U>> a) {
vector<U> res;
for (auto &&k : a)
res.pb(k.se);
return res;
}
template <class T, class U> vector<T> values(map<T, U> a) {
vector<T> res;
for (auto &&k : a)
res.pb(k.se);
return res;
}
template <class T, class U> vector<T> values(umap<T, U> a) {
vector<T> res;
for (auto &&k : a)
res.pb(k.se);
return res;
}
vi list(int a) {
vi res;
while (a) {
res.insert(res.begin(), a % 10);
a /= 10;
}
return res;
}
template <class T, class U> bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class U> bool chmax(const U &b) { return chmax(ma, b); }
template <class T, class U> bool chmin(T &a, const U &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <class U> bool chmin(const U &b) { return chmin(mi, b); }
#define chmi chmin
#define chma chmax
template <class T> T min(T a, signed b) { return a < b ? a : b; }
template <class T> T max(T a, signed b) { return a < b ? b : a; }
template <class T> T min(T a, T b, T c) {
return a >= b ? b >= c ? c : b : a >= c ? c : a;
}
template <class T> T max(T a, T b, T c) {
return a <= b ? b <= c ? c : b : a <= c ? c : a;
}
template <class T> T min(vector<T> a) { return *min_element(all(a)); }
template <class T> T min(vector<T> a, int n) {
return *min_element(a.begin(), a.begin() + min(n, sz(a)));
}
template <class T> T min(vector<T> a, int s, int n) {
return *min_element(a.begin() + s, a.begin() + min(n, sz(a)));
}
template <class T> T max(vector<T> a) { return *max_element(all(a)); }
template <class T> T max(vector<T> a, int n) {
return *max_element(a.begin(), a.begin() + min(n, sz(a)));
}
template <class T> T max(vector<T> a, int s, int n) {
return *max_element(a.begin() + s, a.begin() + min(n, sz(a)));
}
template <typename A, size_t N> A max(A (&a)[N]) {
A res = a[0];
rep(i, N) res = max(res, a[i]);
return res;
}
template <typename A, size_t N, size_t O> A max(A (&a)[N][O]) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P> A max(A (&a)[N][O][P]) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q>
A max(A (&a)[N][O][P][Q], const T &v) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R>
A max(A (&a)[N][O][P][Q][R]) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
size_t S>
A max(A (&a)[N][O][P][Q][R][S]) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N> A min(A (&a)[N]) {
A res = a[0];
rep(i, N) res = min(res, a[i]);
return res;
}
template <typename A, size_t N, size_t O> A min(A (&a)[N][O]) {
A res = min(a[0]);
rep(i, N) res = min(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P> A min(A (&a)[N][O][P]) {
A res = min(a[0]);
rep(i, N) res = min(res, min(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q>
A min(A (&a)[N][O][P][Q], const T &v) {
A res = min(a[0]);
rep(i, N) res = min(res, min(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R>
A min(A (&a)[N][O][P][Q][R]) {
A res = min(a[0]);
rep(i, N) res = min(res, min(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
size_t S>
A min(A (&a)[N][O][P][Q][R][S]) {
A res = min(a[0]);
rep(i, N) res = min(res, min(a[i]));
return res;
}
template <class T> T sum(vector<T> v, int len = -1) {
if (len == -1)
len = v.size();
T res = 0;
chmin(len, v.size());
rep(i, len) res += v[i];
return res;
}
template <class T> T sum(vector<vector<T>> &v, int h = -1, int w = -1) {
if (h == -1)
h = v.size();
if (w == -1)
w = v[0].size();
T res = 0;
chmin(h, v.size());
chmin(w, v[0].size());
rep(i, h) rep(j, w) res += v[i][j];
return res;
}
P sump(vp &v, int len = -1) {
if (len == -1)
len = v.size();
P res = {0, 0};
chmin(len, v.size());
rep(i, len) {
res.fi += v[i].fi;
res.se += v[i].se;
}
return res;
}
/// 要素が0の時、返り値は0か1か
template <class T> T mul(vector<T> &v, int len = -1) {
if (len == -1)
len = v.size();
T res = 1;
chmin(len, v.size());
rep(i, len) res *= v[i];
return res;
}
void clear(PQ &q) {
while (q.size())
q.pop();
}
template <class T> void clear(queue<T> &q) {
while (q.size())
q.pop();
}
template <class T> T *negarr(int size) {
T *body = (T *)malloc((size * 2 + 1) * sizeof(T));
return body + size;
}
template <class T> T *negarr2(int h, int w) {
double **dummy1 = new double *[2 * h + 1];
double *dummy2 = new double[(2 * h + 1) * (2 * w + 1)];
dummy1[0] = dummy2 + w;
for (int i = 1; i <= 2 * h + 1; i++) {
dummy1[i] = dummy1[i - 1] + 2 * w + 1;
}
double **a = dummy1 + h;
}
// imoは0-indexed
// ruiは1-indexed
template <class T> vector<T> imo(vector<T> &v) {
vector<T> ret = v;
rep(i, sz(ret) - 1) ret[i + 1] += ret[i];
return ret;
}
template <class T> vector<T> imomi(vector<T> &v) {
vector<T> ret = v;
rep(i, sz(ret) - 1) chmin(ret[i + 1], ret[i]);
return ret;
}
template <class T> struct ruiC {
const vector<T> rui;
ruiC(vector<T> &ru) : rui(ru) {}
T operator()(int l, int r) {
assert(l <= r);
return rui[r] - rui[l];
}
T operator[](int i) { return rui[i]; }
};
template <class T> struct rruic {
const T *rrui;
rruic(T *ru) : rrui(ru) {}
// n-1から-1へ
T operator()(int l, int r) {
assert(l >= r);
return rrui[r] - rrui[l];
}
T operator[](int i) { return rrui[i]; }
};
template <class T> vector<T> ruiv(vector<T> &a) {
vector<T> ret(a.size() + 1);
rep(i, a.size()) ret[i + 1] = ret[i] + a[i];
return ret;
}
template <class T> ruiC<T> ruic(vector<T> &a) {
vector<T> ret = ruiv(a);
return ruiC<T>(ret);
}
template <class T> vector<T> ruim(vector<T> &a) {
vector<T> res(a.size() + 1, 1);
rep(i, a.size()) res[i + 1] = res[i] * a[i];
return res;
}
// template<class T> T *rrui(vector<T> &a) {
// 右から左にかけての半開区間 (-1 n-1]
template <class T> rruic<T> rrui(vector<T> &a) {
int len = a.size();
T *body = (T *)malloc((len + 1) * sizeof(T));
T *res = body + 1;
rer(i, len - 1) res[i - 1] = res[i] + a[i];
return rruic<T>(res);
}
// 掛け算
template <class T> T *rruim(vector<T> &a) {
int len = a.size();
T *body = (T *)malloc((len + 1) * sizeof(T));
T *res = body + 1;
res[len - 1] = 1;
rer(i, len - 1) res[i - 1] = res[i] * a[i];
return res;
}
template <class T, class U> void inc(T &a, U v = 1) { a += v; }
template <class T, class U> void inc(vector<T> &a, U v = 1) {
for (auto &u : a)
inc(u, v);
}
template <class T> void inc(vector<T> &a) {
for (auto &u : a)
inc(u, 1);
}
template <class T, class U> void plus(T &a, U v = 1) { a += v; }
template <class T, class U> void plus(vector<T> &a, U v = 1) {
for (auto &u : a)
inc(u, v);
}
template <class T> void plus(vector<T> &a) {
for (auto &u : a)
inc(u, 1);
}
template <class T, class U> void dec(T &a, U v = 1) { a -= v; }
template <class T, class U> void dec(vector<T> &a, U v = 1) {
for (auto &u : a)
dec(u, v);
}
template <class T> void dec(vector<T> &a) {
for (auto &u : a)
dec(u, 1);
}
template <class T, class U> void minu(T &a, U v = 1) { a -= v; }
template <class T, class U> void minu(vector<T> &a, U v = 1) {
for (auto &u : a)
dec(u, v);
}
template <class T> void minu(vector<T> &a) {
for (auto &u : a)
dec(u, 1);
}
inline bool inside(int h, int w, int H, int W) {
return h >= 0 && w >= 0 && h < H && w < W;
}
inline bool inside(int v, int l, int r) { return l <= v && v < r; }
#define ins inside
ll u(ll a) { return a < 0 ? 0 : a; }
template <class T> vector<T> u(const vector<T> &a) {
vector<T> ret = a;
fora(v, ret) v = u(v);
return ret;
}
#define MIN(a) numeric_limits<a>::min()
#define MAX(a) numeric_limits<a>::max()
ll goldd(ll left, ll right, function<ll(ll)> calc) {
double GRATIO = 1.6180339887498948482045868343656;
ll lm = left + (ll)((right - left) / (GRATIO + 1.0));
ll rm = lm + (ll)((right - lm) / (GRATIO + 1.0));
ll fl = calc(lm);
ll fr = calc(rm);
while (right - left > 10) {
if (fl < fr) {
right = rm;
rm = lm;
fr = fl;
lm = left + (ll)((right - left) / (GRATIO + 1.0));
fl = calc(lm);
} else {
left = lm;
lm = rm;
fl = fr;
rm = lm + (ll)((right - lm) / (GRATIO + 1.0));
fr = calc(rm);
}
}
ll minScore = MAX(ll);
ll resIndex = left;
for (ll i = left; i < right + 1; i++) {
ll score = calc(i);
if (minScore > score) {
minScore = score;
resIndex = i;
}
}
return resIndex;
}
ll goldt(ll left, ll right, function<ll(ll)> calc) {
double GRATIO = 1.6180339887498948482045868343656;
ll lm = left + (ll)((right - left) / (GRATIO + 1.0));
ll rm = lm + (ll)((right - lm) / (GRATIO + 1.0));
ll fl = calc(lm);
ll fr = calc(rm);
while (right - left > 10) {
if (fl > fr) {
right = rm;
rm = lm;
fr = fl;
lm = left + (ll)((right - left) / (GRATIO + 1.0));
fl = calc(lm);
} else {
left = lm;
lm = rm;
fl = fr;
rm = lm + (ll)((right - lm) / (GRATIO + 1.0));
fr = calc(rm);
}
}
if (left > right) {
ll l = left;
left = right;
right = l;
}
ll maxScore = MIN(ll);
ll resIndex = left;
for (ll i = left; i < right + 1; i++) {
ll score = calc(i);
if (maxScore < score) {
maxScore = score;
resIndex = i;
}
}
return resIndex;
}
template <class T> T min(vector<vector<T>> &a) {
T res = MAX(T);
rep(i, a.size()) chmin(res, *min_element(all(a[i])));
return res;
}
template <class T> T max(vector<vector<T>> &a) {
T res = MIN(T);
rep(i, a.size()) chmax(res, *max_element(all(a[i])));
return res;
}
bool bget(ll m, int keta) { return (m >> keta) & 1; }
int bget(ll m, int keta, int sinsuu) {
m /= (ll)pow(sinsuu, keta);
return m % sinsuu;
}
inline ll bit(int n) { return (1LL << (n)); }
inline ll bit(int n, int sinsuu) { return (ll)pow(sinsuu, n); }
// int bcou(ll m) { return __builtin_popcount(m & 0xFFFFFFFF) +
// __builtin_popcount(m >> 32); }
#define bcou __builtin_popcountll
// 最下位ビット
int lbit(int n) { return n & -n; }
// 最上位ビット
int hbit(int n) {
n |= (n >> 1);
n |= (n >> 2);
n |= (n >> 4);
n |= (n >> 8);
n |= (n >> 16);
n |= (n >> 32);
return n - (n >> 1);
}
// 初期化は0を渡す
ll nextComb(ll &mask, int n, int r) {
if (!mask)
return mask = (1LL << r) - 1;
ll x = mask & -mask; // 最下位の1
ll y = mask + x; // 連続した下の1を繰り上がらせる
ll res = ((mask & ~y) / x >> 1) | y;
if (bget(res, n))
return mask = 0;
else
return mask = res;
}
// n桁以下でビットがr個立っているもののvectorを返す
vl bitCombList(int n, int r) {
vl res;
int m = 0;
while (nextComb(m, n, r)) {
res.pb(m);
}
return res;
}
// 大文字小文字を区別する
int altoiaZ(char c) {
if ('A' <= c && c <= 'Z')
return c - 'A';
return c - 'a' + 26;
}
char itoalaZ(int i) {
if (i < 26)
return 'A' + i;
return 'a' + i - 26;
}
// aもAも0を返す 基本小文字
int altoi(char c) {
if ('A' <= c && c <= 'Z')
return c - 'A';
return c - 'a';
}
char itoal(int i) { return 'a' + i; }
int ctoi(char c) { return c - '0'; }
char itoc(int i) { return i + '0'; }
int vtoi(vi &v) {
int res = 0;
if (sz(v) > 18) {
debugline("vtoi");
deb(sz(v));
ole();
}
rep(i, sz(v)) {
res *= 10;
res += v[i];
}
return res;
}
vi itov(int i) {
vi res;
while (i) {
res.pb(i % 10);
i /= 10;
}
rev(res);
return res;
}
vector<vector<int>> ctoi(vector<vector<char>> s, char c) {
int n = sz(s), m = sz(s[0]);
vector<vector<int>> res(n, vector<int>(m));
rep(i, n) rep(j, m) res[i][j] = s[i][j] == c;
return res;
}
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
void compress(vi &a) {
vi b;
int len = a.size();
for (int i = 0; i < len; ++i) {
b.push_back(a[i]);
}
sort(b);
UNIQUE(b);
for (int i = 0; i < len; ++i) {
a[i] = lower_bound(all(b), a[i]) - b.begin();
}
}
void compress(int a[], int len) {
vi b;
for (int i = 0; i < len; ++i) {
b.push_back(a[i]);
}
sort(b);
UNIQUE(b);
for (int i = 0; i < len; ++i) {
a[i] = lower_bound(all(b), a[i]) - b.begin();
}
}
// 要素が見つからなかったときに困る
#define binarySearch(a, v) (binary_search(all(a), v))
#define lowerIndex(a, v) (lower_bound(all(a), v) - a.begin())
#define lowerBound(a, v) (*lower_bound(all(a), v))
#define upperIndex(a, v) (upper_bound(all(a), v) - a.begin())
#define upperBound(a, v) (*upper_bound(all(a), v))
#define ans(a) \
cout << a << endl; \
continue;
#define poll(a) \
q.front(); \
q.pop()
#define dpoll(a) \
q.front(); \
q.pop_front()
#define pollLast(a) \
q.back(); \
q.pop_back()
#define pollBack(a) \
q.back(); \
q.pop_back()
template <class T> inline void fin(T s) { cout << s << endl, exit(0); }
template <class T> struct edge {
int from, to;
T cost;
int id;
int type;
edge(int f, int t, T c = 1, int id = -1, int ty = -1)
: from(f), to(t), cost(c), id(id), type(ty) {}
bool operator<(const edge &b) const { return cost < b.cost; }
bool operator>(const edge &b) const { return cost > b.cost; }
};
template <typename T> class graph {
protected:
vector<bool> _used;
public:
vector<vector<edge<T>>> g;
vector<edge<T>> edges;
int n;
graph(int n) : n(n) { g.resize(n), _used.resize(n); }
void clear() { g.clear(), edges.clear(); }
void resize(int n) {
this->n = n;
g.resize(n);
_used.resize(n);
}
int size() { return g.size(); }
vector<edge<T>> &operator[](int i) { return g[i]; }
virtual void add(int from, int to, T cost, int id, int ty) = 0;
virtual bool used(edge<T> &e) = 0;
virtual bool used(int id) = 0;
virtual void del(edge<T> &e) = 0;
virtual void del(int id) = 0;
};
template <typename T = ll> class digraph : public graph<T> {
public:
using graph<T>::g;
using graph<T>::n;
using graph<T>::edges;
using graph<T>::_used;
digraph(int n) : graph<T>(n) {}
void add(int f, int t, T cost = 1, int id = -1, int ty = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("digraph add");
deb(f, t, cost, id, ty);
ole();
}
if (id == -1)
id = edges.size();
g[f].emplace_back(f, t, cost, id, ty);
edges.emplace_back(f, t, cost, id, ty);
}
bool used(edge<T> &e) { return _used[e.id]; }
bool used(int id) { return _used[id]; }
void del(edge<T> &e) { _used[e.id] = _used[e.id ^ 1] = 1; }
void del(int id) { _used[id] = _used[id ^ 1] = 1; }
};
template <class T = int> class undigraph : public graph<T> {
public:
using graph<T>::g;
using graph<T>::n;
using graph<T>::edges;
using graph<T>::_used;
undigraph(int n) : graph<T>(n) {}
void add(int f, int t, T cost = 1, int id = -1, int ty = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("undigraph add");
deb(f, t, cost, id, ty);
ole();
}
if (id == -1)
id = edges.size();
g[f].emplace_back(f, t, cost, id, ty);
g[t].emplace_back(t, f, cost, id + 1, ty);
edges.emplace_back(f, t, cost, id, ty);
edges.emplace_back(t, f, cost, id + 1, ty);
}
void add(edge<T> &e) {
int f = e.from, t = e.to, ty = e.type;
T cost = e.cost;
add(f, t, cost, ty);
}
bool used(edge<T> &e) { return _used[e.id]; }
bool used(int id) { return _used[id]; }
void del(edge<T> &e) { _used[e.id] = _used[e.id ^ 1] = 1; }
void del(int id) { _used[id] = _used[id ^ 1] = 1; }
};
template <class T>
vector<T> dijkstra(const graph<T> &g, int s, int cant_arrive = -1) {
if (!(0 <= s && s < g.n)) {
debugline("dijkstra");
deb(s, g.n);
ole();
}
T initValue = MAX(T);
vector<T> dis(g.n, initValue);
priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q;
dis[s] = 0;
q.emplace(0, s);
while (q.size()) {
T nowc = q.top().fi;
int i = q.top().se;
q.pop();
if (dis[i] != nowc)
continue;
for (auto &&e : g.g[i]) {
int to = e.to;
T cost = nowc + e.cost;
if (dis[to] > cost) {
dis[to] = cost;
q.emplace(dis[to], to);
}
}
}
// 基本、たどり着かないなら-1
if (cant_arrive == -1)
for (auto &&d : dis)
if (d == initValue)
d = -1;
return dis;
}
template <class T>
vector<vector<T>> warshall(const graph<T> &g, int cant_arrive = -1) {
int n = g.n;
vector<vector<T>> dis(n, vector<T>(n, linf));
fora(e, g.edges) chmin(dis[e.from][e.to], e.cost);
rep(i, n) dis[i][i] = 0;
rep(k, n) rep(i, n) rep(j, n) chmin(dis[i][j], dis[i][k] + dis[k][j]);
// 基本、たどり着かないなら-1
if (cant_arrive == -1)
rep(i, n) rep(j, n) if (dis[i][j] == linf) dis[i][j] = -1;
return dis;
}
template <class T = int> class tree : public undigraph<T> {
public:
using undigraph<T>::g;
using undigraph<T>::n;
using undigraph<T>::edges;
using undigraph<T>::_used;
vi dep;
vi disv;
private:
bool never = 1;
int root = -1;
vector<vector<int>> par;
bool costallone;
void dfs(int v, int p, int d) {
dep[v] = d;
par[0][v] = p;
int lim = (*this)[v].size();
for (int i = 0; i < lim; i++) {
int t = g[v][i].to;
if (t == p)
con;
dfs(t, v, d + 1);
}
}
void built() {
never = 0;
n = g.size();
par.assign(30, vi(n));
dep.resize(n);
costallone = 1;
fora(e, edges) if (e.cost != 1) costallone = 0;
dfs(root, -1, 0);
rep(k, par.size() - 1) {
rep(i, n) {
if (par[k][i] == -1)
par[k + 1][i] = -1;
else
par[k + 1][i] = par[k][par[k][i]];
}
}
if (costallone)
disv = dep;
else
disv = dijkstra(*this, root);
}
int _lca(int u, int v) {
if (dep[u] > dep[v])
swap(u, v);
rep(k, par.size()) {
if ((dep[u] - dep[v]) >> k & 1) {
v = par[k][v];
}
}
if (u == v)
return u;
rer(k, par.size() - 1) {
if (par[k][u] != par[k][v]) {
u = par[k][u];
v = par[k][v];
}
}
return par[0][u];
}
int _dis(int u, int v) {
int p = _lca(u, v);
return disv[u] + disv[v] - disv[p] * 2;
}
public:
tree(int n, int root = 0) : undigraph<T>(n), root(root) {}
bool leaf(int v) { return sz(g[v]) == 1 && v != root; }
int dis(int u, int v) {
if (never) {
built();
}
return _dis(u, v);
}
int lca(int u, int v) {
if (never) {
built();
}
return _lca(u, v);
}
};
// 辺によりメモリを大量消費
// よってedgesを消している
// 頂点10^6でメモリを190MB(制限の8割)使う
// 軽量化のため、辺を持たないbig gridクラスがあってもいいかもしれない
//
template <class T = int> class grid_k6 : public undigraph<T> {
public:
using undigraph<T>::g;
using undigraph<T>::n;
using undigraph<T>::edges;
using undigraph<T>::_used;
int H, W;
int eid = 0;
void add(int f, int t, T cost = 1, int id = -1, int ty = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("grid_k6 add");
deb(f, t, cost, id, ty);
ole();
}
g[f].emplace_back(f, t, cost, eid++, ty);
g[t].emplace_back(t, f, cost, eid++, ty);
}
int getid(int h, int w) {
if (!inside(h, w, H, W))
return -1;
return W * h + w;
}
P get2(int id) { return mp(id / W, id % W); }
P operator()(int id) { return get2(id); }
int operator()(int h, int w) { return getid(h, w); }
grid_k6(int H, int W) : H(H), W(W), undigraph<T>(H * W) {
rep(h, H) {
rep(w, W) {
int f = getid(h, w);
if (w + 1 < W)
add(f, getid(h, w + 1));
if (h + 1 < H)
add(f, getid(h + 1, w));
}
}
}
grid_k6(_vvc ba, char wall = '#')
: H(sz(ba)), W(sz(ba[0])), undigraph<T>(sz(ba) * sz(ba[0])) {
rep(h, H) {
rep(w, W) {
if (ba[h][w] == wall)
con;
int f = getid(h, w);
if (w + 1 < W && ba[h][w + 1] != wall) {
add(f, getid(h, w + 1));
}
if (h + 1 < H && ba[h + 1][w] != wall) {
add(f, getid(h + 1, w));
}
}
}
}
void add(int fh, int fw, int th, int tw) {
add(getid(fh, fw), getid(th, tw));
}
};
// 左上から右下に移動できる
template <class T = int> class digrid_k6 : public digraph<T> {
public:
using digraph<T>::g;
using digraph<T>::n;
using digraph<T>::edges;
using digraph<T>::_used;
int H, W;
int eid = 0;
void add(int f, int t, T cost = 1, int id = -1, int ty = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("digrid_k6 add");
deb(f, t, cost, id, ty);
ole();
}
g[f].emplace_back(f, t, cost, eid++, ty);
}
int getid(int h, int w) {
if (!inside(h, w, H, W))
return -1;
return W * h + w;
}
P get2(int id) { return mp(id / W, id % W); }
P operator()(int id) { return get2(id); }
int operator()(int h, int w) { return getid(h, w); }
digrid_k6(int H, int W) : H(H), W(W), digraph<T>(H * W) {
rep(h, H) {
rep(w, W) {
int f = getid(h, w);
if (w + 1 < W)
add(f, getid(h, w + 1));
if (h + 1 < H)
add(f, getid(h + 1, w));
}
}
}
digrid_k6(_vvc ba, char wall = '#')
: H(sz(ba)), W(sz(ba[0])), digraph<T>(sz(ba) * sz(ba[0])) {
rep(h, H) {
rep(w, W) {
if (ba[h][w] == wall)
con;
int f = getid(h, w);
if (w + 1 < W && ba[h][w + 1] != wall) {
add(f, getid(h, w + 1));
}
if (h + 1 < H && ba[h + 1][w] != wall) {
add(f, getid(h + 1, w));
}
}
}
}
void add(int fh, int fw, int th, int tw) {
add(getid(fh, fw), getid(th, tw));
}
};
template <class T> bool nibu(const graph<T> &g) {
if (g.edges.size() == 0)
return true;
UnionFind uf(g.n * 2);
for (auto &&e : g.edges)
uf.unite(e.from, e.to + g.n), uf.unite(e.from + g.n, e.to);
rep(i, g.n) if (uf.same(i, i + g.n)) return 0;
return 1;
}
// 二部グラフを色分けした際の頂点数を返す
template <class T> vp nibug(graph<T> &g) {
vp cg;
if (!nibu(g)) {
debugline("nibu");
ole();
}
int _n = g.size();
vb _was(_n);
queue<P> q;
rep(i, _n) {
if (_was[i])
continue;
q.push(mp(i, 1));
_was[i] = 1;
int red = 0;
int coun = 0;
while (q.size()) {
int now = q.front().fi;
int col = q.front().se;
red += col;
coun++;
q.pop();
forg(gi, g[now]) {
if (_was[t])
continue;
q.push(mp(t, col ^ 1));
_was[t] = 1;
}
}
cg.push_back(mp(red, coun - red));
}
return cg;
}
// 機能拡張
vp vtop(vi &a, vi &b) {
vp res(sz(a));
rep(i, sz(a)) res[i] = mp(a[i], b[i]);
return res;
}
void ptov(vp &p, vi &a, vi &b) {
a.resize(sz(p));
b.resize(sz(p));
rep(i, sz(p)) a[i] = p[i].fi, b[i] = p[i].se;
}
template <typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>
operator+(const basic_string<_CharT, _Traits, _Alloc> &__lhs, const int __rv) {
basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
__str.append(to_string(__rv));
return __str;
}
template <typename _CharT, typename _Traits, typename _Alloc>
void operator+=(basic_string<_CharT, _Traits, _Alloc> &__lhs, const int __rv) {
__lhs += to_string(__rv);
}
template <typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>
operator+(const basic_string<_CharT, _Traits, _Alloc> &__lhs,
const signed __rv) {
basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
__str.append(to_string(__rv));
return __str;
}
template <typename _CharT, typename _Traits, typename _Alloc>
void operator+=(basic_string<_CharT, _Traits, _Alloc> &__lhs,
const signed __rv) {
__lhs += to_string(__rv);
}
template <class T, class U> void operator+=(queue<T> &a, U v) { a.push(v); }
template <class T, class U>
priority_queue<T, vector<T>, greater<T>> &
operator+=(priority_queue<T, vector<T>, greater<T>> &a, U v) {
a.push(v);
return a;
}
template <class T, class U>
priority_queue<T> &operator+=(priority_queue<T> &a, U v) {
a.push(v);
return a;
}
template <class T, class U> set<T> &operator+=(set<T> &a, U v) {
a.insert(v);
return a;
}
template <class T, class U>
set<T, greater<T>> &operator+=(set<T, greater<T>> &a, U v) {
a.insert(v);
return a;
}
template <class T, class U> vector<T> &operator+=(vector<T> &a, U v) {
a.pb(v);
return a;
}
template <class T, class U> vector<T> operator+(const vector<T> &a, U v) {
vector<T> ret = a;
ret += v;
return ret;
}
template <class T, class U> vector<T> operator+(U v, const vector<T> &a) {
vector<T> ret = a;
ret.insert(ret.begin(), v);
return ret;
}
template <class T> vector<T> &operator+=(vector<T> &a, vector<T> &b) {
fora(v, b) a += v;
return a;
}
template <class T, class U>
vector<T> &operator+=(vector<T> &a, initializer_list<U> v) {
for (auto &&va : v)
a.pb(va);
return a;
}
template <class T> vector<T> &operator-=(vector<T> &a, vector<T> &b) {
if (sz(a) != sz(b)) {
debugline("vector<T> operator-=");
deb(a);
deb(b);
ole();
}
rep(i, sz(a)) a[i] -= b[i];
return a;
}
template <class T> vector<T> operator-(vector<T> &a, vector<T> &b) {
if (sz(a) != sz(b)) {
debugline("vector<T> operator-");
deb(a);
deb(b);
ole();
}
vector<T> res(sz(a));
rep(i, sz(a)) res[i] = a[i] - b[i];
return res;
}
template <typename T> void remove(vector<T> &v, unsigned int i) {
v.erase(v.begin() + i);
}
template <typename T>
void remove(vector<T> &v, unsigned int s, unsigned int e) {
v.erase(v.begin() + s, v.begin() + e);
}
template <typename T>
void removen(vector<T> &v, unsigned int s, unsigned int n) {
v.erase(v.begin() + s, v.begin() + s + n);
}
template <typename T> void erase(vector<T> &v, unsigned int i) {
v.erase(v.begin() + i);
}
template <typename T> void erase(vector<T> &v, unsigned int s, unsigned int e) {
v.erase(v.begin() + s, v.begin() + e);
}
template <typename T>
void erasen(vector<T> &v, unsigned int s, unsigned int n) {
v.erase(v.begin() + s, v.begin() + s + n);
}
template <typename T, typename U>
void insert(vector<T> &v, unsigned int i, U t) {
v.insert(v.begin() + i, t);
}
template <typename T, typename U> void push_front(vector<T> &v, U t) {
v.insert(v.begin(), t);
}
template <typename T, typename U>
void insert(vector<T> &v, unsigned int i, vector<T> list) {
for (auto &&va : list)
v.insert(v.begin() + i++, va);
}
template <typename T, typename U>
void insert(vector<T> &v, initializer_list<U> list) {
for (auto &&va : list)
v.pb(va);
}
template <typename T, typename U>
void insert(vector<T> &v, unsigned int i, initializer_list<U> list) {
for (auto &&va : list)
v.insert(v.begin() + i++, va);
}
template <typename T> void insert(set<T> &v, vector<T> list) {
for (auto &&va : list)
v.insert(va);
}
template <typename T> void insert(set<T> &v, initializer_list<T> list) {
for (auto &&va : list)
v.insert(va);
}
// 閉路がなければtrue
bool topo(vi &res, digraph<int> &g) {
int n = g.g.size();
vi nyu(n);
rep(i, n) for (auto &&e : g[i]) nyu[e.to]++;
queue<int> st;
rep(i, n) if (nyu[i] == 0) st.push(i);
while (st.size()) {
int v = st.front();
st.pop();
res.pb(v);
fora(e, g[v]) if (--nyu[e.to] == 0) st.push(e.to);
}
return res.size() == n;
}
// 辞書順最小トポロジカルソート
bool topos(vi &res, digraph<int> &g) {
int n = g.g.size();
vi nyu(n);
rep(i, n) for (auto &&e : g[i]) nyu[e.to]++;
// 小さい順
priority_queue<int, vector<int>, greater<int>> q;
rep(i, n) if (nyu[i] == 0) q.push(i);
while (q.size()) {
int i = q.top();
q.pop();
res.pb(i);
fora(e, g[i]) if (--nyu[e.to] == 0) q.push(e.to);
}
return res.size() == n;
}
vector<string> split(const string a, const char deli) {
string b = a + deli;
int l = 0, r = 0, n = b.size();
vector<string> res;
rep(i, n) {
if (b[i] == deli) {
r = i;
if (l < r)
res.push_back(b.substr(l, r - l));
l = i + 1;
}
}
return res;
}
vector<string> split(const string a, const string deli) {
string b = a + deli;
int l = 0, r = 0, n = b.size(), dn = deli.size();
vector<string> res;
rep(i, n) {
if (i + dn <= n && b.substr(i, i + dn) == deli) {
r = i;
if (l < r)
res.push_back(b.substr(l, r - l));
i += dn - 1;
l = i + 1;
}
}
return res;
}
void yn(bool a) {
if (a)
cout << "yes" << endl;
else
cout << "no" << endl;
}
void Yn(bool a) {
if (a)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void YN(bool a) {
if (a)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void fyn(bool a) {
if (a)
cout << "yes" << endl;
else
cout << "no" << endl;
exit(0);
}
void fYn(bool a) {
if (a)
cout << "Yes" << endl;
else
cout << "No" << endl;
exit(0);
}
void fYN(bool a) {
if (a)
cout << "YES" << endl;
else
cout << "NO" << endl;
exit(0);
}
void Possible(bool a) {
if (a)
cout << "Possible" << endl;
else
cout << "Impossible" << endl;
exit(0);
}
int n, m, k, d, H, W, x, y, z, q;
int cou;
vi a, b, c;
vvi(s, 0, 0);
vvc(ba, 0, 0);
vp p;
void solve() {
cin >> n;
na(a, n);
vi res;
if (a[0] != 1)
fin(-1);
int l = 0;
rep(i, n) {
if (a[i] == 1) {
cou++;
l = i;
}
// else {
// int d = i - l;
// if (d < a[i] - 1)fin(-1);
// }
}
vvi(cu, cou, 0);
vi mav(cou);
vi der(cou);
int ci = 0;
rep(i, n) {
int j = i;
while (j < n) {
cu[ci] += a[j];
chma(mav[ci], a[j]);
if (j == n - 1 || a[j + 1] == 1)
brk;
if (a[j + 1] - a[j] > 1)
der[ci] = 1;
j++;
}
ci++;
i = j;
}
int lim = cou;
vi del(101);
rer(i, lim - 1, 1) {
if (der[i] && mav[i] >= mav[i - 1]) {
cu[i - 1] += cu[i];
del[i] = 1;
int d = -1;
rer(j, sz(cu[i - 1]) - 1, 0) {
if (cu[i - 1][j] == mav[i - 1]) {
d = j + 1;
}
}
if (d < mav[i - 1]) {
der[i - 1] = 1;
}
}
}
rer(i, cou - 1) {
if (del[i])
con;
sort(cu[i]);
fora(v, cu[i]) { res += v; }
}
rep(i, n) { insert(b, res[i] - 1, res[i]); }
rep(i, n) if (a[i] != b[i]) { fin(-1); }
rep(i, n) { cout << res[i] << endl; }
}
int my(int n, vi a) { return 0; }
int sister(int n, vi a) { return 0; }
signed main() {
solve();
#define _arg n, a
// cin>>n;
// na(a,n);
// my(_arg);
// cout << my(_arg) << endl;
#ifdef _DEBUG
bool bad = 0;
for (int i = 0, ok = 1; i < k5 && ok; i++) {
int n = rand(1, 3);
vi a = ranv(m, 1, 10);
int myres = my(_arg);
int res = sister(_arg);
ok = myres == res;
if (!ok) {
cout << n << endl;
cout << a << endl;
cout << "正解 : " << res << endl;
cout << "出力 : " << myres << endl;
bad = 1;
break;
}
}
#endif
return 0;
};
| // todo 文字数を少なくする
// #pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
using namespace std;
//@起動時
struct initon {
initon() {
cin.tie(0);
ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
srand((unsigned)clock() + (unsigned)time(NULL));
};
} __initon;
// 衝突対策
#define ws ___ws
//@必須構造
struct T {
int f, s, t;
T() { f = -1, s = -1, t = -1; }
T(int f, int s, int t) : f(f), s(s), t(t) {}
bool operator<(const T &r) const {
return f != r.f ? f < r.f : s != r.s ? s < r.s : t < r.t;
// return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 大きい順
}
bool operator>(const T &r) const {
return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t;
// return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 小さい順
}
bool operator==(const T &r) const { return f == r.f && s == r.s && t == r.t; }
bool operator!=(const T &r) const { return f != r.f || s != r.s || t != r.t; }
int operator[](int i) {
assert(i < 3);
return i == 0 ? f : i == 1 ? s : t;
}
};
struct F {
int a, b, c, d;
F() { a = -1, b = -1, c = -1, d = -1; }
F(int a, int b, int c, int d) : a(a), b(b), c(c), d(d) {}
bool operator<(const F &r) const {
return a != r.a ? a < r.a
: b != r.b ? b < r.b
: c != r.c ? c < r.c
: d < r.d;
// return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c >
// r.c : d > r.d;
}
bool operator>(const F &r) const {
return a != r.a ? a > r.a
: b != r.b ? b > r.b
: c != r.c ? c > r.c
: d > r.d;
// return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c <
// r.c : d < r.d;
}
bool operator==(const F &r) const {
return a == r.a && b == r.b && c == r.c && d == r.d;
}
bool operator!=(const F &r) const {
return a != r.a || b != r.b || c != r.c || d != r.d;
}
int operator[](int i) {
assert(i < 4);
return i == 0 ? a : i == 1 ? b : i == 2 ? c : d;
}
};
T mt(int a, int b, int c) { return T(a, b, c); }
//@マクロ省略系 型,構造
#define int long long
#define ll long long
#define double long double
#define ull unsigned long long
using dou = double;
using itn = int;
using str = string;
using bo = bool;
#define au auto
using P = pair<ll, ll>;
#define fi first
#define se second
#define vec vector
#define beg begin
#define rbeg rbegin
#define con continue
#define bre break
#define brk break
#define is ==
// マクロ省略系 コンテナ
using vi = vector<int>;
#define _overloadvvi(_1, _2, _3, _4, name, ...) name
#define vvi0() vec<vi>
#define vvi1(a) vec<vi> a
#define vvi2(a, b) vec<vi> a(b)
#define vvi3(a, b, c) vec<vi> a(b, vi(c))
#define vvi4(a, b, c, d) vec<vi> a(b, vi(c, d))
#define vvi(...) \
_overloadvvi(__VA_ARGS__, vvi4, vvi3, vvi2, vvi1, vvi0)(__VA_ARGS__)
using vl = vector<ll>;
#define _overloadvvl(_1, _2, _3, _4, name, ...) name
#define vvl1(a) vec<vl> a
#define vvl2(a, b) vec<vl> a(b)
#define vvl3(a, b, c) vec<vl> a(b, vl(c))
#define vvl4(a, b, c, d) vec<vl> a(b, vl(c, d))
#define vvl(...) _overloadvvl(__VA_ARGS__, vvl4, vvl3, vvl2, vvl1)(__VA_ARGS__)
using vb = vector<bool>;
#define _overloadvvb(_1, _2, _3, _4, name, ...) name
#define vvb1(a) vec<vb> a
#define vvb2(a, b) vec<vb> a(b)
#define vvb3(a, b, c) vec<vb> a(b, vb(c))
#define vvb4(a, b, c, d) vec<vb> a(b, vb(c, d))
#define vvb(...) _overloadvvb(__VA_ARGS__, vvb4, vvb3, vvb2, vvb1)(__VA_ARGS__)
using vs = vector<string>;
#define _overloadvvs(_1, _2, _3, _4, name, ...) name
#define vvs1(a) vec<vs> a
#define vvs2(a, b) vec<vs> a(b)
#define vvs3(a, b, c) vec<vs> a(b, vs(c))
#define vvs4(a, b, c, d) vec<vs> a(b, vs(c, d))
#define vvs(...) _overloadvvs(__VA_ARGS__, vvs4, vvs3, vvs2, vvs1)(__VA_ARGS__)
using vd = vector<double>;
#define _overloadvvd(_1, _2, _3, _4, name, ...) name
#define vvd1(a) vec<vd> a
#define vvd2(a, b) vec<vd> a(b)
#define vvd3(a, b, c) vec<vd> a(b, vd(c))
#define vvd4(a, b, c, d) vec<vd> a(b, vd(c, d))
#define vvd(...) _overloadvvd(__VA_ARGS__, vvd4, vvd3, vvd2, vvd1)(__VA_ARGS__)
using vc = vector<char>;
#define _overloadvvc(_1, _2, _3, _4, name, ...) name
#define vvc1(a) vec<vc> a
#define vvc2(a, b) vec<vc> a(b)
#define vvc3(a, b, c) vec<vc> a(b, vc(c))
#define vvc4(a, b, c, d) vec<vc> a(b, vc(c, d))
#define vvc(...) _overloadvvc(__VA_ARGS__, vvc4, vvc3, vvc2, vvc1)(__VA_ARGS__)
using vp = vector<P>;
#define _overloadvvp(_1, _2, _3, _4, name, ...) name
#define vvp1(a) vec<vp> a
#define vvp2(a, b) vec<vp> a(b)
#define vvp3(a, b, c) vec<vp> a(b, vp(c))
#define vvp4(a, b, c, d) vec<vp> a(b, vp(c, d))
using vt = vector<T>;
#define _overloadvvt(_1, _2, _3, _4, name, ...) name
#define vvt1(a) vec<vt> a
#define vvt2(a, b) vec<vt> a(b)
#define vvt3(a, b, c) vec<vt> a(b, vt(c))
#define vvt4(a, b, c, d) vec<vt> a(b, vt(c, d))
#define v3i(a, b, c, d) vector<vector<vi>> a(b, vector<vi>(c, vi(d)))
#define v3d(a, b, c, d) vector<vector<vd>> a(b, vector<vd>(c, vd(d)))
#define v3m(a, b, c, d) vector<vector<vm>> a(b, vector<vm>(c, vm(d)))
#define _vvi vector<vi>
#define _vvl vector<vl>
#define _vvb vector<vb>
#define _vvs vector<vs>
#define _vvd vector<vd>
#define _vvc vector<vc>
#define _vvp vector<vp>
#define PQ priority_queue<ll, vector<ll>, greater<ll>>
#define tos to_string
using mapi = map<int, int>;
using mapd = map<dou, int>;
using mapc = map<char, int>;
using maps = map<str, int>;
using seti = set<int>;
using setd = set<dou>;
using setc = set<char>;
using sets = set<str>;
using qui = queue<int>;
#define bset bitset
#define uset unordered_set
#define mset multiset
#define umap unordered_map
#define umapi unordered_map<int, int>
#define umapp unordered_map<P, int>
#define mmap multimap
// マクロ 繰り返し
#define _overloadrep(_1, _2, _3, _4, name, ...) name
#define _rep(i, n) for (int i = 0, _lim = n; i < _lim; i++)
#define repi(i, m, n) for (int i = m, _lim = n; i < _lim; i++)
#define repadd(i, m, n, ad) for (int i = m, _lim = n; i < _lim; i += ad)
#define rep(...) _overloadrep(__VA_ARGS__, repadd, repi, _rep, )(__VA_ARGS__)
#define _rer(i, n) for (int i = n; i >= 0; i--)
#define reri(i, m, n) for (int i = m, _lim = n; i >= _lim; i--)
#define rerdec(i, m, n, dec) for (int i = m, _lim = n; i >= _lim; i -= dec)
#define rer(...) _overloadrep(__VA_ARGS__, rerdec, reri, _rer, )(__VA_ARGS__)
#define fora(a, b) for (auto &&a : b)
#define forg(gi, ve) \
for (int gi = 0, f, t, c; gi < ve.size() && (f = ve[gi].from, t = ve[gi].to, \
c = ve[gi].cost, true); \
gi++)
#define fort(gi, ve) \
for (int gi = 0, f, t, c; gi < ve.size() && (f = ve[gi].from, t = ve[gi].to, \
c = ve[gi].cost, true); \
gi++) \
if (t != p)
// #define fort(gi, ve) for (int gi = 0, f, t, c;gi<ve.size()&& (gi+=
// (ve[gi].to==p))< ve.size() && (f = ve[gi].from,t=ve[gi].to, c =
// ve[gi].cost,true); gi++)
// マクロ 定数
#define k3 1010
#define k4 10101
#define k5 101010
#define k6 1010101
#define k7 10101010
const int inf = (int)1e9 + 100;
const ll linf = (ll)1e18 + 100;
const double eps = 1e-9;
const double PI = 3.1415926535897932384626433832795029L;
ll ma = numeric_limits<ll>::min();
ll mi = numeric_limits<ll>::max();
const int y4[] = {-1, 1, 0, 0};
const int x4[] = {0, 0, -1, 1};
const int y8[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int x8[] = {1, 0, -1, 0, 1, -1, 1, -1};
// マクロ省略形 関数等
#define arsz(a) (sizeof(a) / sizeof(a[0]))
#define sz(a) ((int)(a).size())
#define rs resize
#define mp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
//@拡張系 こう出来るべきというもの
// 埋め込み 存在を意識せずに機能を増やされているもの
namespace std {
template <> class hash<std::pair<signed, signed>> {
public:
size_t operator()(const std::pair<signed, signed> &x) const {
return hash<ll>()(((ll)x.first << 32) + x.second);
}
};
template <> class hash<std::pair<ll, ll>> {
public:
// 大きいllが渡されると、<<32でオーバーフローするがとりあえず問題ないと判断
size_t operator()(const std::pair<ll, ll> &x) const {
return hash<ll>()(((ll)x.first << 32) + x.second);
}
};
} // namespace std
istream &operator>>(istream &iss, P &a) {
iss >> a.first >> a.second;
return iss;
}
template <typename T> istream &operator>>(istream &iss, vector<T> &vec) {
for (T &x : vec)
iss >> x;
return iss;
}
ostream &operator<<(ostream &os, P p) {
os << p.fi << " " << p.se << endl;
return os;
}
ostream &operator<<(ostream &os, T p) {
os << p.f << " " << p.s << " " << p.t;
return os;
}
ostream &operator<<(ostream &os, F p) {
os << p.a << " " << p.b << " " << p.c << " " << p.d;
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
for (int i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<vector<T>> &vec) {
for (int i = 0; i < vec.size(); i++) {
for (int j = 0; j < vec[0].size(); j++) {
os << vec[i][j];
}
os << endl;
}
return os;
}
template <typename V, typename H> void resize(vector<V> &vec, const H head) {
vec.resize(head);
}
template <typename V, typename H, typename... T>
void resize(vector<V> &vec, const H &head, const T... tail) {
vec.resize(head);
for (auto &v : vec)
resize(v, tail...);
}
template <typename T, typename _Pr>
bool all_of(const vector<T> &vec, _Pr pred) {
return std::all_of(vec.begin(), vec.end(), pred);
}
template <typename T, typename _Pr>
bool any_of(const vector<T> &vec, _Pr pred) {
return std::any_of(vec.begin(), vec.end(), pred);
}
template <typename T, typename _Pr>
bool none_of(const vector<T> &vec, _Pr pred) {
return std::none_of(vec.begin(), vec.end(), pred);
}
template <typename T, typename _Pr>
const typename vector<T>::const_iterator find_if(const vector<T> &vec,
_Pr pred) {
return std::find_if(vec.begin(), vec.end(), pred);
}
template <typename T> bool contains(const vector<T> &vec, const T &val) {
return std::find(vec.begin(), vec.end(), val) != vec.end();
}
template <typename T, typename _Pr>
bool contains_if(const vector<T> &vec, _Pr pred) {
return std::find_if(vec.begin(), vec.end(), pred) != vec.end();
}
template <class T> void replace(vector<T> &a, T key, T v) {
replace(a.begin(), a.end(), key, v);
}
template <class T> bool includes(vector<T> &a, vector<T> &b) {
vi c = a;
vi d = b;
sort(all(c));
sort(all(d));
return includes(all(c), all(d));
}
template <class T> bool is_permutation(vector<T> &a, vector<T> &b) {
return is_permutation(all(a), all(b));
}
template <class T> bool next_permutation(vector<T> &a) {
return next_permutation(all(a));
}
template <class T> T pop(set<T> &set) {
T res = *set.begin();
set.erase(set.find(res));
return res;
}
template <class T> T pop(mset<T> &set) {
T res = *set.begin();
set.erase(set.find(res));
return res;
}
template <class T> T popBack(set<T> &set) {
T res = *set.rbegin();
set.erase(set.find(res));
return res;
}
template <class T> T popBack(mset<T> &set) {
T res = *set.rbegin();
set.erase(set.find(res));
return res;
}
inline void sort(string &a) { sort(a.begin(), a.end()); }
template <class T> inline void sort(vector<T> &a) { sort(a.begin(), a.end()); };
template <class T> inline void sort(vector<T> &a, int len) {
sort(a.begin(), a.begin() + len);
};
template <class T, class F> inline void sort(vector<T> &a, F f) {
sort(a.begin(), a.end(), [&](T l, T r) { return f(l) < f(r); });
};
enum ___pcomparator { fisi, fisd, fdsi, fdsd, sifi, sifd, sdfi, sdfd };
inline void sort(vector<P> &a, ___pcomparator type) {
switch (type) {
case fisi:
sort(all(a),
[&](P l, P r) { return l.fi != r.fi ? l.fi < r.fi : l.se < r.se; });
break;
case fisd:
sort(all(a),
[&](P l, P r) { return l.fi != r.fi ? l.fi < r.fi : l.se > r.se; });
break;
case fdsi:
sort(all(a),
[&](P l, P r) { return l.fi != r.fi ? l.fi > r.fi : l.se < r.se; });
break;
case fdsd:
sort(all(a),
[&](P l, P r) { return l.fi != r.fi ? l.fi > r.fi : l.se > r.se; });
break;
case sifi:
sort(all(a),
[&](P l, P r) { return l.se != r.se ? l.se < r.se : l.fi < r.fi; });
break;
case sifd:
sort(all(a),
[&](P l, P r) { return l.se != r.se ? l.se < r.se : l.fi > r.fi; });
break;
case sdfi:
sort(all(a),
[&](P l, P r) { return l.se != r.se ? l.se > r.se : l.fi < r.fi; });
break;
case sdfd:
sort(all(a),
[&](P l, P r) { return l.se != r.se ? l.se > r.se : l.fi > r.fi; });
break;
}
};
inline void sort(vector<T> &a, ___pcomparator type) {
switch (type) {
case fisi:
sort(all(a), [&](T l, T r) { return l.f != r.f ? l.f < r.f : l.s < r.s; });
break;
case fisd:
sort(all(a), [&](T l, T r) { return l.f != r.f ? l.f < r.f : l.s > r.s; });
break;
case fdsi:
sort(all(a), [&](T l, T r) { return l.f != r.f ? l.f > r.f : l.s < r.s; });
break;
case fdsd:
sort(all(a), [&](T l, T r) { return l.f != r.f ? l.f > r.f : l.s > r.s; });
break;
case sifi:
sort(all(a), [&](T l, T r) { return l.s != r.s ? l.s < r.s : l.f < r.f; });
break;
case sifd:
sort(all(a), [&](T l, T r) { return l.s != r.s ? l.s < r.s : l.f > r.f; });
break;
case sdfi:
sort(all(a), [&](T l, T r) { return l.s != r.s ? l.s > r.s : l.f < r.f; });
break;
case sdfd:
sort(all(a), [&](T l, T r) { return l.s != r.s ? l.s > r.s : l.f > r.f; });
break;
}
};
template <class T> inline void rsort(vector<T> &a) {
sort(a.begin(), a.end(), greater<T>());
};
template <class T> inline void rsort(vector<T> &a, int len) {
sort(a.begin(), a.begin() + len, greater<T>());
};
template <class U, class F> inline void rsort(vector<U> &a, F f) {
sort(a.begin(), a.end(), [&](U l, U r) { return f(l) > f(r); });
};
template <class U> inline void sortp(vector<U> &a, vector<U> &b) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
sort(c);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
;
}
};
// F = T<T>
// 例えばreturn p.fi + p.se;
template <class U, class F> inline void sortp(vector<U> &a, vector<U> &b, F f) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
sort(c, f);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
}
};
template <class U, class F>
inline void sortp(vector<U> &a, vector<U> &b, char type) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
sort(c, type);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
}
};
template <class U> inline void rsortp(vector<U> &a, vector<U> &b) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
rsort(c);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
}
};
template <class U, class F>
inline void rsortp(vector<U> &a, vector<U> &b, F f) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
rsort(c, f);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
}
};
template <class U> inline void sortt(vector<U> &a, vector<U> &b, vector<U> &c) {
vt r;
int n = sz(a);
assert(n == sz(b));
assert(n == sz(c));
rep(i, n) r.eb(a[i], b[i], c[i]);
sort(r);
rep(i, n) {
a[i] = r[i].f;
b[i] = r[i].s;
c[i] = r[i].t;
}
};
template <class U, class F>
inline void sortt(vector<U> &a, vector<U> &b, vector<U> &c, F f) {
vt r;
int n = sz(a);
assert(n == sz(b));
assert(n == sz(c));
rep(i, n) r.eb(a[i], b[i], c[i]);
sort(r, f);
rep(i, n) {
a[i] = r[i].f;
b[i] = r[i].s;
c[i] = r[i].t;
}
};
template <class U, class F>
inline void rsortt(vector<U> &a, vector<U> &b, vector<U> &c, F f) {
vt r;
int n = sz(a);
assert(n == sz(b));
assert(n == sz(c));
rep(i, n) r.eb(a[i], b[i], c[i]);
rsort(r, f);
rep(i, n) {
a[i] = r[i].f;
b[i] = r[i].s;
c[i] = r[i].t;
}
};
template <class T> inline void sort2(vector<vector<T>> &a) {
for (int i = 0, n = a.size(); i < n; i++)
sort(a[i]);
}
template <class T> inline void rsort2(vector<vector<T>> &a) {
for (int i = 0, n = a.size(); i < n; i++)
rsort(a[i]);
}
template <typename A, size_t N, typename T> void fill(A (&a)[N], const T &v) {
rep(i, N) a[i] = v;
}
template <typename A, size_t N, size_t O, typename T>
void fill(A (&a)[N][O], const T &v) {
rep(i, N) rep(j, O) a[i][j] = v;
}
template <typename A, size_t N, size_t O, size_t P, typename T>
void fill(A (&a)[N][O][P], const T &v) {
rep(i, N) rep(j, O) rep(k, P) a[i][j][k] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, typename T>
void fill(A (&a)[N][O][P][Q], const T &v) {
rep(i, N) rep(j, O) rep(k, P) rep(l, Q) a[i][j][k][l] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
typename T>
void fill(A (&a)[N][O][P][Q][R], const T &v) {
rep(i, N) rep(j, O) rep(k, P) rep(l, Q) rep(m, R) a[i][j][k][l][m] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
size_t S, typename T>
void fill(A (&a)[N][O][P][Q][R][S], const T &v) {
rep(i, N) rep(j, O) rep(k, P) rep(l, Q) rep(m, R) rep(n, S)
a[i][j][k][l][m][n] = v;
}
template <typename V, typename T> void fill(V &xx, const T vall) { xx = vall; }
template <typename V, typename T> void fill(vector<V> &vecc, const T vall) {
for (auto &&vx : vecc)
fill(vx, vall);
}
//@汎用便利関数 入力
template <typename T = int> T _in() {
T x;
cin >> x;
return (x);
}
#define _overloadin(_1, _2, _3, _4, name, ...) name
#define in0() _in()
#define in1(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define in4(a, b, c, d) cin >> a >> b >> c >> d
#define in(...) _overloadin(__VA_ARGS__, in4, in3, in2, in1, in0)(__VA_ARGS__)
#define _overloaddin(_1, _2, _3, _4, name, ...) name
#define din1(a) \
int a; \
cin >> a
#define din2(a, b) \
int a, b; \
cin >> a >> b
#define din3(a, b, c) \
int a, b, c; \
cin >> a >> b >> c
#define din4(a, b, c, d) \
int a, b, c, d; \
cin >> a >> b >> c >> d
#define din(...) _overloadin(__VA_ARGS__, din4, din3, din2, din1)(__VA_ARGS__)
#define _overloaddind(_1, _2, _3, _4, name, ...) name
#define din1d(a) \
int a; \
cin >> a; \
a--
#define din2d(a, b) \
int a, b; \
cin >> a >> b; \
a--, b--
#define din3d(a, b, c) \
int a, b, c; \
cin >> a >> b >> c; \
a--, b--, c--
#define din4d(a, b, c, d) \
int a, b, c, d; \
cin >> a >> b >> c >> d; \
; \
a--, b--, c--, d--
#define dind(...) \
_overloaddind(__VA_ARGS__, din4d, din3d, din2d, din1d)(__VA_ARGS__)
#define _overloadout(_1, _2, _3, _4, name, ...) name
#define out1(a) cout << a << endl
#define out2(a, b) cout << a << " " << b << endl
#define out3(a, b, c) cout << a << " " << b << " " << c << endl
#define out4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define out(...) _overloadout(__VA_ARGS__, out4, out3, out2, out1)(__VA_ARGS__)
string sin() { return _in<string>(); }
ll lin() { return _in<ll>(); }
#define na(a, n) \
a.resize(n); \
rep(i, n) cin >> a[i];
#define nao(a, n) \
a.resize(n + 1); \
rep(i, n) cin >> a[i + 1];
#define nad(a, n) \
a.resize(n); \
rep(i, n) { \
cin >> a[i]; \
a[i]--; \
}
#define na2(a, b, n) \
a.resize(n), b.resize(n); \
rep(i, n) cin >> a[i] >> b[i];
#define na2d(a, b, n) \
a.resize(n), b.resize(n); \
rep(i, n) { \
cin >> a[i] >> b[i]; \
a[i]--, b[i]--; \
}
#define na3(a, b, c, n) \
a.resize(n), b.resize(n), c.resize(n); \
rep(i, n) cin >> a[i] >> b[i] >> c[i];
#define na3d(a, b, c, n) \
a.resize(n), b.resize(n), c.resize(n); \
rep(i, n) { \
cin >> a[i] >> b[i] >> c[i]; \
a[i]--, b[i]--, c[i]--; \
}
#define nt(a, h, w) \
resize(a, h, w); \
rep(hi, h) rep(wi, w) cin >> a[hi][wi];
#define ntd(a, h, w) \
rs(a, h, w); \
rep(hi, h) rep(wi, w) cin >> a[hi][wi], a[hi][wi]--;
#define ntp(a, h, w) \
fill(a, '#'); \
rep(hi, 1, h + 1) rep(wi, 1, w + 1) cin >> a[hi][wi];
// デバッグ
#define sp << " " <<
#define debugName(VariableName) #VariableName
#define _deb1(x) cerr << debugName(x) << " = " << x << endl
#define _deb2(x, y) \
cerr << debugName(x) << " = " << x << ", " << debugName(y) << " = " << y \
<< endl
#define _deb3(x, y, z) \
cerr << debugName(x) << " = " << x << ", " << debugName(y) << " = " << y \
<< ", " debugName(z) << " = " << z << endl
#define _deb4(x, y, z, a) \
cerr << debugName(x) << " = " << x << ", " << debugName(y) << " = " << y \
<< ", " << debugName(z) << " = " << z << ", " << debugName(a) << " = " \
<< a << endl
#define _deb5(x, y, z, a, b) \
cerr << debugName(x) << " = " << x << ", " << debugName(y) << " = " << y \
<< ", " << debugName(z) << " = " << z << ", " << debugName(a) << " = " \
<< a << ", " << debugName(b) << " = " << b << endl
#define _overloadebug(_1, _2, _3, _4, _5, name, ...) name
#define debug(...) \
_overloadebug(__VA_ARGS__, _deb5, _deb4, _deb3, _deb2, _deb1)(__VA_ARGS__)
#define deb(...) \
_overloadebug(__VA_ARGS__, _deb5, _deb4, _deb3, _deb2, _deb1)(__VA_ARGS__)
#define debugline(x) \
cerr << x << " " \
<< "(L:" << __LINE__ << ")" << '\n'
// よく使うクラス、構造体
class UnionFind {
public:
vi par, rank, sizes;
int n, trees;
UnionFind(int n) : n(n), trees(n) {
par.resize(n), rank.resize(n), sizes.resize(n);
rep(i, n) par[i] = i, sizes[i] = 1;
}
int root(int x) {
if (par[x] == x)
return x;
else
return par[x] = root(par[x]);
}
int find(int x) { return root(x); }
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return;
if (rank[x] < rank[y])
swap(x, y);
trees--;
par[y] = x;
sizes[x] += sizes[y];
if (rank[x] == rank[y])
rank[x]++;
}
bool same(int x, int y) { return root(x) == root(y); }
int size(int x) { return sizes[root(x)]; }
// 順不同 umapなので
vec<vi> sets() {
vec<vi> res(trees);
umap<int, vi> map;
rep(i, n) map[root(i)].push_back(i);
int i = 0;
for (auto &&p : map) {
int r = p.fi;
res[i].push_back(r);
for (auto &&v : p.se) {
if (r == v)
continue;
res[i].push_back(v);
}
i++;
}
return res;
}
};
using bint = __int128;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
if (s) {
__uint128_t tmp = value < 0 ? -value : value;
char buffer[128];
char *d = std::end(buffer);
do {
--d;
*d = "0123456789"[tmp % 10];
tmp /= 10;
} while (tmp != 0);
if (value < 0) {
--d;
*d = '-';
}
int len = std::end(buffer) - d;
if (dest.rdbuf()->sputn(d, len) != len) {
dest.setstate(std::ios_base::badbit);
}
}
return dest;
}
__int128 toi128(string &s) {
__int128 ret = 0;
for (int i = 0; i < s.length(); i++)
if ('0' <= s[i] && s[i] <= '9')
ret = 10 * ret + s[i] - '0';
return ret;
}
template <typename T> T minv(T a, T m);
template <typename T> class Modular {
public:
using Type = typename decay<decltype(T::value)>::type;
constexpr Modular() : value() {}
template <typename U> Modular(const U &x) { value = normalize(x); }
template <typename U> static Type normalize(const U &x) {
Type v;
if (-mod() <= x && x < mod())
v = static_cast<Type>(x);
else
v = static_cast<Type>(x % mod());
if (v < 0)
v += mod();
return v;
}
const Type &operator()() const { return value; }
template <typename U> explicit operator U() const {
return static_cast<U>(value);
}
constexpr static Type mod() { return T::value; }
Modular &operator+=(const Modular &other) {
if ((value += other.value) >= mod())
value -= mod();
return *this;
}
Modular &operator-=(const Modular &other) {
if ((value -= other.value) < 0)
value += mod();
return *this;
}
template <typename U> Modular &operator+=(const U &other) {
return *this += Modular(other);
}
template <typename U> Modular &operator-=(const U &other) {
return *this -= Modular(other);
}
Modular &operator++() { return *this += 1; }
Modular &operator--() { return *this -= 1; }
Modular operator++(signed) {
Modular result(*this);
*this += 1;
return result;
}
Modular operator--(signed) {
Modular result(*this);
*this -= 1;
return result;
}
Modular operator-() const { return Modular(-value); }
template <typename U = T>
typename enable_if<is_same<typename Modular<U>::Type, signed>::value,
Modular>::type &
operator*=(const Modular &rhs) {
#ifdef _WIN32
uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);
uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x),
d, m;
asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(mod()));
value = m;
#else
value = normalize(static_cast<int64_t>(value) *
static_cast<int64_t>(rhs.value));
#endif
return *this;
}
template <typename U = T>
typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value,
Modular>::type &
operator*=(const Modular &rhs) {
int64_t q =
static_cast<int64_t>(static_cast<double>(value) * rhs.value / mod());
value = normalize(value * rhs.value - q * mod());
return *this;
}
template <typename U = T>
typename enable_if<!is_integral<typename Modular<U>::Type>::value,
Modular>::type &
operator*=(const Modular &rhs) {
value = normalize(value * rhs.value);
return *this;
}
Modular &operator/=(const Modular &other) {
return *this *= Modular(minv(other.value, mod()));
}
template <typename U>
friend bool operator==(const Modular<U> &lhs, const Modular<U> &rhs);
template <typename U>
friend bool operator<(const Modular<U> &lhs, const Modular<U> &rhs);
template <typename U>
friend std::istream &operator>>(std::istream &stream, Modular<U> &number);
private:
Type value;
};
template <typename T>
bool operator==(const Modular<T> &lhs, const Modular<T> &rhs) {
return lhs.value == rhs.value;
}
template <typename T, typename U>
bool operator==(const Modular<T> &lhs, U rhs) {
return lhs == Modular<T>(rhs);
}
template <typename T, typename U>
bool operator==(U lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) == rhs;
}
template <typename T>
bool operator!=(const Modular<T> &lhs, const Modular<T> &rhs) {
return !(lhs == rhs);
}
template <typename T, typename U>
bool operator!=(const Modular<T> &lhs, U rhs) {
return !(lhs == rhs);
}
template <typename T, typename U>
bool operator!=(U lhs, const Modular<T> &rhs) {
return !(lhs == rhs);
}
template <typename T>
bool operator<(const Modular<T> &lhs, const Modular<T> &rhs) {
return lhs.value < rhs.value;
}
template <typename T>
Modular<T> operator+(const Modular<T> &lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) += rhs;
}
template <typename T, typename U>
Modular<T> operator+(const Modular<T> &lhs, U rhs) {
return Modular<T>(lhs) += rhs;
}
template <typename T, typename U>
Modular<T> operator+(U lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) += rhs;
}
template <typename T>
Modular<T> operator-(const Modular<T> &lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) -= rhs;
}
template <typename T, typename U>
Modular<T> operator-(const Modular<T> &lhs, U rhs) {
return Modular<T>(lhs) -= rhs;
}
template <typename T, typename U>
Modular<T> operator-(U lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) -= rhs;
}
template <typename T>
Modular<T> operator*(const Modular<T> &lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) *= rhs;
}
template <typename T, typename U>
Modular<T> operator*(const Modular<T> &lhs, U rhs) {
return Modular<T>(lhs) *= rhs;
}
template <typename T, typename U>
Modular<T> operator*(U lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) *= rhs;
}
template <typename T>
Modular<T> operator/(const Modular<T> &lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) /= rhs;
}
template <typename T, typename U>
Modular<T> operator/(const Modular<T> &lhs, U rhs) {
return Modular<T>(lhs) /= rhs;
}
template <typename T, typename U>
Modular<T> operator/(U lhs, const Modular<T> &rhs) {
return Modular<T>(lhs) /= rhs;
}
constexpr signed MOD = 1000000007;
using mint = Modular<std::integral_constant<decay<decltype(MOD)>::type, MOD>>;
mint com(int n, int r) {
const int NUM_ = 1400001;
static ll fac[NUM_ + 1], finv[NUM_ + 1], inv[NUM_ + 1];
if (fac[0] == 0) {
inv[1] = fac[0] = finv[0] = 1;
for (int i = 2; i <= NUM_; ++i)
inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
for (int i = 1; i <= NUM_; ++i)
fac[i] = fac[i - 1] * i % MOD, finv[i] = finv[i - 1] * inv[i] % MOD;
}
if (r < 0 || r > n)
return 0;
return mint(finv[r] * fac[n] % MOD * finv[n - r]);
}
mint ncr(int n, int r) { return com(n, r); }
mint nhr(int n, int r) { return com(n + r - 1, r); }
template <typename T> T minv(T a, T m) {
T u = 0, v = 1;
while (a != 0) {
T t = m / a;
m -= t * a;
swap(a, m);
u -= t * v;
swap(u, v);
}
assert(m == 1);
return u;
}
template <typename T, typename U>
Modular<T> mpow(const Modular<T> &a, const U &b) {
assert(b >= 0);
int x = a(), res = 1;
U p = b;
while (p > 0) {
if (p & 1)
(res *= x) %= MOD;
(x *= x) %= MOD;
p >>= 1;
}
return res;
}
template <typename T, typename U> Modular<T> mpow(const T &a, const U &b) {
assert(b >= 0);
int x = a, res = 1;
U p = b;
while (p > 0) {
if (p & 1)
(res *= x) %= MOD;
(x *= x) %= MOD;
p >>= 1;
}
return res;
}
template <typename T> string to_string(const Modular<T> &number) {
return to_string(number());
}
template <typename T>
std::ostream &operator<<(std::ostream &stream, const Modular<T> &number) {
return stream << number();
}
template <typename T>
std::istream &operator>>(std::istream &stream, Modular<T> &number) {
typename common_type<typename Modular<T>::Type, int64_t>::type x;
stream >> x;
number.value = Modular<T>::normalize(x);
return stream;
}
using PM = pair<mint, mint>;
using vm = vector<mint>;
#define _overloadvvm(_1, _2, _3, _4, name, ...) name
#define vvm1(a) vec<vm> a
#define vvm2(a, b) vec<vm> a(b)
#define vvm3(a, b, c) vec<vm> a(b, vm(c))
#define vvm4(a, b, c, d) vec<vm> a(b, vm(c, d))
#define vvm(...) _overloadvvm(__VA_ARGS__, vvm4, vvm3, vvm2, vvm1)(__VA_ARGS__)
vb isPrime;
vi primes;
void setPrime() {
int len = 4010101;
isPrime.resize(4010101);
fill(isPrime, true);
isPrime[0] = isPrime[1] = false;
for (int i = 2; i <= sqrt(len) + 5; ++i) {
if (!isPrime[i])
continue;
for (int j = 2; i * j < len; ++j) {
isPrime[i * j] = false;
}
}
rep(i, len) if (isPrime[i]) primes.pb(i);
}
// 幾何 Pをcomplexとして扱う
bool eq(double a, double b) { return fabs(a - b) < eps; }
using C = complex<double>;
C rot(C &a, dou th) { return a * C(cos(th), sin(th)); }
dou inpro(C &a, C &b) { return real(a * conj(b)); }
// 90度回転させて内積が0なら平行
bool line(C a, C b, C c) {
C ab = b - a;
C ac = c - a;
// 複素数の掛け算は回転
ab *= C(0, 1);
return eq(inpro(ab, ac), 0);
}
bool line(P a, P b, P c) {
return line(C(a.fi, a.se), C(b.fi, b.se), C(c.fi, c.se));
}
bool line(int xa, int ya, int xb, int yb, int xc, int yc) {
C a = C(xa, ya);
C b = C(xb, yb);
C c = C(xc, yc);
return line(a, b, c);
}
// 便利関数
// テスト用
char ranc() { return (char)('a' + rand() % 26); }
int rand(int min, int max) {
assert(min <= max);
if (min >= 0 && max >= 0) {
return rand() % (max + 1 - min) + min;
} else if (max < 0) {
return -rand(-max, -min);
} else {
//+
if (rand() % 2) {
return rand(0, max);
//-
} else {
return -rand(0, -min);
}
}
}
vi ranv(int n, int min, int max) {
vi v(n);
rep(i, n) v[i] = rand(min, max);
return v;
}
// 単調増加
vi ranvi(int n, int min, int max) {
vi v(n);
bool bad = 1;
while (bad) {
bad = 0;
v.resize(n);
rep(i, n) {
if (i && min > max - v[i - 1]) {
bad = 1;
break;
}
if (i)
v[i] = v[i - 1] + rand(min, max - v[i - 1]);
else
v[i] = rand(min, max);
}
}
return v;
}
void ranvlr(int n, int min, int max, vi &l, vi &r) {
l.resize(n);
r.resize(n);
rep(i, n) {
l[i] = rand(min, max);
r[i] = l[i] + rand(0, max - l[i]);
}
}
// 便利 汎用
// strを整数として比較
string smax(str &a, str b) {
if (sz(a) < sz(b)) {
return b;
} else if (sz(a) > sz(b)) {
return a;
} else {
rep(i, sz(a)) {
if (a[i] < b[i]) {
return b;
} else if (a[i] > b[i])
return a;
}
}
return a;
}
// strを整数として比較
string smin(str &a, str b) {
if (sz(a) < sz(b)) {
return a;
} else if (sz(a) > sz(b)) {
return b;
} else {
rep(i, sz(a)) {
if (a[i] < b[i]) {
return a;
} else if (a[i] > b[i])
return b;
}
}
return a;
}
template <typename V, typename T> int find(vector<V> &a, const T key) {
rep(i, sz(a)) if (a[i] == key) return i;
return -1;
}
template <typename V, typename T> P find(vector<vector<V>> &a, const T key) {
rep(i, sz(a)) rep(j, sz(a[0])) if (a[i][j] == key) return mp(i, j);
return mp(-1, -1);
}
template <typename V, typename U>
T find(vector<vector<vector<V>>> &a, const U key) {
rep(i, sz(a)) rep(j, sz(a[0]))
rep(k, sz(a[0][0])) if (a[i][j][k] == key) return mt(i, j, k);
return mt(-1, -1, -1);
}
template <typename V, typename T> int count(V &a, const T k) { return a == k; }
template <typename V, typename T> int count(vector<V> &a, const T k) {
int ret = 0;
fora(v, a) ret += count(v, k);
return ret;
}
template <typename V> int count_odd(V &a) { return a % 2; }
template <typename V> int count_odd(vector<V> &a) {
int ret = 0;
fora(v, a) ret += count_odd(v);
return ret;
}
template <typename V> int count_even(V &a) { return a % 2 == 0; }
template <typename V> int count_even(vector<V> &a) {
int ret = 0;
fora(v, a) ret += count_even(v);
return ret;
}
// algorythm
void iota(vector<int> &ve, int s, int n) {
ve.resize(n);
iota(all(ve), s);
}
vi iota(int s, int n) {
vi ve(n);
iota(all(ve), s);
return ve;
}
// 便利 数学
int mod(int a, int m) { return (a % m + m) % m; }
int pow(int a) { return a * a; };
ll fact(int v) { return v <= 1 ? 1 : v * fact(v - 1); }
ll comi(int n, int r) {
assert(n < 100);
static vvi(pas, 100, 100);
if (pas[0][0])
return pas[n][r];
pas[0][0] = 1;
rep(i, 1, 100) {
pas[i][0] = 1;
rep(j, 1, i + 1) pas[i][j] = pas[i - 1][j - 1] + pas[i - 1][j];
}
return pas[n][r];
}
void ole() {
#ifdef _DEBUG
debugline("ole");
exit(0);
#endif
string a = "a";
rep(i, 30) a += a;
rep(i, 1 << 17) cout << a << endl;
cout << "OLE 出力長制限超過" << endl;
exit(0);
}
void tle() {
while (inf)
cout << inf << endl;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll gcd(vi b) {
ll res = b[0];
for (auto &&v : b)
res = gcd(v, res);
return res;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll rev(ll a) {
ll res = 0;
while (a) {
res *= 10;
res += a % 10;
a /= 10;
}
return res;
}
template <class T> vector<T> rev(vector<T> &a) {
vector<T> ret = a;
reverse(all(ret));
return ret;
}
ll ceil(ll a, ll b) {
if (b == 0) {
debugline("ceil");
deb(a, b);
ole();
return -1;
} else
return (a + b - 1) / b;
}
ll sqrt(ll a) {
if (a < 0) {
debugline("sqrt");
deb(a);
ole();
}
ll res = (ll)std::sqrt(a);
while (res * res < a)
res++;
return res;
}
double log(double e, double x) { return log(x) / log(e); }
ll sig(ll t) { return (1 + t) * t / 2; }
ll sig(ll s, ll t) { return (s + t) * (t - s + 1) / 2; }
vi divisors(int v) {
vi res;
double lim = std::sqrt(v);
for (int i = 1; i <= lim; ++i) {
if (v % i == 0) {
res.pb(i);
if (i != v / i)
res.pb(v / i);
}
}
return res;
}
vi factorization(int v) {
int tv = v;
vi res;
if (isPrime.size() == 0)
setPrime();
for (auto &&p : primes) {
if (v % p == 0)
res.push_back(p);
while (v % p == 0) {
v /= p;
}
if (v == 1 || p * p > tv)
break;
}
if (v > 1)
res.pb(v);
return res;
}
unordered_map<int, int> factorizationMap(int v) {
int tv = v;
unordered_map<int, int> res;
if (isPrime.size() == 0)
setPrime();
for (auto &&p : primes) {
while (v % p == 0) {
res[p]++;
v /= p;
}
if (v == 1 || p * p > tv)
break;
}
if (v > 1)
res[v]++;
return res;
}
int get(int a, int keta) { return (a / (int)pow(10, keta)) % 10; }
int keta(int v) {
int cou = 0;
while (v) {
cou++, v %= 10;
}
return cou;
}
int dsum(int v) {
int ret = 0;
for (; v; v /= 10)
ret += v % 10;
return ret;
}
int sumd(int v) { return dsum(v); }
// 変換系
template <class T, class U> vector<T> keys(vector<pair<T, U>> a) {
vector<T> res;
for (auto &&k : a)
res.pb(k.fi);
return res;
}
template <class T, class U> vector<U> keys(map<T, U> a) {
vector<U> res;
for (auto &&k : a)
res.pb(k.fi);
return res;
}
template <class T, class U> vector<U> keys(umap<T, U> a) {
vector<U> res;
for (auto &&k : a)
res.pb(k.fi);
return res;
}
template <class T, class U> vector<U> values(vector<pair<T, U>> a) {
vector<U> res;
for (auto &&k : a)
res.pb(k.se);
return res;
}
template <class T, class U> vector<T> values(map<T, U> a) {
vector<T> res;
for (auto &&k : a)
res.pb(k.se);
return res;
}
template <class T, class U> vector<T> values(umap<T, U> a) {
vector<T> res;
for (auto &&k : a)
res.pb(k.se);
return res;
}
vi list(int a) {
vi res;
while (a) {
res.insert(res.begin(), a % 10);
a /= 10;
}
return res;
}
template <class T, class U> bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class U> bool chmax(const U &b) { return chmax(ma, b); }
template <class T, class U> bool chmin(T &a, const U &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <class U> bool chmin(const U &b) { return chmin(mi, b); }
#define chmi chmin
#define chma chmax
template <class T> T min(T a, signed b) { return a < b ? a : b; }
template <class T> T max(T a, signed b) { return a < b ? b : a; }
template <class T> T min(T a, T b, T c) {
return a >= b ? b >= c ? c : b : a >= c ? c : a;
}
template <class T> T max(T a, T b, T c) {
return a <= b ? b <= c ? c : b : a <= c ? c : a;
}
template <class T> T min(vector<T> a) { return *min_element(all(a)); }
template <class T> T min(vector<T> a, int n) {
return *min_element(a.begin(), a.begin() + min(n, sz(a)));
}
template <class T> T min(vector<T> a, int s, int n) {
return *min_element(a.begin() + s, a.begin() + min(n, sz(a)));
}
template <class T> T max(vector<T> a) { return *max_element(all(a)); }
template <class T> T max(vector<T> a, int n) {
return *max_element(a.begin(), a.begin() + min(n, sz(a)));
}
template <class T> T max(vector<T> a, int s, int n) {
return *max_element(a.begin() + s, a.begin() + min(n, sz(a)));
}
template <typename A, size_t N> A max(A (&a)[N]) {
A res = a[0];
rep(i, N) res = max(res, a[i]);
return res;
}
template <typename A, size_t N, size_t O> A max(A (&a)[N][O]) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P> A max(A (&a)[N][O][P]) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q>
A max(A (&a)[N][O][P][Q], const T &v) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R>
A max(A (&a)[N][O][P][Q][R]) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
size_t S>
A max(A (&a)[N][O][P][Q][R][S]) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N> A min(A (&a)[N]) {
A res = a[0];
rep(i, N) res = min(res, a[i]);
return res;
}
template <typename A, size_t N, size_t O> A min(A (&a)[N][O]) {
A res = min(a[0]);
rep(i, N) res = min(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P> A min(A (&a)[N][O][P]) {
A res = min(a[0]);
rep(i, N) res = min(res, min(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q>
A min(A (&a)[N][O][P][Q], const T &v) {
A res = min(a[0]);
rep(i, N) res = min(res, min(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R>
A min(A (&a)[N][O][P][Q][R]) {
A res = min(a[0]);
rep(i, N) res = min(res, min(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
size_t S>
A min(A (&a)[N][O][P][Q][R][S]) {
A res = min(a[0]);
rep(i, N) res = min(res, min(a[i]));
return res;
}
template <class T> T sum(vector<T> v, int len = -1) {
if (len == -1)
len = v.size();
T res = 0;
chmin(len, v.size());
rep(i, len) res += v[i];
return res;
}
template <class T> T sum(vector<vector<T>> &v, int h = -1, int w = -1) {
if (h == -1)
h = v.size();
if (w == -1)
w = v[0].size();
T res = 0;
chmin(h, v.size());
chmin(w, v[0].size());
rep(i, h) rep(j, w) res += v[i][j];
return res;
}
P sump(vp &v, int len = -1) {
if (len == -1)
len = v.size();
P res = {0, 0};
chmin(len, v.size());
rep(i, len) {
res.fi += v[i].fi;
res.se += v[i].se;
}
return res;
}
/// 要素が0の時、返り値は0か1か
template <class T> T mul(vector<T> &v, int len = -1) {
if (len == -1)
len = v.size();
T res = 1;
chmin(len, v.size());
rep(i, len) res *= v[i];
return res;
}
void clear(PQ &q) {
while (q.size())
q.pop();
}
template <class T> void clear(queue<T> &q) {
while (q.size())
q.pop();
}
template <class T> T *negarr(int size) {
T *body = (T *)malloc((size * 2 + 1) * sizeof(T));
return body + size;
}
template <class T> T *negarr2(int h, int w) {
double **dummy1 = new double *[2 * h + 1];
double *dummy2 = new double[(2 * h + 1) * (2 * w + 1)];
dummy1[0] = dummy2 + w;
for (int i = 1; i <= 2 * h + 1; i++) {
dummy1[i] = dummy1[i - 1] + 2 * w + 1;
}
double **a = dummy1 + h;
}
// imoは0-indexed
// ruiは1-indexed
template <class T> vector<T> imo(vector<T> &v) {
vector<T> ret = v;
rep(i, sz(ret) - 1) ret[i + 1] += ret[i];
return ret;
}
template <class T> vector<T> imomi(vector<T> &v) {
vector<T> ret = v;
rep(i, sz(ret) - 1) chmin(ret[i + 1], ret[i]);
return ret;
}
template <class T> struct ruiC {
const vector<T> rui;
ruiC(vector<T> &ru) : rui(ru) {}
T operator()(int l, int r) {
assert(l <= r);
return rui[r] - rui[l];
}
T operator[](int i) { return rui[i]; }
};
template <class T> struct rruic {
const T *rrui;
rruic(T *ru) : rrui(ru) {}
// n-1から-1へ
T operator()(int l, int r) {
assert(l >= r);
return rrui[r] - rrui[l];
}
T operator[](int i) { return rrui[i]; }
};
template <class T> vector<T> ruiv(vector<T> &a) {
vector<T> ret(a.size() + 1);
rep(i, a.size()) ret[i + 1] = ret[i] + a[i];
return ret;
}
template <class T> ruiC<T> ruic(vector<T> &a) {
vector<T> ret = ruiv(a);
return ruiC<T>(ret);
}
template <class T> vector<T> ruim(vector<T> &a) {
vector<T> res(a.size() + 1, 1);
rep(i, a.size()) res[i + 1] = res[i] * a[i];
return res;
}
// template<class T> T *rrui(vector<T> &a) {
// 右から左にかけての半開区間 (-1 n-1]
template <class T> rruic<T> rrui(vector<T> &a) {
int len = a.size();
T *body = (T *)malloc((len + 1) * sizeof(T));
T *res = body + 1;
rer(i, len - 1) res[i - 1] = res[i] + a[i];
return rruic<T>(res);
}
// 掛け算
template <class T> T *rruim(vector<T> &a) {
int len = a.size();
T *body = (T *)malloc((len + 1) * sizeof(T));
T *res = body + 1;
res[len - 1] = 1;
rer(i, len - 1) res[i - 1] = res[i] * a[i];
return res;
}
template <class T, class U> void inc(T &a, U v = 1) { a += v; }
template <class T, class U> void inc(vector<T> &a, U v = 1) {
for (auto &u : a)
inc(u, v);
}
template <class T> void inc(vector<T> &a) {
for (auto &u : a)
inc(u, 1);
}
template <class T, class U> void plus(T &a, U v = 1) { a += v; }
template <class T, class U> void plus(vector<T> &a, U v = 1) {
for (auto &u : a)
inc(u, v);
}
template <class T> void plus(vector<T> &a) {
for (auto &u : a)
inc(u, 1);
}
template <class T, class U> void dec(T &a, U v = 1) { a -= v; }
template <class T, class U> void dec(vector<T> &a, U v = 1) {
for (auto &u : a)
dec(u, v);
}
template <class T> void dec(vector<T> &a) {
for (auto &u : a)
dec(u, 1);
}
template <class T, class U> void minu(T &a, U v = 1) { a -= v; }
template <class T, class U> void minu(vector<T> &a, U v = 1) {
for (auto &u : a)
dec(u, v);
}
template <class T> void minu(vector<T> &a) {
for (auto &u : a)
dec(u, 1);
}
inline bool inside(int h, int w, int H, int W) {
return h >= 0 && w >= 0 && h < H && w < W;
}
inline bool inside(int v, int l, int r) { return l <= v && v < r; }
#define ins inside
ll u(ll a) { return a < 0 ? 0 : a; }
template <class T> vector<T> u(const vector<T> &a) {
vector<T> ret = a;
fora(v, ret) v = u(v);
return ret;
}
#define MIN(a) numeric_limits<a>::min()
#define MAX(a) numeric_limits<a>::max()
ll goldd(ll left, ll right, function<ll(ll)> calc) {
double GRATIO = 1.6180339887498948482045868343656;
ll lm = left + (ll)((right - left) / (GRATIO + 1.0));
ll rm = lm + (ll)((right - lm) / (GRATIO + 1.0));
ll fl = calc(lm);
ll fr = calc(rm);
while (right - left > 10) {
if (fl < fr) {
right = rm;
rm = lm;
fr = fl;
lm = left + (ll)((right - left) / (GRATIO + 1.0));
fl = calc(lm);
} else {
left = lm;
lm = rm;
fl = fr;
rm = lm + (ll)((right - lm) / (GRATIO + 1.0));
fr = calc(rm);
}
}
ll minScore = MAX(ll);
ll resIndex = left;
for (ll i = left; i < right + 1; i++) {
ll score = calc(i);
if (minScore > score) {
minScore = score;
resIndex = i;
}
}
return resIndex;
}
ll goldt(ll left, ll right, function<ll(ll)> calc) {
double GRATIO = 1.6180339887498948482045868343656;
ll lm = left + (ll)((right - left) / (GRATIO + 1.0));
ll rm = lm + (ll)((right - lm) / (GRATIO + 1.0));
ll fl = calc(lm);
ll fr = calc(rm);
while (right - left > 10) {
if (fl > fr) {
right = rm;
rm = lm;
fr = fl;
lm = left + (ll)((right - left) / (GRATIO + 1.0));
fl = calc(lm);
} else {
left = lm;
lm = rm;
fl = fr;
rm = lm + (ll)((right - lm) / (GRATIO + 1.0));
fr = calc(rm);
}
}
if (left > right) {
ll l = left;
left = right;
right = l;
}
ll maxScore = MIN(ll);
ll resIndex = left;
for (ll i = left; i < right + 1; i++) {
ll score = calc(i);
if (maxScore < score) {
maxScore = score;
resIndex = i;
}
}
return resIndex;
}
template <class T> T min(vector<vector<T>> &a) {
T res = MAX(T);
rep(i, a.size()) chmin(res, *min_element(all(a[i])));
return res;
}
template <class T> T max(vector<vector<T>> &a) {
T res = MIN(T);
rep(i, a.size()) chmax(res, *max_element(all(a[i])));
return res;
}
bool bget(ll m, int keta) { return (m >> keta) & 1; }
int bget(ll m, int keta, int sinsuu) {
m /= (ll)pow(sinsuu, keta);
return m % sinsuu;
}
inline ll bit(int n) { return (1LL << (n)); }
inline ll bit(int n, int sinsuu) { return (ll)pow(sinsuu, n); }
// int bcou(ll m) { return __builtin_popcount(m & 0xFFFFFFFF) +
// __builtin_popcount(m >> 32); }
#define bcou __builtin_popcountll
// 最下位ビット
int lbit(int n) { return n & -n; }
// 最上位ビット
int hbit(int n) {
n |= (n >> 1);
n |= (n >> 2);
n |= (n >> 4);
n |= (n >> 8);
n |= (n >> 16);
n |= (n >> 32);
return n - (n >> 1);
}
// 初期化は0を渡す
ll nextComb(ll &mask, int n, int r) {
if (!mask)
return mask = (1LL << r) - 1;
ll x = mask & -mask; // 最下位の1
ll y = mask + x; // 連続した下の1を繰り上がらせる
ll res = ((mask & ~y) / x >> 1) | y;
if (bget(res, n))
return mask = 0;
else
return mask = res;
}
// n桁以下でビットがr個立っているもののvectorを返す
vl bitCombList(int n, int r) {
vl res;
int m = 0;
while (nextComb(m, n, r)) {
res.pb(m);
}
return res;
}
// 大文字小文字を区別する
int altoiaZ(char c) {
if ('A' <= c && c <= 'Z')
return c - 'A';
return c - 'a' + 26;
}
char itoalaZ(int i) {
if (i < 26)
return 'A' + i;
return 'a' + i - 26;
}
// aもAも0を返す 基本小文字
int altoi(char c) {
if ('A' <= c && c <= 'Z')
return c - 'A';
return c - 'a';
}
char itoal(int i) { return 'a' + i; }
int ctoi(char c) { return c - '0'; }
char itoc(int i) { return i + '0'; }
int vtoi(vi &v) {
int res = 0;
if (sz(v) > 18) {
debugline("vtoi");
deb(sz(v));
ole();
}
rep(i, sz(v)) {
res *= 10;
res += v[i];
}
return res;
}
vi itov(int i) {
vi res;
while (i) {
res.pb(i % 10);
i /= 10;
}
rev(res);
return res;
}
vector<vector<int>> ctoi(vector<vector<char>> s, char c) {
int n = sz(s), m = sz(s[0]);
vector<vector<int>> res(n, vector<int>(m));
rep(i, n) rep(j, m) res[i][j] = s[i][j] == c;
return res;
}
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
void compress(vi &a) {
vi b;
int len = a.size();
for (int i = 0; i < len; ++i) {
b.push_back(a[i]);
}
sort(b);
UNIQUE(b);
for (int i = 0; i < len; ++i) {
a[i] = lower_bound(all(b), a[i]) - b.begin();
}
}
void compress(int a[], int len) {
vi b;
for (int i = 0; i < len; ++i) {
b.push_back(a[i]);
}
sort(b);
UNIQUE(b);
for (int i = 0; i < len; ++i) {
a[i] = lower_bound(all(b), a[i]) - b.begin();
}
}
// 要素が見つからなかったときに困る
#define binarySearch(a, v) (binary_search(all(a), v))
#define lowerIndex(a, v) (lower_bound(all(a), v) - a.begin())
#define lowerBound(a, v) (*lower_bound(all(a), v))
#define upperIndex(a, v) (upper_bound(all(a), v) - a.begin())
#define upperBound(a, v) (*upper_bound(all(a), v))
#define ans(a) \
cout << a << endl; \
continue;
#define poll(a) \
q.front(); \
q.pop()
#define dpoll(a) \
q.front(); \
q.pop_front()
#define pollLast(a) \
q.back(); \
q.pop_back()
#define pollBack(a) \
q.back(); \
q.pop_back()
template <class T> inline void fin(T s) { cout << s << endl, exit(0); }
template <class T> struct edge {
int from, to;
T cost;
int id;
int type;
edge(int f, int t, T c = 1, int id = -1, int ty = -1)
: from(f), to(t), cost(c), id(id), type(ty) {}
bool operator<(const edge &b) const { return cost < b.cost; }
bool operator>(const edge &b) const { return cost > b.cost; }
};
template <typename T> class graph {
protected:
vector<bool> _used;
public:
vector<vector<edge<T>>> g;
vector<edge<T>> edges;
int n;
graph(int n) : n(n) { g.resize(n), _used.resize(n); }
void clear() { g.clear(), edges.clear(); }
void resize(int n) {
this->n = n;
g.resize(n);
_used.resize(n);
}
int size() { return g.size(); }
vector<edge<T>> &operator[](int i) { return g[i]; }
virtual void add(int from, int to, T cost, int id, int ty) = 0;
virtual bool used(edge<T> &e) = 0;
virtual bool used(int id) = 0;
virtual void del(edge<T> &e) = 0;
virtual void del(int id) = 0;
};
template <typename T = ll> class digraph : public graph<T> {
public:
using graph<T>::g;
using graph<T>::n;
using graph<T>::edges;
using graph<T>::_used;
digraph(int n) : graph<T>(n) {}
void add(int f, int t, T cost = 1, int id = -1, int ty = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("digraph add");
deb(f, t, cost, id, ty);
ole();
}
if (id == -1)
id = edges.size();
g[f].emplace_back(f, t, cost, id, ty);
edges.emplace_back(f, t, cost, id, ty);
}
bool used(edge<T> &e) { return _used[e.id]; }
bool used(int id) { return _used[id]; }
void del(edge<T> &e) { _used[e.id] = _used[e.id ^ 1] = 1; }
void del(int id) { _used[id] = _used[id ^ 1] = 1; }
};
template <class T = int> class undigraph : public graph<T> {
public:
using graph<T>::g;
using graph<T>::n;
using graph<T>::edges;
using graph<T>::_used;
undigraph(int n) : graph<T>(n) {}
void add(int f, int t, T cost = 1, int id = -1, int ty = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("undigraph add");
deb(f, t, cost, id, ty);
ole();
}
if (id == -1)
id = edges.size();
g[f].emplace_back(f, t, cost, id, ty);
g[t].emplace_back(t, f, cost, id + 1, ty);
edges.emplace_back(f, t, cost, id, ty);
edges.emplace_back(t, f, cost, id + 1, ty);
}
void add(edge<T> &e) {
int f = e.from, t = e.to, ty = e.type;
T cost = e.cost;
add(f, t, cost, ty);
}
bool used(edge<T> &e) { return _used[e.id]; }
bool used(int id) { return _used[id]; }
void del(edge<T> &e) { _used[e.id] = _used[e.id ^ 1] = 1; }
void del(int id) { _used[id] = _used[id ^ 1] = 1; }
};
template <class T>
vector<T> dijkstra(const graph<T> &g, int s, int cant_arrive = -1) {
if (!(0 <= s && s < g.n)) {
debugline("dijkstra");
deb(s, g.n);
ole();
}
T initValue = MAX(T);
vector<T> dis(g.n, initValue);
priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q;
dis[s] = 0;
q.emplace(0, s);
while (q.size()) {
T nowc = q.top().fi;
int i = q.top().se;
q.pop();
if (dis[i] != nowc)
continue;
for (auto &&e : g.g[i]) {
int to = e.to;
T cost = nowc + e.cost;
if (dis[to] > cost) {
dis[to] = cost;
q.emplace(dis[to], to);
}
}
}
// 基本、たどり着かないなら-1
if (cant_arrive == -1)
for (auto &&d : dis)
if (d == initValue)
d = -1;
return dis;
}
template <class T>
vector<vector<T>> warshall(const graph<T> &g, int cant_arrive = -1) {
int n = g.n;
vector<vector<T>> dis(n, vector<T>(n, linf));
fora(e, g.edges) chmin(dis[e.from][e.to], e.cost);
rep(i, n) dis[i][i] = 0;
rep(k, n) rep(i, n) rep(j, n) chmin(dis[i][j], dis[i][k] + dis[k][j]);
// 基本、たどり着かないなら-1
if (cant_arrive == -1)
rep(i, n) rep(j, n) if (dis[i][j] == linf) dis[i][j] = -1;
return dis;
}
template <class T = int> class tree : public undigraph<T> {
public:
using undigraph<T>::g;
using undigraph<T>::n;
using undigraph<T>::edges;
using undigraph<T>::_used;
vi dep;
vi disv;
private:
bool never = 1;
int root = -1;
vector<vector<int>> par;
bool costallone;
void dfs(int v, int p, int d) {
dep[v] = d;
par[0][v] = p;
int lim = (*this)[v].size();
for (int i = 0; i < lim; i++) {
int t = g[v][i].to;
if (t == p)
con;
dfs(t, v, d + 1);
}
}
void built() {
never = 0;
n = g.size();
par.assign(30, vi(n));
dep.resize(n);
costallone = 1;
fora(e, edges) if (e.cost != 1) costallone = 0;
dfs(root, -1, 0);
rep(k, par.size() - 1) {
rep(i, n) {
if (par[k][i] == -1)
par[k + 1][i] = -1;
else
par[k + 1][i] = par[k][par[k][i]];
}
}
if (costallone)
disv = dep;
else
disv = dijkstra(*this, root);
}
int _lca(int u, int v) {
if (dep[u] > dep[v])
swap(u, v);
rep(k, par.size()) {
if ((dep[u] - dep[v]) >> k & 1) {
v = par[k][v];
}
}
if (u == v)
return u;
rer(k, par.size() - 1) {
if (par[k][u] != par[k][v]) {
u = par[k][u];
v = par[k][v];
}
}
return par[0][u];
}
int _dis(int u, int v) {
int p = _lca(u, v);
return disv[u] + disv[v] - disv[p] * 2;
}
public:
tree(int n, int root = 0) : undigraph<T>(n), root(root) {}
bool leaf(int v) { return sz(g[v]) == 1 && v != root; }
int dis(int u, int v) {
if (never) {
built();
}
return _dis(u, v);
}
int lca(int u, int v) {
if (never) {
built();
}
return _lca(u, v);
}
};
// 辺によりメモリを大量消費
// よってedgesを消している
// 頂点10^6でメモリを190MB(制限の8割)使う
// 軽量化のため、辺を持たないbig gridクラスがあってもいいかもしれない
//
template <class T = int> class grid_k6 : public undigraph<T> {
public:
using undigraph<T>::g;
using undigraph<T>::n;
using undigraph<T>::edges;
using undigraph<T>::_used;
int H, W;
int eid = 0;
void add(int f, int t, T cost = 1, int id = -1, int ty = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("grid_k6 add");
deb(f, t, cost, id, ty);
ole();
}
g[f].emplace_back(f, t, cost, eid++, ty);
g[t].emplace_back(t, f, cost, eid++, ty);
}
int getid(int h, int w) {
if (!inside(h, w, H, W))
return -1;
return W * h + w;
}
P get2(int id) { return mp(id / W, id % W); }
P operator()(int id) { return get2(id); }
int operator()(int h, int w) { return getid(h, w); }
grid_k6(int H, int W) : H(H), W(W), undigraph<T>(H * W) {
rep(h, H) {
rep(w, W) {
int f = getid(h, w);
if (w + 1 < W)
add(f, getid(h, w + 1));
if (h + 1 < H)
add(f, getid(h + 1, w));
}
}
}
grid_k6(_vvc ba, char wall = '#')
: H(sz(ba)), W(sz(ba[0])), undigraph<T>(sz(ba) * sz(ba[0])) {
rep(h, H) {
rep(w, W) {
if (ba[h][w] == wall)
con;
int f = getid(h, w);
if (w + 1 < W && ba[h][w + 1] != wall) {
add(f, getid(h, w + 1));
}
if (h + 1 < H && ba[h + 1][w] != wall) {
add(f, getid(h + 1, w));
}
}
}
}
void add(int fh, int fw, int th, int tw) {
add(getid(fh, fw), getid(th, tw));
}
};
// 左上から右下に移動できる
template <class T = int> class digrid_k6 : public digraph<T> {
public:
using digraph<T>::g;
using digraph<T>::n;
using digraph<T>::edges;
using digraph<T>::_used;
int H, W;
int eid = 0;
void add(int f, int t, T cost = 1, int id = -1, int ty = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("digrid_k6 add");
deb(f, t, cost, id, ty);
ole();
}
g[f].emplace_back(f, t, cost, eid++, ty);
}
int getid(int h, int w) {
if (!inside(h, w, H, W))
return -1;
return W * h + w;
}
P get2(int id) { return mp(id / W, id % W); }
P operator()(int id) { return get2(id); }
int operator()(int h, int w) { return getid(h, w); }
digrid_k6(int H, int W) : H(H), W(W), digraph<T>(H * W) {
rep(h, H) {
rep(w, W) {
int f = getid(h, w);
if (w + 1 < W)
add(f, getid(h, w + 1));
if (h + 1 < H)
add(f, getid(h + 1, w));
}
}
}
digrid_k6(_vvc ba, char wall = '#')
: H(sz(ba)), W(sz(ba[0])), digraph<T>(sz(ba) * sz(ba[0])) {
rep(h, H) {
rep(w, W) {
if (ba[h][w] == wall)
con;
int f = getid(h, w);
if (w + 1 < W && ba[h][w + 1] != wall) {
add(f, getid(h, w + 1));
}
if (h + 1 < H && ba[h + 1][w] != wall) {
add(f, getid(h + 1, w));
}
}
}
}
void add(int fh, int fw, int th, int tw) {
add(getid(fh, fw), getid(th, tw));
}
};
template <class T> bool nibu(const graph<T> &g) {
if (g.edges.size() == 0)
return true;
UnionFind uf(g.n * 2);
for (auto &&e : g.edges)
uf.unite(e.from, e.to + g.n), uf.unite(e.from + g.n, e.to);
rep(i, g.n) if (uf.same(i, i + g.n)) return 0;
return 1;
}
// 二部グラフを色分けした際の頂点数を返す
template <class T> vp nibug(graph<T> &g) {
vp cg;
if (!nibu(g)) {
debugline("nibu");
ole();
}
int _n = g.size();
vb _was(_n);
queue<P> q;
rep(i, _n) {
if (_was[i])
continue;
q.push(mp(i, 1));
_was[i] = 1;
int red = 0;
int coun = 0;
while (q.size()) {
int now = q.front().fi;
int col = q.front().se;
red += col;
coun++;
q.pop();
forg(gi, g[now]) {
if (_was[t])
continue;
q.push(mp(t, col ^ 1));
_was[t] = 1;
}
}
cg.push_back(mp(red, coun - red));
}
return cg;
}
// 機能拡張
vp vtop(vi &a, vi &b) {
vp res(sz(a));
rep(i, sz(a)) res[i] = mp(a[i], b[i]);
return res;
}
void ptov(vp &p, vi &a, vi &b) {
a.resize(sz(p));
b.resize(sz(p));
rep(i, sz(p)) a[i] = p[i].fi, b[i] = p[i].se;
}
template <typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>
operator+(const basic_string<_CharT, _Traits, _Alloc> &__lhs, const int __rv) {
basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
__str.append(to_string(__rv));
return __str;
}
template <typename _CharT, typename _Traits, typename _Alloc>
void operator+=(basic_string<_CharT, _Traits, _Alloc> &__lhs, const int __rv) {
__lhs += to_string(__rv);
}
template <typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>
operator+(const basic_string<_CharT, _Traits, _Alloc> &__lhs,
const signed __rv) {
basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
__str.append(to_string(__rv));
return __str;
}
template <typename _CharT, typename _Traits, typename _Alloc>
void operator+=(basic_string<_CharT, _Traits, _Alloc> &__lhs,
const signed __rv) {
__lhs += to_string(__rv);
}
template <class T, class U> void operator+=(queue<T> &a, U v) { a.push(v); }
template <class T, class U>
priority_queue<T, vector<T>, greater<T>> &
operator+=(priority_queue<T, vector<T>, greater<T>> &a, U v) {
a.push(v);
return a;
}
template <class T, class U>
priority_queue<T> &operator+=(priority_queue<T> &a, U v) {
a.push(v);
return a;
}
template <class T, class U> set<T> &operator+=(set<T> &a, U v) {
a.insert(v);
return a;
}
template <class T, class U>
set<T, greater<T>> &operator+=(set<T, greater<T>> &a, U v) {
a.insert(v);
return a;
}
template <class T, class U> vector<T> &operator+=(vector<T> &a, U v) {
a.pb(v);
return a;
}
template <class T, class U> vector<T> operator+(const vector<T> &a, U v) {
vector<T> ret = a;
ret += v;
return ret;
}
template <class T, class U> vector<T> operator+(U v, const vector<T> &a) {
vector<T> ret = a;
ret.insert(ret.begin(), v);
return ret;
}
template <class T> vector<T> &operator+=(vector<T> &a, vector<T> &b) {
fora(v, b) a += v;
return a;
}
template <class T, class U>
vector<T> &operator+=(vector<T> &a, initializer_list<U> v) {
for (auto &&va : v)
a.pb(va);
return a;
}
template <class T> vector<T> &operator-=(vector<T> &a, vector<T> &b) {
if (sz(a) != sz(b)) {
debugline("vector<T> operator-=");
deb(a);
deb(b);
ole();
}
rep(i, sz(a)) a[i] -= b[i];
return a;
}
template <class T> vector<T> operator-(vector<T> &a, vector<T> &b) {
if (sz(a) != sz(b)) {
debugline("vector<T> operator-");
deb(a);
deb(b);
ole();
}
vector<T> res(sz(a));
rep(i, sz(a)) res[i] = a[i] - b[i];
return res;
}
template <typename T> void remove(vector<T> &v, unsigned int i) {
v.erase(v.begin() + i);
}
template <typename T>
void remove(vector<T> &v, unsigned int s, unsigned int e) {
v.erase(v.begin() + s, v.begin() + e);
}
template <typename T>
void removen(vector<T> &v, unsigned int s, unsigned int n) {
v.erase(v.begin() + s, v.begin() + s + n);
}
template <typename T> void erase(vector<T> &v, unsigned int i) {
v.erase(v.begin() + i);
}
template <typename T> void erase(vector<T> &v, unsigned int s, unsigned int e) {
v.erase(v.begin() + s, v.begin() + e);
}
template <typename T>
void erasen(vector<T> &v, unsigned int s, unsigned int n) {
v.erase(v.begin() + s, v.begin() + s + n);
}
template <typename T, typename U>
void insert(vector<T> &v, unsigned int i, U t) {
v.insert(v.begin() + i, t);
}
template <typename T, typename U> void push_front(vector<T> &v, U t) {
v.insert(v.begin(), t);
}
template <typename T, typename U>
void insert(vector<T> &v, unsigned int i, vector<T> list) {
for (auto &&va : list)
v.insert(v.begin() + i++, va);
}
template <typename T, typename U>
void insert(vector<T> &v, initializer_list<U> list) {
for (auto &&va : list)
v.pb(va);
}
template <typename T, typename U>
void insert(vector<T> &v, unsigned int i, initializer_list<U> list) {
for (auto &&va : list)
v.insert(v.begin() + i++, va);
}
template <typename T> void insert(set<T> &v, vector<T> list) {
for (auto &&va : list)
v.insert(va);
}
template <typename T> void insert(set<T> &v, initializer_list<T> list) {
for (auto &&va : list)
v.insert(va);
}
// 閉路がなければtrue
bool topo(vi &res, digraph<int> &g) {
int n = g.g.size();
vi nyu(n);
rep(i, n) for (auto &&e : g[i]) nyu[e.to]++;
queue<int> st;
rep(i, n) if (nyu[i] == 0) st.push(i);
while (st.size()) {
int v = st.front();
st.pop();
res.pb(v);
fora(e, g[v]) if (--nyu[e.to] == 0) st.push(e.to);
}
return res.size() == n;
}
// 辞書順最小トポロジカルソート
bool topos(vi &res, digraph<int> &g) {
int n = g.g.size();
vi nyu(n);
rep(i, n) for (auto &&e : g[i]) nyu[e.to]++;
// 小さい順
priority_queue<int, vector<int>, greater<int>> q;
rep(i, n) if (nyu[i] == 0) q.push(i);
while (q.size()) {
int i = q.top();
q.pop();
res.pb(i);
fora(e, g[i]) if (--nyu[e.to] == 0) q.push(e.to);
}
return res.size() == n;
}
vector<string> split(const string a, const char deli) {
string b = a + deli;
int l = 0, r = 0, n = b.size();
vector<string> res;
rep(i, n) {
if (b[i] == deli) {
r = i;
if (l < r)
res.push_back(b.substr(l, r - l));
l = i + 1;
}
}
return res;
}
vector<string> split(const string a, const string deli) {
string b = a + deli;
int l = 0, r = 0, n = b.size(), dn = deli.size();
vector<string> res;
rep(i, n) {
if (i + dn <= n && b.substr(i, i + dn) == deli) {
r = i;
if (l < r)
res.push_back(b.substr(l, r - l));
i += dn - 1;
l = i + 1;
}
}
return res;
}
void yn(bool a) {
if (a)
cout << "yes" << endl;
else
cout << "no" << endl;
}
void Yn(bool a) {
if (a)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void YN(bool a) {
if (a)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void fyn(bool a) {
if (a)
cout << "yes" << endl;
else
cout << "no" << endl;
exit(0);
}
void fYn(bool a) {
if (a)
cout << "Yes" << endl;
else
cout << "No" << endl;
exit(0);
}
void fYN(bool a) {
if (a)
cout << "YES" << endl;
else
cout << "NO" << endl;
exit(0);
}
void Possible(bool a) {
if (a)
cout << "Possible" << endl;
else
cout << "Impossible" << endl;
exit(0);
}
int n, m, k, d, H, W, x, y, z, q;
int cou;
vi a, b, c;
vvi(s, 0, 0);
vvc(ba, 0, 0);
vp p;
void solve() {
cin >> n;
na(a, n);
vi res;
vi usd(n);
rep(_, n) {
int d = 1;
int id = -1;
rep(i, n) {
if (usd[i])
con;
if (a[i] == d)
id = i;
d++;
}
if (id == -1)
fin(-1);
res += a[id];
usd[id] = 1;
}
res = rev(res);
rep(i, n) cout << res[i] << endl;
}
int my(int n, vi a) { return 0; }
int sister(int n, vi a) { return 0; }
signed main() {
solve();
#define _arg n, a
// cin>>n;
// na(a,n);
// my(_arg);
// cout << my(_arg) << endl;
#ifdef _DEBUG
bool bad = 0;
for (int i = 0, ok = 1; i < k5 && ok; i++) {
int n = rand(1, 3);
vi a = ranv(m, 1, 10);
int myres = my(_arg);
int res = sister(_arg);
ok = myres == res;
if (!ok) {
cout << n << endl;
cout << a << endl;
cout << "正解 : " << res << endl;
cout << "出力 : " << myres << endl;
bad = 1;
break;
}
}
#endif
return 0;
};
| replace | 2,598 | 2,657 | 2,598 | 2,616 | 0 | |
p03089 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <vector>
using namespace std;
using lli = long long int;
template <class T, class U> void init_n(vector<T> &v, size_t n, U x) {
v = vector<T>(n, x);
}
template <class T> void init_n(vector<T> &v, size_t n) { init_n(v, n, T()); }
template <class T> void read_n(vector<T> &v, size_t n, size_t o = 0) {
v = vector<T>(n + o);
for (lli i = o; i < n + o; ++i)
cin >> v[i];
}
template <class T> void read_n(T a[], size_t n, size_t o = 0) {
for (lli i = o; i < n + o; ++i)
cin >> a[i];
}
template <class T> T gabs(const T &x) { return max(x, -x); }
#define abs gabs
lli n;
int main() {
vector<lli> b;
cin >> n;
read_n(b, n, 1);
b[0] = -1;
vector<lli> c;
while (b.size() >= 2) {
lli j = b.size() - 1;
for (; j >= 0; --j) {
if (b[j] == j) {
b.erase(begin(b) + j);
c.push_back(j);
break;
}
}
if (j == 0) {
cout << -1 << '\n';
return 0;
}
}
for (lli i = c.size() - 1; i >= 0; --i)
cout << c[i] << '\n';
return 0;
}
| #include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <vector>
using namespace std;
using lli = long long int;
template <class T, class U> void init_n(vector<T> &v, size_t n, U x) {
v = vector<T>(n, x);
}
template <class T> void init_n(vector<T> &v, size_t n) { init_n(v, n, T()); }
template <class T> void read_n(vector<T> &v, size_t n, size_t o = 0) {
v = vector<T>(n + o);
for (lli i = o; i < n + o; ++i)
cin >> v[i];
}
template <class T> void read_n(T a[], size_t n, size_t o = 0) {
for (lli i = o; i < n + o; ++i)
cin >> a[i];
}
template <class T> T gabs(const T &x) { return max(x, -x); }
#define abs gabs
lli n;
int main() {
vector<lli> b;
cin >> n;
read_n(b, n, 1);
b[0] = -1;
vector<lli> c;
while (b.size() >= 2) {
lli j = b.size() - 1;
for (; j > 0; --j) {
if (b[j] == j) {
b.erase(begin(b) + j);
c.push_back(j);
break;
}
}
if (j == 0) {
cout << -1 << '\n';
return 0;
}
}
for (lli i = c.size() - 1; i >= 0; --i)
cout << c[i] << '\n';
return 0;
}
| replace | 43 | 44 | 43 | 44 | TLE | |
p03089 | Python | Time Limit Exceeded | N = int(input())
b_list = list(map(int, input().split()))
generate_seq = []
def is_ok(b):
len_b = len(b)
if len_b == 1 and b[0] == 1:
generate_seq.append(1)
return True
processing = []
for idx in range(len_b):
if b[idx] != idx + 1:
processing.append(False)
else:
b_tmp = b[:]
del b_tmp[idx]
tmp = is_ok(b_tmp)
if tmp:
generate_seq.append(idx + 1)
return True
return False
result = is_ok(b_list)
if result:
print("\n".join(list(map(str, generate_seq))))
else:
print(-1)
| N = int(input())
b_list = list(map(int, input().split()))
generate_seq = []
def is_ok(b):
len_b = len(b)
if len_b == 1 and b[0] == 1:
generate_seq.append(1)
return True
for idx, val in enumerate(b):
if idx + 1 < val:
return False
processing = []
for idx in range(len_b):
if b[idx] != idx + 1:
processing.append(False)
else:
b_tmp = b[:]
del b_tmp[idx]
tmp = is_ok(b_tmp)
if tmp:
generate_seq.append(idx + 1)
return True
return False
result = is_ok(b_list)
if result:
print("\n".join(list(map(str, generate_seq))))
else:
print(-1)
| insert | 11 | 11 | 11 | 15 | TLE | |
p03089 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int Check(vector<int> &b) {
for (int i = 0; i < b.size(); i++) {
if (b[i] == i + 1) {
int temp = b[i];
if (b.size() == 1) {
cout << temp << endl;
return 1;
} else {
b.erase(b.begin() + i);
}
if (Check(b) == 1) {
cout << temp << endl;
return 1;
}
b.insert(b.begin() + i, temp);
}
}
return 0;
}
int main() {
int n;
cin >> n;
vector<int> b;
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
b.push_back(tmp);
if (b[i] > i + 1) {
cout << "-1";
return 0;
}
}
if (Check(b) == 0) {
cout << "-1";
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int Check(vector<int> &b) {
for (int i = b.size() - 1; i >= 0; i--) {
if (b[i] == i + 1) {
int temp = b[i];
if (b.size() == 1) {
cout << temp << endl;
return 1;
} else {
b.erase(b.begin() + i);
}
if (Check(b) == 1) {
cout << temp << endl;
return 1;
}
b.insert(b.begin() + i, temp);
}
}
return 0;
}
int main() {
int n;
cin >> n;
vector<int> b;
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
b.push_back(tmp);
if (b[i] > i + 1) {
cout << "-1";
return 0;
}
}
if (Check(b) == 0) {
cout << "-1";
}
return 0;
}
| replace | 8 | 9 | 8 | 9 | TLE | |
p03089 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> b(N);
for (auto &x : b)
cin >> x;
for (int i = 0; i < N; i++) {
if (b[i] > i + 1) {
cout << -1 << endl;
return 0;
}
}
stack<pair<vector<int>, vector<int>>> st;
st.emplace(b, vector<int>());
while (!st.empty()) {
auto now = st.top();
st.pop();
if (now.first.size() == 0) {
reverse(now.second.begin(), now.second.end());
for (auto &x : now.second)
cout << x << endl;
return 0;
}
for (int i = now.first.size() - 1; i >= 0; i--) {
if (now.first[i] == i + 1) {
auto newVec1 = now.first;
newVec1.erase(newVec1.begin() + i);
auto newVec2 = now.second;
newVec2.push_back(i + 1);
st.emplace(newVec1, newVec2);
}
}
}
cout << -1 << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> b(N);
for (auto &x : b)
cin >> x;
for (int i = 0; i < N; i++) {
if (b[i] > i + 1) {
cout << -1 << endl;
return 0;
}
}
stack<pair<vector<int>, vector<int>>> st;
st.emplace(b, vector<int>());
while (!st.empty()) {
auto now = st.top();
st.pop();
if (now.first.size() == 0) {
reverse(now.second.begin(), now.second.end());
for (auto &x : now.second)
cout << x << endl;
return 0;
}
for (int i = 0; i < now.first.size(); i++) {
if (now.first[i] == i + 1) {
auto newVec1 = now.first;
newVec1.erase(newVec1.begin() + i);
auto newVec2 = now.second;
newVec2.push_back(i + 1);
st.emplace(newVec1, newVec2);
}
}
}
cout << -1 << endl;
return 0;
}
| replace | 35 | 36 | 35 | 36 | TLE | |
p03089 | C++ | Time Limit Exceeded | // Created by sz
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e2 + 5;
int n, b[N], vis[N], a[N];
bool dfs(int pos, int idx) {
a[idx] = pos;
if (idx == n)
return true;
int used = 0;
for (int i = 1; i <= n; i++) {
if (vis[i])
used++;
else if (b[i] + used > i)
return false;
else if (b[i] + used == i) {
vis[i] = 1;
if (dfs(i, idx + 1))
return true;
vis[i] = 0;
}
}
return false;
}
bool solve() {
for (int i = 1; i <= n; i++) {
if (b[i] == i) {
vis[i] = 1;
if (dfs(i, 1))
return true;
vis[i] = 0;
}
}
return false;
}
int main() {
#ifdef LOCAL
freopen("./input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> b[i];
bool ok = solve();
if (!ok)
cout << -1 << endl;
else {
for (int i = n; i >= 1; i--) {
cout << b[a[i]] << endl;
}
}
return 0;
}
| // Created by sz
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e2 + 5;
int n, b[N], vis[N], a[N];
bool dfs(int pos, int idx) {
a[idx] = pos;
if (idx == n)
return true;
int used = 0;
for (int i = 1; i <= n; i++) {
if (vis[i])
used++;
else if (b[i] + used > i)
return false;
}
used = 0;
for (int i = 1; i <= n; i++) {
if (vis[i])
used++;
else if (b[i] + used == i) {
vis[i] = 1;
if (dfs(i, idx + 1))
return true;
vis[i] = 0;
}
}
return false;
}
bool solve() {
for (int i = 1; i <= n; i++) {
if (b[i] == i) {
vis[i] = 1;
if (dfs(i, 1))
return true;
vis[i] = 0;
}
}
return false;
}
int main() {
#ifdef LOCAL
freopen("./input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> b[i];
bool ok = solve();
if (!ok)
cout << -1 << endl;
else {
for (int i = n; i >= 1; i--) {
cout << b[a[i]] << endl;
}
}
return 0;
}
| insert | 19 | 19 | 19 | 24 | TLE | |
p03090 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll, ll>
#define f first
#define s second
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define int ll
#define sz(x) (ll) x.size()
#define all(x) (x.begin(), x.end())
using namespace std;
const ll INF = 1e12;
const ll N = (100 + 5); // TODO : change value as per problem
const ll MOD = 1e9 + 7;
int adj[N][N];
void solve() {
int n;
cin >> n;
if (n % 2 == 0) {
// int s = n+1;
// vector<pll> cand;
// set<int> vis;
// for(int i =1;i <= n;i++){
// for(int j = 1;j<=n;j++){
// if(j != i and j+i == s and !vis.count(i) and !vis.count(j)){
// cand.pb({i,j});
// vis.in(i);
// vis.in(j);
// }
// }
// }
// for(auto x:cand){
// cout << x.f << " " << x.s << endl;
// }
int S = n + 1;
for (int i = 1; i <= (n / 2); i++) {
adj[i][n - i + 1] = 1;
adj[n - i + 1][i] = 1;
}
vector<pll> ed;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (!adj[i][j]) {
ed.pb({i, j});
}
}
}
cout << ed.size() << endl;
for (auto x : ed)
cout << x.f << " " << x.s << endl;
} else {
while (true)
;
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
// freopen(".in","r",stdin);freopen(".out","w",stdout);
ll tt = 1;
// cin >> tt;
while (tt--) {
solve();
}
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll, ll>
#define f first
#define s second
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define int ll
#define sz(x) (ll) x.size()
#define all(x) (x.begin(), x.end())
using namespace std;
const ll INF = 1e12;
const ll N = (100 + 5); // TODO : change value as per problem
const ll MOD = 1e9 + 7;
int adj[N][N];
void solve() {
int n;
cin >> n;
if (n % 2 == 0) {
// int s = n+1;
// vector<pll> cand;
// set<int> vis;
// for(int i =1;i <= n;i++){
// for(int j = 1;j<=n;j++){
// if(j != i and j+i == s and !vis.count(i) and !vis.count(j)){
// cand.pb({i,j});
// vis.in(i);
// vis.in(j);
// }
// }
// }
// for(auto x:cand){
// cout << x.f << " " << x.s << endl;
// }
int S = n + 1;
for (int i = 1; i <= (n / 2); i++) {
adj[i][n - i + 1] = 1;
adj[n - i + 1][i] = 1;
}
vector<pll> ed;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (!adj[i][j]) {
ed.pb({i, j});
}
}
}
cout << ed.size() << endl;
for (auto x : ed)
cout << x.f << " " << x.s << endl;
} else {
int k = (n - 1) / 2;
for (int i = 1; i <= k; i++) {
adj[i][n - 1 - i + 1] = 1;
adj[n - 1 - i + 1][i] = 1;
}
vector<pll> ed;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (!adj[i][j]) {
ed.pb({i, j});
}
}
}
cout << ed.size() << endl;
for (auto x : ed)
cout << x.f << " " << x.s << endl;
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
// freopen(".in","r",stdin);freopen(".out","w",stdout);
ll tt = 1;
// cin >> tt;
while (tt--) {
solve();
}
} | replace | 87 | 89 | 87 | 103 | TLE | |
p03090 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define P pair<ll, ll>
#define sz(x) (ll) x.size()
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define VE vector<ll>
#define COUT(x) cout << (x) << endl
#define MA map<ll, ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, VE, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define EPS (1e-14)
#define pb push_back
long long MOD = 1000000007;
// const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
assert(n < MOD);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
} com(10);
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n = 1) : n(n), f(n + 1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i])
continue;
primes.push_back(i);
f[i] = i;
for (ll j = i * i; j <= n; j += i) {
if (!f[j])
f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x; }
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<P> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0)
return {};
vector<P> res(1, P(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
};
template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
bool prime(ll n) {
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return n != 1;
}
map<ll, ll> prime_factor(ll n) {
map<ll, ll> ret;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
vector<pair<char, int>> RunLength(string s) {
if (s.size() == 0)
return {};
vector<pair<char, int>> res(1, pair<char, int>(s[0], 0));
for (char p : s) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
// Digit Count
int GetDigit(int num) { return log10(num) + 1; }
// bit calculation[how many "1"] (= __builtin_popcount())
int bit_count(int n) {
int cnt = 0;
while (n > 0) {
if (n % 2 == 1)
cnt++;
n /= 2;
}
return cnt;
}
vector<long long> enum_divisors(long long N) {
vector<long long> res;
for (long long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
if (N / i != i)
res.push_back(N / i);
}
}
sort(res.begin(), res.end());
return res;
}
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
struct edge {
ll to, cost;
};
typedef long double ld;
using Graph = vector<VE>;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// cout << fixed << setprecision(15);
int n;
cin >> n;
if ((n * (n + 1) / 2) % 2 == 1) {
assert(n == INF);
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define P pair<ll, ll>
#define sz(x) (ll) x.size()
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define VE vector<ll>
#define COUT(x) cout << (x) << endl
#define MA map<ll, ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, VE, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define EPS (1e-14)
#define pb push_back
long long MOD = 1000000007;
// const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
assert(n < MOD);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
} com(10);
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n = 1) : n(n), f(n + 1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i])
continue;
primes.push_back(i);
f[i] = i;
for (ll j = i * i; j <= n; j += i) {
if (!f[j])
f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x; }
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<P> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0)
return {};
vector<P> res(1, P(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
};
template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
bool prime(ll n) {
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return n != 1;
}
map<ll, ll> prime_factor(ll n) {
map<ll, ll> ret;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
vector<pair<char, int>> RunLength(string s) {
if (s.size() == 0)
return {};
vector<pair<char, int>> res(1, pair<char, int>(s[0], 0));
for (char p : s) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
// Digit Count
int GetDigit(int num) { return log10(num) + 1; }
// bit calculation[how many "1"] (= __builtin_popcount())
int bit_count(int n) {
int cnt = 0;
while (n > 0) {
if (n % 2 == 1)
cnt++;
n /= 2;
}
return cnt;
}
vector<long long> enum_divisors(long long N) {
vector<long long> res;
for (long long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
if (N / i != i)
res.push_back(N / i);
}
}
sort(res.begin(), res.end());
return res;
}
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
struct edge {
ll to, cost;
};
typedef long double ld;
using Graph = vector<VE>;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// cout << fixed << setprecision(15);
int n;
cin >> n;
if (n % 2 == 0) {
vector<P> ans;
for (int i = 1; i <= n - 1; i++) {
for (int j = i + 1; j <= n; j++) {
if (i + j == n + 1)
continue;
ans.push_back(make_pair(i, j));
}
}
cout << ans.size() << endl;
rep(i, ans.size()) { cout << ans[i].first << " " << ans[i].second << endl; }
} else {
vector<P> ans;
for (int i = 1; i < n - 1; i++) {
for (int j = n - 1; j > i; j--) {
if (i + j == n)
continue;
ans.push_back(make_pair(i, j));
}
}
for (int i = 1; i < n; i++)
ans.push_back(make_pair(i, n));
cout << ans.size() << endl;
rep(i, ans.size()) { cout << ans[i].first << " " << ans[i].second << endl; }
}
return 0;
} | replace | 267 | 269 | 267 | 291 | 0 | |
p03090 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define STI(s) atoi(s.c_str())
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
struct io {
io() {
ios::sync_with_stdio(false);
cin.tie(0);
};
};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL << 62;
int main(void) {
int n;
cin >> n;
vector<vector<int>> allG(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j)
continue;
allG[i].push_back(j);
}
}
vi allsum(n);
for (int i = 0; i < n; i++) {
allsum[i] = n * (n + 1) / 2 - (i + 1);
}
for (int s = 2 * n; s >= 0; s--) {
// cout<<s<<endl;
vvi chG = allG;
vi sumG = allsum;
bool ch = true;
while (ch) {
bool fin = true;
for (int i = 0; i < n; i++) {
if (sumG[i] < s) {
ch = false;
break;
}
}
// for(int i=0;i<n;i++){
// cout<<sumG[i]<<" ";
// }
// cout<<endl;
int maxpos = 0;
int maxval = 0;
int reduce = 0;
for (int i = 0; i < n; i++) {
if (maxval <= sumG[i]) {
maxval = sumG[i];
maxpos = i;
}
}
// cout<<"AA"<<endl;
// rem
bool ischange = false;
for (int i = 0; i < chG[maxpos].size(); i++) {
// cout<<"i:"<<i<<endl;
if (sumG[maxpos] - chG[maxpos][i] - 1 == s) {
sumG[maxpos] -= chG[maxpos][i] + 1;
sumG[chG[maxpos][i]] -= maxpos + 1;
int from = maxpos + 1;
int to = chG[maxpos][i] + 1;
// cout<<"FT "<<from<<" "<<to<<endl;
chG[from - 1].erase(find(all(chG[from - 1]), to - 1));
chG[to - 1].erase(find(all(chG[to - 1]), from - 1));
ischange = true;
break;
}
}
// cout<<"BB"<<endl;
if (!ischange) {
Sort(chG[maxpos]);
sumG[maxpos] -= chG[maxpos][0] + 1;
chG[maxpos].erase(chG[maxpos].begin());
}
for (int i = 0; i < n; i++) {
if (sumG[i] != s) {
fin = false;
break;
}
}
// for(int i=0;i<n;i++){
// cout<<"i: "<<i+1<<" =";
// for(int j=0;j<chG[i].size();j++){
// cout<<chG[i][j]+1<<" ";
// }
// cout<<endl;
// }
if (fin) {
// 出力
set<pair<int, int>> sp;
vector<pair<int, int>> ans;
for (int i = 0; i < n; i++) {
for (int j = 0; j < chG[i].size(); j++) {
if (sp.find(mp(i + 1, chG[i][j] + 1)) != sp.end())
continue;
ans.push_back(mp(i + 1, chG[i][j] + 1));
sp.insert(mp(i + 1, chG[i][j] + 1));
sp.insert(mp(chG[i][j] + 1, i + 1));
}
}
cout << (int)ans.size() << endl;
for (int i = 0; i < ans.size(); i++) {
cout << ans[i].first << " " << ans[i].second << endl;
}
return 0;
}
}
}
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define STI(s) atoi(s.c_str())
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
struct io {
io() {
ios::sync_with_stdio(false);
cin.tie(0);
};
};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL << 62;
int main(void) {
int n;
cin >> n;
vector<vector<int>> allG(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j)
continue;
allG[i].push_back(j);
}
}
vi allsum(n);
for (int i = 0; i < n; i++) {
allsum[i] = n * (n + 1) / 2 - (i + 1);
}
for (int s = n * n; s >= 0; s--) {
// cout<<s<<endl;
vvi chG = allG;
vi sumG = allsum;
bool ch = true;
while (ch) {
bool fin = true;
for (int i = 0; i < n; i++) {
if (sumG[i] < s) {
ch = false;
break;
}
}
// for(int i=0;i<n;i++){
// cout<<sumG[i]<<" ";
// }
// cout<<endl;
int maxpos = 0;
int maxval = 0;
int reduce = 0;
for (int i = 0; i < n; i++) {
if (maxval <= sumG[i]) {
maxval = sumG[i];
maxpos = i;
}
}
// cout<<"AA"<<endl;
// rem
bool ischange = false;
for (int i = 0; i < chG[maxpos].size(); i++) {
// cout<<"i:"<<i<<endl;
if (sumG[maxpos] - chG[maxpos][i] - 1 == s) {
sumG[maxpos] -= chG[maxpos][i] + 1;
sumG[chG[maxpos][i]] -= maxpos + 1;
int from = maxpos + 1;
int to = chG[maxpos][i] + 1;
// cout<<"FT "<<from<<" "<<to<<endl;
chG[from - 1].erase(find(all(chG[from - 1]), to - 1));
chG[to - 1].erase(find(all(chG[to - 1]), from - 1));
ischange = true;
break;
}
}
// cout<<"BB"<<endl;
if (!ischange) {
Sort(chG[maxpos]);
sumG[maxpos] -= chG[maxpos][0] + 1;
chG[maxpos].erase(chG[maxpos].begin());
}
for (int i = 0; i < n; i++) {
if (sumG[i] != s) {
fin = false;
break;
}
}
// for(int i=0;i<n;i++){
// cout<<"i: "<<i+1<<" =";
// for(int j=0;j<chG[i].size();j++){
// cout<<chG[i][j]+1<<" ";
// }
// cout<<endl;
// }
if (fin) {
// 出力
set<pair<int, int>> sp;
vector<pair<int, int>> ans;
for (int i = 0; i < n; i++) {
for (int j = 0; j < chG[i].size(); j++) {
if (sp.find(mp(i + 1, chG[i][j] + 1)) != sp.end())
continue;
ans.push_back(mp(i + 1, chG[i][j] + 1));
sp.insert(mp(i + 1, chG[i][j] + 1));
sp.insert(mp(chG[i][j] + 1, i + 1));
}
}
cout << (int)ans.size() << endl;
for (int i = 0; i < ans.size(); i++) {
cout << ans[i].first << " " << ans[i].second << endl;
}
return 0;
}
}
}
}
| replace | 84 | 85 | 84 | 85 | 0 | |
p03090 | C++ | Runtime Error | /**
* There is a start and there is no end in the space. ---Infinity.
* It ruins and goes though there is also a start in stars. ---Finite.
* Only the man who has wisdom can read the most foolish one from the history.
* Fishes living in the sea doesn't know the life in the land.
* It also ruins and goes if they have wisdom.
* It funnier that man exceeds the speed of light than fish start living in the
* land. It can be said that this is an final ultimatum from the god to the
* people who can fight.
*
* Steins;Gate
*/
#include <bits/stdc++.h>
const int N = 110;
int vis[N];
int main() {
int n, cnt1 = 0;
scanf("%d", &n);
int t = (n + 1) * n / 2;
if (t & 1) {
if ((n & 1) == 0) {
printf("%d\n", n * (n - 2) / 2);
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (i + j != n + 1) {
printf("%d %d \n", i, j);
}
}
}
return 0;
} else
return -1;
}
t /= 2;
for (int i = n; i >= 1 && t; i--) {
if (t >= i) {
t -= i;
vis[i] = 1;
cnt1++;
}
}
printf("%d\n", cnt1 * (n - cnt1));
for (int i = 1; i <= n; i++) {
if (vis[i]) {
for (int j = 1; j <= n; j++) {
if (!vis[j]) {
printf("%d %d \n", i, j);
}
}
}
}
return 0;
}
| /**
* There is a start and there is no end in the space. ---Infinity.
* It ruins and goes though there is also a start in stars. ---Finite.
* Only the man who has wisdom can read the most foolish one from the history.
* Fishes living in the sea doesn't know the life in the land.
* It also ruins and goes if they have wisdom.
* It funnier that man exceeds the speed of light than fish start living in the
* land. It can be said that this is an final ultimatum from the god to the
* people who can fight.
*
* Steins;Gate
*/
#include <bits/stdc++.h>
const int N = 110;
int vis[N];
int main() {
int n, cnt1 = 0;
scanf("%d", &n);
int t = (n + 1) * n / 2;
if (t & 1) {
if ((n & 1) == 0) {
printf("%d\n", n * (n - 2) / 2);
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (i + j != n + 1) {
printf("%d %d \n", i, j);
}
}
}
return 0;
} else {
printf("%d \n", (n - 1) * (n - 3) / 2 + n - 1);
for (int i = 1; i < n; i++) {
printf("%d %d \n", i, n);
}
for (int i = 1; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (i + j != n) {
printf("%d %d \n", i, j);
}
}
}
}
return 0;
}
t /= 2;
for (int i = n; i >= 1 && t; i--) {
if (t >= i) {
t -= i;
vis[i] = 1;
cnt1++;
}
}
printf("%d\n", cnt1 * (n - cnt1));
for (int i = 1; i <= n; i++) {
if (vis[i]) {
for (int j = 1; j <= n; j++) {
if (!vis[j]) {
printf("%d %d \n", i, j);
}
}
}
}
return 0;
}
| replace | 35 | 37 | 35 | 49 | 0 | |
p03090 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
template <typename T> void read(T &x) {
x = 0;
char c = getchar();
bool f = 0;
while (!isdigit(c) && c != '-')
c = getchar();
if (c == '-')
f = 1, c = getchar();
while (isdigit(c))
x = x * 10 + c - '0', c = getchar();
if (f)
x = -x;
}
int sum[20], e[20][20];
int n;
/*void dfs(int x, int y)
{
if(x == n)
{
int t = sum[1], flg = 1;
for(int i=1; i<=n; i++)
if(sum[i] != t)
flg = 0;
if(flg)
{
cout<<t<<" : "<<endl;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++) cout<<e[i][j]<<" ";
cout<<endl;
}
}
}
else if(y == n+1) dfs(x+1, x+2);
else
{
dfs(x, y+1);
sum[x] += y;
sum[y] += x;
e[x][y] = e[y][x] = 1;
dfs(x, y+1);
sum[x] -= y;
sum[y] -= x;
e[x][y] = e[y][x] = 0;
}
}*/
int main() {
read(n);
if (n & 1) {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (i + j == n || i == j)
e[i][j] = 0;
else
e[i][j] = 1;
} else {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (i + j == n + 1 || i == j)
e[i][j] = 0;
else
e[i][j] = 1;
}
int cnt = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (e[i][j])
cnt++;
printf("%d\n", cnt);
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (e[i][j])
printf("%d %d\n", i, j);
// dfs(1, 2);
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
template <typename T> void read(T &x) {
x = 0;
char c = getchar();
bool f = 0;
while (!isdigit(c) && c != '-')
c = getchar();
if (c == '-')
f = 1, c = getchar();
while (isdigit(c))
x = x * 10 + c - '0', c = getchar();
if (f)
x = -x;
}
int sum[270], e[270][270];
int n;
/*void dfs(int x, int y)
{
if(x == n)
{
int t = sum[1], flg = 1;
for(int i=1; i<=n; i++)
if(sum[i] != t)
flg = 0;
if(flg)
{
cout<<t<<" : "<<endl;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++) cout<<e[i][j]<<" ";
cout<<endl;
}
}
}
else if(y == n+1) dfs(x+1, x+2);
else
{
dfs(x, y+1);
sum[x] += y;
sum[y] += x;
e[x][y] = e[y][x] = 1;
dfs(x, y+1);
sum[x] -= y;
sum[y] -= x;
e[x][y] = e[y][x] = 0;
}
}*/
int main() {
read(n);
if (n & 1) {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (i + j == n || i == j)
e[i][j] = 0;
else
e[i][j] = 1;
} else {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (i + j == n + 1 || i == j)
e[i][j] = 0;
else
e[i][j] = 1;
}
int cnt = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (e[i][j])
cnt++;
printf("%d\n", cnt);
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (e[i][j])
printf("%d %d\n", i, j);
// dfs(1, 2);
return 0;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p03090 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main() {
int n;
cin >> n;
int sum = n;
vector<vector<int>> flag(100, vector<int>(100, 0));
vector<int> ans1, ans2;
if (n % 2 == 0)
sum++;
REP(i, 1, n + 1) {
REP(l, 1, n + 1) {
if (i != l && flag[i][l] == 0 && i + l != sum) {
flag[i][l]++;
flag[l][i]++;
ans1.pb(i);
ans2.pb(l);
}
}
}
cout << ans1.size() << endl;
REP(i, 0, ans1.size()) { cout << ans1[i] << " " << ans2[i] << endl; }
} | #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main() {
int n;
cin >> n;
int sum = n;
vector<vector<int>> flag(101, vector<int>(101, 0));
vector<int> ans1, ans2;
if (n % 2 == 0)
sum++;
REP(i, 1, n + 1) {
REP(l, 1, n + 1) {
if (i != l && flag[i][l] == 0 && i + l != sum) {
flag[i][l]++;
flag[l][i]++;
ans1.pb(i);
ans2.pb(l);
}
}
}
cout << ans1.size() << endl;
REP(i, 0, ans1.size()) { cout << ans1[i] << " " << ans2[i] << endl; }
} | replace | 26 | 27 | 26 | 27 | 0 | |
p03090 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FastRead \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long int
#define ld long double
#define FOR(i, a, n) for (int i = (a); i <= (n); ++i)
#define RFOR(i, a, n) for (int i = (n); i >= (a); --i)
#define FI(i, n) for (int i = 0; i < (n); ++i)
#define ZERO(a) memset((a), 0, sizeof((a)))
#define f first
// #define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(), g.end()
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including
// tree_order_statistics_node_updat using namespace __gnu_pbds; typedef tree<ll,
// null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
// ordered_set;
// I am questioning life and universe and
// everything else after looking at this
void solve() {
ll n;
cin >> n;
vector<ll> graph[n + 1];
ll to_be_made = n;
if (n % 2 == 0)
to_be_made++;
vector<pair<ll, ll>> pairs;
for (ll i = 1; i <= n / 2; i++) {
pairs.push_back({i, to_be_made - i});
}
for (ll i = 0; i < pairs.size(); i++) {
for (ll j = i + 1; j < pairs.size(); i++) {
graph[pairs[i].first].push_back(pairs[j].first);
graph[pairs[i].first].push_back(pairs[j].second);
graph[pairs[i].second].push_back(pairs[j].first);
graph[pairs[i].second].push_back(pairs[j].second);
}
if (n % 2 == 1) {
graph[n].push_back(pairs[i].first);
graph[n].push_back(pairs[i].second);
}
}
vector<pair<ll, ll>> edges;
for (ll i = 1; i <= n; i++) {
for (ll v : graph[i]) {
edges.push_back({i, v});
}
}
cout << edges.size() << endl;
for (auto x : edges) {
cout << x.first << " " << x.second << endl;
}
}
signed main() {
FastRead;
ll t;
t = 1;
// cin>>t;
while (t--)
solve();
} | #include <bits/stdc++.h>
using namespace std;
#define FastRead \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define ll long long int
#define ld long double
#define FOR(i, a, n) for (int i = (a); i <= (n); ++i)
#define RFOR(i, a, n) for (int i = (n); i >= (a); --i)
#define FI(i, n) for (int i = 0; i < (n); ++i)
#define ZERO(a) memset((a), 0, sizeof((a)))
#define f first
// #define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(), g.end()
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including
// tree_order_statistics_node_updat using namespace __gnu_pbds; typedef tree<ll,
// null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
// ordered_set;
// I am questioning life and universe and
// everything else after looking at this
void solve() {
ll n;
cin >> n;
vector<ll> graph[n + 1];
ll to_be_made = n;
if (n % 2 == 0)
to_be_made++;
vector<pair<ll, ll>> pairs;
for (ll i = 1; i <= n / 2; i++) {
pairs.push_back({i, to_be_made - i});
}
for (ll i = 0; i < pairs.size(); i++) {
for (ll j = i + 1; j < pairs.size(); j++) {
graph[pairs[i].first].push_back(pairs[j].first);
graph[pairs[i].first].push_back(pairs[j].second);
graph[pairs[i].second].push_back(pairs[j].first);
graph[pairs[i].second].push_back(pairs[j].second);
}
if (n % 2 == 1) {
graph[n].push_back(pairs[i].first);
graph[n].push_back(pairs[i].second);
}
}
vector<pair<ll, ll>> edges;
for (ll i = 1; i <= n; i++) {
for (ll v : graph[i]) {
edges.push_back({i, v});
}
}
cout << edges.size() << endl;
for (auto x : edges) {
cout << x.first << " " << x.second << endl;
}
}
signed main() {
FastRead;
ll t;
t = 1;
// cin>>t;
while (t--)
solve();
} | replace | 45 | 46 | 45 | 46 | 0 | |
p03090 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;
int main() {
int N;
cin >> N;
if (N == 3) {
cout << 2 << endl;
cout << "1 3\n2 3" << endl;
return 0;
} else if (N == 4) {
cout << 4 << endl;
cout << "1 2\n1 3\n4 2\n4 3\n";
return 0;
}
using P = pair<int, int>;
vector<P> ans;
if (N % 2 == 1) {
int K = N - 1;
vector<vector<int>> a(K / 2 + 2);
for (int i = 0; i < K / 2; i++) {
a[i + 1].push_back(i + 1);
a[i + 1].push_back(K - i);
}
a[0].push_back(N);
a[K / 2 + 1].push_back(N);
for (int i = 0; i <= K / 2; i++) {
for (auto v : a[i]) {
for (auto u : a[i + 1]) {
ans.push_back({v, u});
}
}
}
} else {
int K = N;
vector<vector<int>> a(K / 2 + 1);
for (int i = 0; i < K / 2; i++) {
a[i + 1].push_back(i + 1);
a[i + 1].push_back(K - i);
if (i == (K / 2 - 1)) {
a[0].push_back(i + 1);
a[0].push_back(K - i);
}
}
for (int i = 0; i <= K / 2; i++) {
for (auto v : a[i]) {
for (auto u : a[i + 1]) {
ans.push_back({v, u});
}
}
}
}
cout << ans.size() << endl;
for (auto p : ans) {
cout << p.first << ' ' << p.second << "\n";
}
}
| #include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;
int main() {
int N;
cin >> N;
if (N == 3) {
cout << 2 << endl;
cout << "1 3\n2 3" << endl;
return 0;
} else if (N == 4) {
cout << 4 << endl;
cout << "1 2\n1 3\n4 2\n4 3\n";
return 0;
}
using P = pair<int, int>;
vector<P> ans;
if (N % 2 == 1) {
int K = N - 1;
vector<vector<int>> a(K / 2 + 2);
for (int i = 0; i < K / 2; i++) {
a[i + 1].push_back(i + 1);
a[i + 1].push_back(K - i);
}
a[0].push_back(N);
a[K / 2 + 1].push_back(N);
for (int i = 0; i <= K / 2; i++) {
for (auto v : a[i]) {
for (auto u : a[i + 1]) {
ans.push_back({v, u});
}
}
}
} else {
int K = N;
vector<vector<int>> a(K / 2 + 1);
for (int i = 0; i < K / 2; i++) {
a[i + 1].push_back(i + 1);
a[i + 1].push_back(K - i);
if (i == (K / 2 - 1)) {
a[0].push_back(i + 1);
a[0].push_back(K - i);
}
}
for (int i = 0; i < K / 2; i++) {
for (auto v : a[i]) {
for (auto u : a[i + 1]) {
ans.push_back({v, u});
}
}
}
}
cout << ans.size() << endl;
for (auto p : ans) {
cout << p.first << ' ' << p.second << "\n";
}
}
| replace | 69 | 70 | 69 | 70 | 0 | |
p03090 | C++ | Runtime Error | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i, a, b) ((a) <= (i) && (i) < (b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll, vector<ll>, greater<ll>> PQIG;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
//---------------------------------------------
int n;
cin >> n;
if (n == 3) {
cout << "2 1 3 2 3" << endl;
} else if (n % 2 == 0) {
int memo = n + 1;
int cnt = 0;
rep(i, n - 1) {
rep(j, n) {
if (i + 1 + j + 1 == memo || i >= j)
continue;
cnt++;
}
}
cout << cnt << endl;
rep(i, n - 1) {
rep(j, n) {
if (i + 1 + j + 1 == memo || i >= j)
continue;
cout << i + 1 << " " << j + 1 << endl;
}
}
} else {
exit(1);
}
} | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i, a, b) ((a) <= (i) && (i) < (b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll, vector<ll>, greater<ll>> PQIG;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
//---------------------------------------------
int n;
cin >> n;
if (n == 3) {
cout << "2 1 3 2 3" << endl;
} else if (n % 2 == 0) {
int memo = n + 1;
int cnt = 0;
rep(i, n - 1) {
rep(j, n) {
if (i + 1 + j + 1 == memo || i >= j)
continue;
cnt++;
}
}
cout << cnt << endl;
rep(i, n - 1) {
rep(j, n) {
if (i + 1 + j + 1 == memo || i >= j)
continue;
cout << i + 1 << " " << j + 1 << endl;
}
}
} else {
// exit(1);
pvec a(n / 2 + 1);
for (int i = 0; i < n / 2; i++) {
a[i] = P(i + 1, n - (i + 1));
// cout<<i+1<<n-i-1<<endl;
}
a[n / 2] = P(n, -1);
int x = a.size();
int cnt = 0;
for (int i = 0; i < x - 1; i++) {
for (int j = i + 1; j < x; j++) {
// cout<<a[i].fs<<" "<<a[j].fs<<endl;
// cout<<a[i].sc<<" "<<a[j].fs<<endl;
cnt += 2;
if (j == x - 1)
continue;
// cout<<a[i].fs<<" "<<a[j].sc<<endl;
// cout<<a[i].sc<<" "<<a[j].sc<<endl;
cnt += 2;
}
}
cout << cnt << endl;
for (int i = 0; i < x - 1; i++) {
for (int j = i + 1; j < x; j++) {
cout << a[i].fs << " " << a[j].fs << endl;
cout << a[i].sc << " " << a[j].fs << endl;
// cnt+=2;
if (j == x - 1)
continue;
cout << a[i].fs << " " << a[j].sc << endl;
cout << a[i].sc << " " << a[j].sc << endl;
// cnt+=2;
}
}
}
} | replace | 76 | 77 | 76 | 110 | 0 | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i, x, y) \
for (i64 i = i64(x), i##_max_for_repmacro = i64(y); \
i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class graph_type> class bridge_and_articulation {
private:
void dfs(int v, int p, int &k) { // vが根のときp=-1
used[v] = true;
ord[v] = low[v] = k++;
int count = 0;
for (const auto &edge : graph[v]) {
const int u = edge.to;
if (!used[u]) {
++count;
dfs(u, v, k);
low[v] = min(low[v], low[u]);
if (ord[v] < low[u])
bridges.push_back(make_pair(min(v, u), max(v, u)));
if (p != -1 and ord[v] <= low[u])
is_art[v] = true;
} else if (u != p)
low[v] = min(low[v], ord[u]);
}
if (p == -1 and count > 1)
is_art[v] = true;
if (is_art[v])
articulations.push_back(v);
}
public:
const int size;
graph_type graph;
vector<bool> used, is_art;
vector<int> ord, low, articulations;
vector<pair<int, int>> bridges;
bridge_and_articulation(const graph_type &graph)
: graph(graph), size(graph.size()), used(size), is_art(size), ord(size),
low(size) {
int k = 0;
for (int i = 0; i < size; ++i)
if (!used[i])
dfs(i, -1, k);
}
bool is_articulation(int v) const { return is_art[v]; }
bool is_bridge(int u, int v) const { // 辺(u,v)がグラフに含まれることを仮定する
if (ord[u] > ord[v])
swap(u, v);
return ord[u] < low[v];
}
};
struct edge {
i64 to;
};
void solve() {
// const i64 mod = 1'000'000'007;
i64 N, M;
cin >> N >> M;
vector<i64> a(M), b(M);
vector<vector<i64>> graph(N);
vector<i64> deg(N);
rep(i, 0, M) {
cin >> a[i] >> b[i];
--a[i];
--b[i];
graph[a[i]].emplace_back(b[i]);
graph[b[i]].emplace_back(a[i]);
++deg[a[i]];
++deg[b[i]];
}
const string yes = "Yes", no = "No";
rep(i, 0, N) {
if (deg[i] % 2 != 0) {
cout << no << endl;
return;
}
}
rep(i, 0, N) {
if (deg[i] >= 6) {
cout << yes << endl;
return;
}
}
map<i64, i64> cnt;
rep(i, 0, N) { ++cnt[deg[i]]; }
if (cnt[4] <= 1) {
cout << no << endl;
return;
}
if (cnt[4] == 2) {
vector<vector<edge>> g(N);
rep(i, 0, N) {
for (auto j : graph[i]) {
g[i].emplace_back(edge{j});
}
}
bridge_and_articulation<vector<vector<edge>>> ba(g);
rep(i, 0, N) {
if (ba.is_articulation(i)) {
cout << yes << endl;
return;
}
}
cout << no << endl;
}
if (cnt[4] >= 3) {
cout << yes << endl;
return;
}
assert(false);
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i, x, y) \
for (i64 i = i64(x), i##_max_for_repmacro = i64(y); \
i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class graph_type> class bridge_and_articulation {
private:
void dfs(int v, int p, int &k) { // vが根のときp=-1
used[v] = true;
ord[v] = low[v] = k++;
int count = 0;
for (const auto &edge : graph[v]) {
const int u = edge.to;
if (!used[u]) {
++count;
dfs(u, v, k);
low[v] = min(low[v], low[u]);
if (ord[v] < low[u])
bridges.push_back(make_pair(min(v, u), max(v, u)));
if (p != -1 and ord[v] <= low[u])
is_art[v] = true;
} else if (u != p)
low[v] = min(low[v], ord[u]);
}
if (p == -1 and count > 1)
is_art[v] = true;
if (is_art[v])
articulations.push_back(v);
}
public:
const int size;
graph_type graph;
vector<bool> used, is_art;
vector<int> ord, low, articulations;
vector<pair<int, int>> bridges;
bridge_and_articulation(const graph_type &graph)
: graph(graph), size(graph.size()), used(size), is_art(size), ord(size),
low(size) {
int k = 0;
for (int i = 0; i < size; ++i)
if (!used[i])
dfs(i, -1, k);
}
bool is_articulation(int v) const { return is_art[v]; }
bool is_bridge(int u, int v) const { // 辺(u,v)がグラフに含まれることを仮定する
if (ord[u] > ord[v])
swap(u, v);
return ord[u] < low[v];
}
};
struct edge {
i64 to;
};
void solve() {
// const i64 mod = 1'000'000'007;
i64 N, M;
cin >> N >> M;
vector<i64> a(M), b(M);
vector<vector<i64>> graph(N);
vector<i64> deg(N);
rep(i, 0, M) {
cin >> a[i] >> b[i];
--a[i];
--b[i];
graph[a[i]].emplace_back(b[i]);
graph[b[i]].emplace_back(a[i]);
++deg[a[i]];
++deg[b[i]];
}
const string yes = "Yes", no = "No";
rep(i, 0, N) {
if (deg[i] % 2 != 0) {
cout << no << endl;
return;
}
}
rep(i, 0, N) {
if (deg[i] >= 6) {
cout << yes << endl;
return;
}
}
map<i64, i64> cnt;
rep(i, 0, N) { ++cnt[deg[i]]; }
if (cnt[4] <= 1) {
cout << no << endl;
return;
}
if (cnt[4] == 2) {
vector<vector<edge>> g(N);
rep(i, 0, N) {
for (auto j : graph[i]) {
g[i].emplace_back(edge{j});
}
}
bridge_and_articulation<vector<vector<edge>>> ba(g);
rep(i, 0, N) {
if (ba.is_articulation(i)) {
cout << yes << endl;
return;
}
}
cout << no << endl;
return;
}
if (cnt[4] >= 3) {
cout << yes << endl;
return;
}
assert(false);
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
return 0;
}
| insert | 164 | 164 | 164 | 165 | 0 | |
p03091 | C++ | Runtime Error | /*
Rathin Bhargava
IIIT Bangalore
*/
#include <bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define pr(v) \
{ \
for (int i = 0; i < v.size(); i++) { \
v[i] == INF ? cout << "INF " : cout << v[i] << " "; \
} \
cout << endl; \
}
#define t1(x) cerr << #x << " : " << x << endl
#define t2(x, y) cerr << #x << " : " << x << " " << #y << " : " << y << endl
#define t3(x, y, z) \
cerr << #x << " : " << x << " " << #y << " : " << y << " " << #z << " : " \
<< z << endl
#define t4(a, b, c, d) \
cerr << #a << " : " << a << " " << #b << " : " << b << " " << #c << " : " \
<< c << " " << #d << " : " << d << endl
#define t5(a, b, c, d, e) \
cerr << #a << " : " << a << " " << #b << " : " << b << " " << #c << " : " \
<< c << " " << #d << " : " << d << " " << #e << " : " << e << endl
#define t6(a, b, c, d, e, f) \
cerr << #a << " : " << a << " " << #b << " : " << b << " " << #c << " : " \
<< c << " " << #d << " : " << d << " " << #e << " : " << e << " " << #f \
<< " : " << f << endl
#define GET_MACRO(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define t(...) GET_MACRO(__VA_ARGS__, t6, t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr << "here" << endl;
#define __ \
{ \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL); \
}
using namespace std;
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
return out << "(" << a.first << ", " << a.second << ")";
}
template <int> ostream &operator<<(ostream &os, const vector<int> &v) {
os << "[";
for (int i = 0; i < v.size(); ++i) {
if (v[i] != INF)
os << v[i];
else
os << "INF";
if (i != v.size() - 1)
os << ", ";
}
os << "]\n";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[";
for (int i = 0; i < v.size(); ++i) {
os << v[i];
;
if (i != v.size() - 1)
os << ", ";
}
os << "]\n";
return os;
}
const int N = 1e5 + 100;
vector<int> adj[N] = {};
vector<int> vis(N);
map<pair<int, int>, int> edges;
int dfs(int u, int root, int root2, int parent) {
while (u != root && u != root2) {
u = adj[u][0] + adj[u][1] - parent;
parent = u;
}
if (u == root2)
return 1;
return 0;
}
int main() {
__;
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
adj[a].pu(b);
adj[b].pu(a);
edges[{a, b}] = edges[{b, a}] = 0;
}
bool boo = false;
int idx = -1;
int cnt = 0;
vector<int> id;
for (int i = 0; i < n; i++)
if (adj[i].size() % 2 == 1) {
cout << "No" << endl;
return 0;
}
for (int i = 0; i < n; i++) {
if (adj[i].size() >= 6) {
cout << "Yes" << endl;
return 0;
} else if (adj[i].size() == 4) {
cnt++;
id.pu(i);
boo = true;
}
}
if (cnt > 2) {
cout << "Yes" << endl;
return 0;
} else if (cnt <= 1) {
cout << "No" << endl;
return 0;
}
int root = id[0], root2 = id[1];
int paths = 0;
for (auto v : adj[root]) {
paths += dfs(v, root, root2, root);
}
if (paths == 4)
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
}
| /*
Rathin Bhargava
IIIT Bangalore
*/
#include <bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define pr(v) \
{ \
for (int i = 0; i < v.size(); i++) { \
v[i] == INF ? cout << "INF " : cout << v[i] << " "; \
} \
cout << endl; \
}
#define t1(x) cerr << #x << " : " << x << endl
#define t2(x, y) cerr << #x << " : " << x << " " << #y << " : " << y << endl
#define t3(x, y, z) \
cerr << #x << " : " << x << " " << #y << " : " << y << " " << #z << " : " \
<< z << endl
#define t4(a, b, c, d) \
cerr << #a << " : " << a << " " << #b << " : " << b << " " << #c << " : " \
<< c << " " << #d << " : " << d << endl
#define t5(a, b, c, d, e) \
cerr << #a << " : " << a << " " << #b << " : " << b << " " << #c << " : " \
<< c << " " << #d << " : " << d << " " << #e << " : " << e << endl
#define t6(a, b, c, d, e, f) \
cerr << #a << " : " << a << " " << #b << " : " << b << " " << #c << " : " \
<< c << " " << #d << " : " << d << " " << #e << " : " << e << " " << #f \
<< " : " << f << endl
#define GET_MACRO(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define t(...) GET_MACRO(__VA_ARGS__, t6, t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr << "here" << endl;
#define __ \
{ \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL); \
}
using namespace std;
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
return out << "(" << a.first << ", " << a.second << ")";
}
template <int> ostream &operator<<(ostream &os, const vector<int> &v) {
os << "[";
for (int i = 0; i < v.size(); ++i) {
if (v[i] != INF)
os << v[i];
else
os << "INF";
if (i != v.size() - 1)
os << ", ";
}
os << "]\n";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[";
for (int i = 0; i < v.size(); ++i) {
os << v[i];
;
if (i != v.size() - 1)
os << ", ";
}
os << "]\n";
return os;
}
const int N = 1e5 + 100;
vector<int> adj[N] = {};
vector<int> vis(N);
map<pair<int, int>, int> edges;
int dfs(int u, int root, int root2, int parent) {
while (u != root && u != root2) {
parent = adj[u][0] + adj[u][1] - parent;
swap(parent, u);
}
if (u == root2)
return 1;
return 0;
}
int main() {
__;
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
adj[a].pu(b);
adj[b].pu(a);
edges[{a, b}] = edges[{b, a}] = 0;
}
bool boo = false;
int idx = -1;
int cnt = 0;
vector<int> id;
for (int i = 0; i < n; i++)
if (adj[i].size() % 2 == 1) {
cout << "No" << endl;
return 0;
}
for (int i = 0; i < n; i++) {
if (adj[i].size() >= 6) {
cout << "Yes" << endl;
return 0;
} else if (adj[i].size() == 4) {
cnt++;
id.pu(i);
boo = true;
}
}
if (cnt > 2) {
cout << "Yes" << endl;
return 0;
} else if (cnt <= 1) {
cout << "No" << endl;
return 0;
}
int root = id[0], root2 = id[1];
int paths = 0;
for (auto v : adj[root]) {
paths += dfs(v, root, root2, root);
}
if (paths == 4)
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
}
| replace | 86 | 88 | 86 | 88 | 0 | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int MX = 200002;
template <typename T> void cmax(T &x, const T &y) {
if (y > x)
x = y;
}
template <typename T> void read(T &x) {
x = 0;
char c = getchar();
bool f = 0;
while (!isdigit(c) && c != '-')
c = getchar();
if (c == '-')
f = 1, c = getchar();
while (isdigit(c))
x = x * 10 + c - '0', c = getchar();
if (f)
x = -x;
}
int deg[MX];
int fst[MX], nxt[MX], v[MX], lnum;
int n, m;
void addeg(int nu, int nv) {
nxt[++lnum] = fst[nu];
fst[nu] = lnum;
v[lnum] = nv;
deg[nv]++;
}
void input() {
read(n), read(m);
for (int i = 1; i <= m; i++) {
int nu, nv;
read(nu), read(nv);
addeg(nu, nv);
addeg(nv, nu);
}
}
void out_no() {
puts("No");
exit(0);
}
void out_yes() {
puts("Yes");
exit(0);
}
void check(int x, int y) {
queue<int> que;
static int way[MX];
memset(way, 0, sizeof(way));
que.push(x);
way[x] = 1;
while (!que.empty()) {
int a = que.front();
que.pop();
if (a == y)
continue;
for (int i = fst[a]; i; i = nxt[i]) {
int b = v[i];
if (!way[b])
que.push(b);
way[b] += way[x];
}
}
if (way[y] == 2)
out_yes();
else if (way[y] == 4)
out_no();
else
assert(0);
}
void work() {
for (int i = 1; i <= n; i++)
if (deg[i] & 1)
out_no();
for (int i = 1; i <= n; i++)
if (deg[i] >= 6)
out_yes();
vector<int> v4;
for (int i = 1; i <= n; i++)
if (deg[i] == 4)
v4.push_back(i);
if (v4.size() <= 1)
out_no();
else if (v4.size() == 2)
check(v4[0], v4[1]);
else
out_yes();
}
int main() {
input();
work();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int MX = 200002;
template <typename T> void cmax(T &x, const T &y) {
if (y > x)
x = y;
}
template <typename T> void read(T &x) {
x = 0;
char c = getchar();
bool f = 0;
while (!isdigit(c) && c != '-')
c = getchar();
if (c == '-')
f = 1, c = getchar();
while (isdigit(c))
x = x * 10 + c - '0', c = getchar();
if (f)
x = -x;
}
int deg[MX];
int fst[MX], nxt[MX], v[MX], lnum;
int n, m;
void addeg(int nu, int nv) {
nxt[++lnum] = fst[nu];
fst[nu] = lnum;
v[lnum] = nv;
deg[nv]++;
}
void input() {
read(n), read(m);
for (int i = 1; i <= m; i++) {
int nu, nv;
read(nu), read(nv);
addeg(nu, nv);
addeg(nv, nu);
}
}
void out_no() {
puts("No");
exit(0);
}
void out_yes() {
puts("Yes");
exit(0);
}
void check(int x, int y) {
queue<int> que;
static int way[MX];
memset(way, 0, sizeof(way));
que.push(x);
way[x] = 1;
while (!que.empty()) {
int a = que.front();
que.pop();
if (a == y)
continue;
for (int i = fst[a]; i; i = nxt[i]) {
int b = v[i];
if (!way[b])
que.push(b);
way[b] += way[a];
}
}
if (way[y] == 2)
out_yes();
else if (way[y] == 4)
out_no();
else
assert(0);
}
void work() {
for (int i = 1; i <= n; i++)
if (deg[i] & 1)
out_no();
for (int i = 1; i <= n; i++)
if (deg[i] >= 6)
out_yes();
vector<int> v4;
for (int i = 1; i <= n; i++)
if (deg[i] == 4)
v4.push_back(i);
if (v4.size() <= 1)
out_no();
else if (v4.size() == 2)
check(v4[0], v4[1]);
else
out_yes();
}
int main() {
input();
work();
return 0;
} | replace | 71 | 72 | 71 | 72 | 0 | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define per(i, a, b) for (int i = (a); i >= int(b); i--)
#define fir first
#define sec second
#define tct template <class type>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int maxn = 1e5, mod = 1e9 + 7;
int n, m, u[maxn + 5], v[maxn + 5], d[maxn + 5], fa[maxn + 5];
inline void red(int &x) { x += x >> 31 & mod; }
tct inline void cmax(type &x, type y) { x < y ? x = y : 0; }
tct inline void cmin(type &x, type y) { x > y ? x = y : 0; }
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int main() {
scanf("%d %d", &n, &m);
rep(i, 1, m) {
scanf("%d %d", &u[i], &v[i]);
d[u[i]]++, d[v[i]]++;
}
rep(i, 1, n) if (d[i] & 1) puts("No"), exit(0);
rep(i, 1, n) if (d[i] >= 6) puts("Yes"), exit(0);
int c = 0;
rep(i, 1, n) c += d[i] == 4;
if (c != 2)
puts(c >= 3 ? "Yes" : "No"), exit(0);
int x = 0;
rep(i, 1, n) if (d[i] == 4) {
x = i;
break;
}
rep(i, 1, n) fa[i] = i;
rep(i, 1, m) if (u[i] != x && v[i] != x) fa[find(u[i])] = v[i];
int y = 0;
rep(i, 1, n) y += find(i) == i;
puts(y == 3 ? "Yes" : "No");
return 0;
} | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define per(i, a, b) for (int i = (a); i >= int(b); i--)
#define fir first
#define sec second
#define tct template <class type>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int maxn = 1e5, mod = 1e9 + 7;
int n, m, u[maxn + 5], v[maxn + 5], d[maxn + 5], fa[maxn + 5];
inline void red(int &x) { x += x >> 31 & mod; }
tct inline void cmax(type &x, type y) { x < y ? x = y : 0; }
tct inline void cmin(type &x, type y) { x > y ? x = y : 0; }
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int main() {
scanf("%d %d", &n, &m);
rep(i, 1, m) {
scanf("%d %d", &u[i], &v[i]);
d[u[i]]++, d[v[i]]++;
}
rep(i, 1, n) if (d[i] & 1) puts("No"), exit(0);
rep(i, 1, n) if (d[i] >= 6) puts("Yes"), exit(0);
int c = 0;
rep(i, 1, n) c += d[i] == 4;
if (c != 2)
puts(c >= 3 ? "Yes" : "No"), exit(0);
int x = 0;
rep(i, 1, n) if (d[i] == 4) {
x = i;
break;
}
rep(i, 1, n) fa[i] = i;
rep(i, 1, m) if (u[i] != x && v[i] != x) fa[find(u[i])] = find(v[i]);
int y = 0;
rep(i, 1, n) y += find(i) == i;
puts(y == 3 ? "Yes" : "No");
return 0;
} | replace | 37 | 38 | 37 | 38 | 0 | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
const int MAXN = 100010;
void bye() {
std::cout << "No\n";
exit(0);
}
int deg[MAXN], xs[MAXN], ys[MAXN];
int n, m, vis[MAXN], tc;
int head[MAXN], nxt[MAXN << 1], to[MAXN << 1];
void addedge(int b, int e, int tot) {
nxt[++tot] = head[b];
to[head[b] = tot] = e;
nxt[++tot] = head[e];
to[head[e] = tot] = b;
}
int rt;
int dfs(int u, int fa = 0) {
if (!fa)
rt = u;
vis[u] = true;
for (int i = head[u]; i; i = nxt[i])
if (to[i] != fa) {
if (vis[to[i]] && to[i] == rt) {
xs[i >> 1] = 0;
++tc;
return true;
}
if (dfs(to[i], u)) {
xs[i >> 1] = 0;
++tc;
return true;
}
}
return false;
}
void reducecir() {
memset(vis, 0, n + 1 << 2);
memset(head, 0, n + 1 << 2);
for (int i = 1; i <= m; ++i)
if (xs[i])
addedge(xs[i], ys[i], i * 2 - 1);
for (int i = 1; i <= n; ++i)
if (!vis[i] && dfs(i))
return;
}
int main() {
std::ios_base::sync_with_stdio(false), std::cin.tie(0);
std::cin >> n >> m;
for (int i = 1; i <= m; ++i) {
std::cin >> xs[i] >> ys[i];
++deg[xs[i]];
++deg[ys[i]];
}
for (int i = 1; i <= n; ++i)
if (deg[i] & 1)
bye();
int cnt = 0, cnt2 = false;
for (int i = 1; i <= n; ++i)
cnt += deg[i] == 4, cnt2 |= deg[i] > 4;
if (!cnt2 && cnt < 3) {
reducecir();
if (tc < m)
reducecir();
if (tc == m)
bye();
}
std::cout << "Yes\n";
return 0;
}
| #include <bits/stdc++.h>
const int MAXN = 100010;
void bye() {
std::cout << "No\n";
exit(0);
}
int deg[MAXN], xs[MAXN], ys[MAXN];
int n, m, vis[MAXN], tc;
int head[MAXN], nxt[MAXN << 1], to[MAXN << 1];
void addedge(int b, int e, int tot) {
nxt[++tot] = head[b];
to[head[b] = tot] = e;
nxt[++tot] = head[e];
to[head[e] = tot] = b;
}
int rt;
int dfs(int u, int fa = 0) {
if (!fa)
rt = u;
vis[u] = true;
for (int i = head[u]; i; i = nxt[i])
if (to[i] != fa) {
if (vis[to[i]] && to[i] == rt) {
xs[i >> 1] = 0;
++tc;
return true;
}
if (!vis[to[i]] && dfs(to[i], u)) {
xs[i >> 1] = 0;
++tc;
return true;
}
}
return false;
}
void reducecir() {
memset(vis, 0, n + 1 << 2);
memset(head, 0, n + 1 << 2);
for (int i = 1; i <= m; ++i)
if (xs[i])
addedge(xs[i], ys[i], i * 2 - 1);
for (int i = 1; i <= n; ++i)
if (!vis[i] && dfs(i))
return;
}
int main() {
std::ios_base::sync_with_stdio(false), std::cin.tie(0);
std::cin >> n >> m;
for (int i = 1; i <= m; ++i) {
std::cin >> xs[i] >> ys[i];
++deg[xs[i]];
++deg[ys[i]];
}
for (int i = 1; i <= n; ++i)
if (deg[i] & 1)
bye();
int cnt = 0, cnt2 = false;
for (int i = 1; i <= n; ++i)
cnt += deg[i] == 4, cnt2 |= deg[i] > 4;
if (!cnt2 && cnt < 3) {
reducecir();
if (tc < m)
reducecir();
if (tc == m)
bye();
}
std::cout << "Yes\n";
return 0;
}
| replace | 28 | 29 | 28 | 29 | 0 | |
p03091 | C++ | Runtime Error |
#include "bits/stdc++.h"
using namespace std;
#pragma warning(disable : 4996)
int dfs(const vector<vector<int>> &edges, int now, int from, vector<int> ss) {
if (now == ss[0])
return 0;
else if (now == ss[1])
return 1;
for (auto e : edges[now]) {
if (e != from)
return dfs(edges, e, now, ss);
}
assert(false);
}
int main() {
int N, M;
cin >> N >> M;
vector<vector<int>> edges(N);
for (int i = 0; i < M; ++i) {
int a, b;
cin >> a >> b;
a--;
b--;
edges[a].push_back(b);
edges[b].push_back(a);
}
bool ok = true;
for (int i = 0; i < N; ++i) {
if (edges[i].size() == 0)
ok = false;
else if (edges[i].size() % 2 == 1)
ok = false;
}
if (ok) {
bool aok = false;
int num = 0;
for (int i = 0; i < N; ++i) {
if (edges[i].size() >= 6)
aok = true;
else if (edges[i].size() >= 4)
num++;
}
if (aok || num >= 3)
aok = true;
else if (num == 2) {
vector<int> ss;
for (int i = 0; i < N; ++i) {
if (edges[i].size() == 4) {
ss.push_back(i);
}
}
int to_same_num = 0;
for (int a = 0; a < 2; ++a) {
int now = ss[a];
for (auto e : edges[now]) {
int to = dfs(edges, e, now, ss);
if (a == to)
to_same_num++;
}
}
if (to_same_num == 4)
aok = true;
else {
assert(to_same_num == 0);
aok = false;
}
} else {
assert(false);
}
if (aok) {
ok = true;
} else {
ok = false;
}
}
if (ok)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
#pragma warning(disable : 4996)
int dfs(const vector<vector<int>> &edges, int now, int from, vector<int> ss) {
if (now == ss[0])
return 0;
else if (now == ss[1])
return 1;
for (auto e : edges[now]) {
if (e != from)
return dfs(edges, e, now, ss);
}
assert(false);
}
int main() {
int N, M;
cin >> N >> M;
vector<vector<int>> edges(N);
for (int i = 0; i < M; ++i) {
int a, b;
cin >> a >> b;
a--;
b--;
edges[a].push_back(b);
edges[b].push_back(a);
}
bool ok = true;
for (int i = 0; i < N; ++i) {
if (edges[i].size() == 0)
ok = false;
else if (edges[i].size() % 2 == 1)
ok = false;
}
if (ok) {
bool aok = false;
int num = 0;
for (int i = 0; i < N; ++i) {
if (edges[i].size() >= 6)
aok = true;
else if (edges[i].size() >= 4)
num++;
}
if (aok || num >= 3)
aok = true;
else if (num == 2) {
vector<int> ss;
for (int i = 0; i < N; ++i) {
if (edges[i].size() == 4) {
ss.push_back(i);
}
}
int to_same_num = 0;
for (int a = 0; a < 2; ++a) {
int now = ss[a];
for (auto e : edges[now]) {
int to = dfs(edges, e, now, ss);
if (a == to)
to_same_num++;
}
}
if (to_same_num == 4)
aok = true;
else {
assert(to_same_num == 0);
aok = false;
}
} else {
// assert(false);
}
if (aok) {
ok = true;
} else {
ok = false;
}
}
if (ok)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
| replace | 70 | 71 | 70 | 71 | 0 | |
p03091 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
struct edge {
int v, nxt;
} e[500005];
int n, m, h[100005], t, deg[100005], vis[100005];
void add(int u, int v) {
e[++t].v = v;
e[t].nxt = h[u];
h[u] = t;
}
void dfs(int u) {
for (int i = h[u]; i; i = e[i].nxt) {
int v = e[i].v;
if (vis[v])
continue;
dfs(v);
}
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int u, v;
scanf("%d%d", &u, &v);
add(u, v);
add(v, u);
deg[u]++, deg[v]++;
}
for (int i = 1; i <= n; i++)
if (deg[i] % 2) {
printf("No\n");
return 0;
}
int ct = 0;
for (int i = 1; i <= n; i++)
if (deg[i] >= 6) {
printf("Yes\n");
return 0;
} else if (deg[i] == 4)
ct++;
if (ct != 2) {
if (ct <= 1)
printf("No\n");
else
printf("Yes\n");
return 0;
}
for (int i = 1; i <= n; i++)
if (deg[i] == 4) {
vis[i] = 1;
break;
}
for (int i = 1; i <= n; i++)
if (deg[i] == 2) {
dfs(i);
for (int i = 1; i <= n; i++)
if (!vis[i]) {
printf("Yes\n");
return 0;
}
printf("No\n");
return 0;
}
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
struct edge {
int v, nxt;
} e[500005];
int n, m, h[100005], t, deg[100005], vis[100005];
void add(int u, int v) {
e[++t].v = v;
e[t].nxt = h[u];
h[u] = t;
}
void dfs(int u) {
vis[u] = 1;
for (int i = h[u]; i; i = e[i].nxt) {
int v = e[i].v;
if (vis[v])
continue;
dfs(v);
}
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int u, v;
scanf("%d%d", &u, &v);
add(u, v);
add(v, u);
deg[u]++, deg[v]++;
}
for (int i = 1; i <= n; i++)
if (deg[i] % 2) {
printf("No\n");
return 0;
}
int ct = 0;
for (int i = 1; i <= n; i++)
if (deg[i] >= 6) {
printf("Yes\n");
return 0;
} else if (deg[i] == 4)
ct++;
if (ct != 2) {
if (ct <= 1)
printf("No\n");
else
printf("Yes\n");
return 0;
}
for (int i = 1; i <= n; i++)
if (deg[i] == 4) {
vis[i] = 1;
break;
}
for (int i = 1; i <= n; i++)
if (deg[i] == 2) {
dfs(i);
for (int i = 1; i <= n; i++)
if (!vis[i]) {
printf("Yes\n");
return 0;
}
printf("No\n");
return 0;
}
return 0;
} | insert | 14 | 14 | 14 | 15 | 0 | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
template <typename T> void vprint(T &v) {
REP(i, v.size()) { cout << v[i] << " "; }
cout << endl;
}
vector<ll> G[101010];
void answer(bool flag) {
cout << (flag ? "Yes" : "No") << endl;
exit(0);
}
vector<bool> visited(101010, false);
bool dfs(ll now, ll par, ll x, ll y) {
if (now == y)
return false;
if (now == x && visited[now])
return true;
if (visited[now])
return false;
visited[now] = true;
bool res = false;
REP(i, G[now].size()) {
ll next = G[now][i];
if (next == par)
continue;
res = (res || dfs(next, now, x, y));
}
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, M;
cin >> N >> M;
REP(i, M) {
ll a, b;
cin >> a >> b;
a--, b--;
G[a].push_back(b);
G[b].push_back(a);
}
bool flag = true;
REP(i, N) {
if (G[i].size() % 2 != 0)
flag = false;
}
if (!flag) {
answer(false);
}
vector<ll> four;
REP(i, N) {
if (G[i].size() > 5)
answer(true);
if (G[i].size() == 4)
four.push_back(i);
}
if (four.size() > 2)
answer(true);
if (four.size() == 1)
answer(false);
ll x = four[0];
ll y = four[1];
answer(dfs(x, -1, x, y));
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
template <typename T> void vprint(T &v) {
REP(i, v.size()) { cout << v[i] << " "; }
cout << endl;
}
vector<ll> G[101010];
void answer(bool flag) {
cout << (flag ? "Yes" : "No") << endl;
exit(0);
}
vector<bool> visited(101010, false);
bool dfs(ll now, ll par, ll x, ll y) {
if (now == y)
return false;
if (now == x && visited[now])
return true;
if (visited[now])
return false;
visited[now] = true;
bool res = false;
REP(i, G[now].size()) {
ll next = G[now][i];
if (next == par)
continue;
res = (res || dfs(next, now, x, y));
}
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, M;
cin >> N >> M;
REP(i, M) {
ll a, b;
cin >> a >> b;
a--, b--;
G[a].push_back(b);
G[b].push_back(a);
}
bool flag = true;
REP(i, N) {
if (G[i].size() % 2 != 0)
flag = false;
}
if (!flag) {
answer(false);
}
vector<ll> four;
REP(i, N) {
if (G[i].size() > 5)
answer(true);
if (G[i].size() == 4)
four.push_back(i);
}
if (four.size() > 2)
answer(true);
if (four.size() < 2)
answer(false);
ll x = four[0];
ll y = four[1];
answer(dfs(x, -1, x, y));
return 0;
} | replace | 81 | 82 | 81 | 82 | 0 | |
p03091 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define NO return puts("No"), 0
#define YES return puts("Yes"), 0
const int N = 1e5 + 5;
int n, m, cnt, tmp[2], vis[N];
vector<int> G[N];
template <typename _Tp> inline void IN(_Tp &x) {
char ch;
bool flag = 0;
x = 0;
while (ch = getchar(), !isdigit(ch))
if (ch == '-')
flag = 1;
while (isdigit(ch))
x = x * 10 + ch - '0', ch = getchar();
if (flag)
x = -x;
}
inline void addedge(int u = 0, int v = 0) {
IN(u), IN(v), G[u].push_back(v), G[v].push_back(u);
}
void dfs(int u) {
vis[u] = true;
for (auto v : G[u])
if (vis[v] == 2)
tmp[cnt++] = v;
else
dfs(v);
}
int main() {
IN(n), IN(m);
for (int i = 1; i <= m; ++i)
addedge();
int max_du = 0, max_tot = 0;
for (int i = 1; i <= n; ++i)
if (G[i].size() & 1)
NO;
else if (G[i].size() == max_du)
++max_tot;
else if (G[i].size() > max_du)
max_du = G[i].size(), max_tot = 1;
if (max_du >= 6 || (max_du == 4 && max_tot >= 3))
YES;
else if (max_du == 2 || max_tot == 1)
NO;
else if (max_du == 4 && max_tot == 2) {
for (int i = 1; i <= n; ++i)
if (G[i].size() == 4)
vis[i] = 2;
for (int i = 1; i <= n; ++i)
if (!vis[i]) {
cnt = 0, dfs(i);
if (tmp[0] == tmp[1])
YES;
}
}
NO;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define NO return puts("No"), 0
#define YES return puts("Yes"), 0
const int N = 1e5 + 5;
int n, m, cnt, tmp[2], vis[N];
vector<int> G[N];
template <typename _Tp> inline void IN(_Tp &x) {
char ch;
bool flag = 0;
x = 0;
while (ch = getchar(), !isdigit(ch))
if (ch == '-')
flag = 1;
while (isdigit(ch))
x = x * 10 + ch - '0', ch = getchar();
if (flag)
x = -x;
}
inline void addedge(int u = 0, int v = 0) {
IN(u), IN(v), G[u].push_back(v), G[v].push_back(u);
}
void dfs(int u) {
vis[u] = true;
for (auto v : G[u])
if (vis[v] == 2)
tmp[cnt++] = v;
else if (!vis[v])
dfs(v);
}
int main() {
IN(n), IN(m);
for (int i = 1; i <= m; ++i)
addedge();
int max_du = 0, max_tot = 0;
for (int i = 1; i <= n; ++i)
if (G[i].size() & 1)
NO;
else if (G[i].size() == max_du)
++max_tot;
else if (G[i].size() > max_du)
max_du = G[i].size(), max_tot = 1;
if (max_du >= 6 || (max_du == 4 && max_tot >= 3))
YES;
else if (max_du == 2 || max_tot == 1)
NO;
else if (max_du == 4 && max_tot == 2) {
for (int i = 1; i <= n; ++i)
if (G[i].size() == 4)
vis[i] = 2;
for (int i = 1; i <= n; ++i)
if (!vis[i]) {
cnt = 0, dfs(i);
if (tmp[0] == tmp[1])
YES;
}
}
NO;
} | replace | 36 | 37 | 36 | 37 | 0 | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
#define Tp template <typename Ty>
#define Ts template <typename Ty, typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int &
#define I inline
#define W while
#define N 100000
#define add(x, y) (e[++ee].nxt = lnk[x], ++d[e[lnk[x] = ee].to = y])
using namespace std;
int n, m, ee, d[N + 5], lnk[N + 5];
struct edge {
int to, nxt;
} e[2 * N + 5];
int tot;
I void DFS(CI s, CI x, CI y, CI lst = 0) {
if (lst && s == x)
return;
if (s == y)
return (void)(++tot);
for (RI i = lnk[s]; i; i = e[i].nxt)
e[i].to ^ lst && (DFS(e[i].to, x, y, s), 0);
}
int main() {
RI i, x, y, f = 0, t = 0;
for (scanf("%d%d", &n, &m), i = 1; i <= m; ++i)
scanf("%d%d", &x, &y), add(x, y), add(y, x);
for (i = 1; i <= n; ++i)
if (d[i] & 1)
return puts("No"), 0;
else
d[i] >= 6 ? f = 1 : d[i] == 4 && (++t, (x ? y : x) = i);
if (f || t >= 3)
return puts("Yes"), 0;
if (t ^ 2)
return puts("No"), 0;
return DFS(x, x, y), puts(tot == 2 ? "Yes" : "No"), 0;
} | #include <bits/stdc++.h>
#define Tp template <typename Ty>
#define Ts template <typename Ty, typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int &
#define I inline
#define W while
#define N 100000
#define add(x, y) (e[++ee].nxt = lnk[x], ++d[e[lnk[x] = ee].to = y])
using namespace std;
int n, m, ee, d[N + 5], lnk[N + 5];
struct edge {
int to, nxt;
} e[2 * N + 5];
int tot;
I void DFS(CI s, CI x, CI y, CI lst = 0) {
if (lst && s == x)
return;
if (s == y)
return (void)(++tot);
for (RI i = lnk[s]; i; i = e[i].nxt)
e[i].to ^ lst && (DFS(e[i].to, x, y, s), 0);
}
int main() {
RI i, x, y, f = 0, t = 0;
for (scanf("%d%d", &n, &m), i = 1; i <= m; ++i)
scanf("%d%d", &x, &y), add(x, y), add(y, x);
for (x = y = 0, i = 1; i <= n; ++i)
if (d[i] & 1)
return puts("No"), 0;
else
d[i] >= 6 ? f = 1 : d[i] == 4 && (++t, (x ? y : x) = i);
if (f || t >= 3)
return puts("Yes"), 0;
if (t ^ 2)
return puts("No"), 0;
return DFS(x, x, y), puts(tot == 2 ? "Yes" : "No"), 0;
} | replace | 29 | 30 | 29 | 30 | 0 | |
p03091 | C++ | Time Limit Exceeded | /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author
*/
#include <fstream>
#include <iostream>
#ifndef _TB
#define _TB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b - 1; i >= a; --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)
#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define ABS(A) ((A) < 0 ? (-(A)) : (A))
#define ALL(V) V.begin(), V.end()
#define SIZE(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define EPS 1e-7
#define Pi 3.14159265358979
#define FILL(a, v) memset(a, v, sizeof(a))
using namespace std;
typedef long long Long;
typedef unsigned long long ULong;
typedef unsigned int Uint;
typedef unsigned char Uchar;
typedef vector<int> VI;
typedef pair<int, int> PII;
#define X first
#define Y second
typedef std::pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<ui, ui> puu;
template <typename T, typename U>
std::istream &operator>>(std::istream &i, pair<T, U> &p) {
i >> p.X >> p.Y;
return i;
}
template <typename T> std::istream &operator>>(std::istream &i, vector<T> &t) {
for (auto &v : t) {
i >> v;
}
return i;
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &o, const pair<T, U> &p) {
o << p.X << ' ' << p.Y;
return o;
}
template <typename T>
std::ostream &operator<<(std::ostream &o, const vector<T> &t) {
if (t.empty())
o << '\n';
for (size_t i = 0; i < t.size(); ++i) {
o << t[i] << " \n"[i == t.size() - 1];
}
return o;
}
template <typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template <typename T> bool in(T a, T b, T c) { return a <= b && b < c; }
ui logceil(int x) { return 8 * sizeof(int) - __builtin_clz(x); }
namespace std {
template <typename T, typename U> struct hash<pair<T, U>> {
hash<T> t;
hash<U> u;
size_t operator()(const pair<T, U> &p) const {
return t(p.x) ^ (u(p.y) << 7);
}
};
} // namespace std
template <typename T, typename F> T bsh(T l, T h, const F &f) {
T r = -1, m;
while (l <= h) {
m = (l + h) / 2;
if (f(m)) {
l = m + 1;
r = m;
} else {
h = m - 1;
}
}
return r;
}
template <typename F>
double bshd(double l, double h, const F &f, double p = 1e-9) {
ui r = 3 + (ui)log2((h - l) / p);
while (r--) {
double m = (l + h) / 2;
if (f(m)) {
l = m;
} else {
h = m;
}
}
return (l + h) / 2;
}
template <typename T, typename F> T bsl(T l, T h, const F &f) {
T r = -1, m;
while (l <= h) {
m = (l + h) / 2;
if (f(m)) {
h = m - 1;
r = m;
} else {
l = m + 1;
}
}
return r;
}
template <typename F>
double bsld(double l, double h, const F &f, double p = 1e-9) {
ui r = 3 + (ui)log2((h - l) / p);
while (r--) {
double m = (l + h) / 2;
if (f(m)) {
h = m;
} else {
l = m;
}
}
return (l + h) / 2;
}
template <typename T> T gcd(T a, T b) {
if (a < b)
swap(a, b);
return b ? gcd(b, a % b) : a;
}
template <typename T> class vector2 : public vector<vector<T>> {
public:
vector2() {}
vector2(size_t a, size_t b, T t = T())
: vector<vector<T>>(a, vector<T>(b, t)) {}
};
template <typename T> class vector3 : public vector<vector2<T>> {
public:
vector3() {}
vector3(size_t a, size_t b, size_t c, T t = T())
: vector<vector2<T>>(a, vector2<T>(b, c, t)) {}
};
template <typename T> class vector4 : public vector<vector3<T>> {
public:
vector4() {}
vector4(size_t a, size_t b, size_t c, size_t d, T t = T())
: vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {}
};
template <typename T> class vector5 : public vector<vector4<T>> {
public:
vector5() {}
vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T())
: vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {}
};
void fastIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
#endif
const int MAXN = 100100;
VI g[MAXN];
set<int> v;
int go(int v, int p) {
if (g[v].size() > 2)
return v;
for (auto nv : g[v])
if (nv != p)
return go(nv, p);
}
class CThreeCircuits {
public:
string solve1(std::istream &in) {
fastIO();
int n, m;
in >> n >> m;
v.clear();
REP(i, n) { g[i].clear(); }
int b, c;
REP(i, m) {
in >> b >> c;
--b;
--c;
g[b].push_back(c);
g[c].push_back(b);
}
bool bad = false;
bool has6 = false;
REP(i, n) {
if (g[i].size() % 2 == 1)
bad = true;
if (g[i].size() >= 4) {
v.insert(i);
}
if (g[i].size() >= 6)
has6 = true;
}
if (bad) {
return "No";
}
int c4 = v.size();
if (has6 || c4 >= 3) {
return "Yes";
}
if (c4 < 2) {
return "No";
}
int c1 = *v.begin();
for (auto v : g[c1]) {
if (go(v, c1) == c1)
return "Yes";
}
return "No";
}
void solve(std::istream &in, std::ostream &out) { out << solve1(in) << endl; }
};
int main() {
CThreeCircuits solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
return 0;
}
| /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author
*/
#include <fstream>
#include <iostream>
#ifndef _TB
#define _TB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b - 1; i >= a; --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)
#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define ABS(A) ((A) < 0 ? (-(A)) : (A))
#define ALL(V) V.begin(), V.end()
#define SIZE(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define EPS 1e-7
#define Pi 3.14159265358979
#define FILL(a, v) memset(a, v, sizeof(a))
using namespace std;
typedef long long Long;
typedef unsigned long long ULong;
typedef unsigned int Uint;
typedef unsigned char Uchar;
typedef vector<int> VI;
typedef pair<int, int> PII;
#define X first
#define Y second
typedef std::pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<ui, ui> puu;
template <typename T, typename U>
std::istream &operator>>(std::istream &i, pair<T, U> &p) {
i >> p.X >> p.Y;
return i;
}
template <typename T> std::istream &operator>>(std::istream &i, vector<T> &t) {
for (auto &v : t) {
i >> v;
}
return i;
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &o, const pair<T, U> &p) {
o << p.X << ' ' << p.Y;
return o;
}
template <typename T>
std::ostream &operator<<(std::ostream &o, const vector<T> &t) {
if (t.empty())
o << '\n';
for (size_t i = 0; i < t.size(); ++i) {
o << t[i] << " \n"[i == t.size() - 1];
}
return o;
}
template <typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template <typename T> bool in(T a, T b, T c) { return a <= b && b < c; }
ui logceil(int x) { return 8 * sizeof(int) - __builtin_clz(x); }
namespace std {
template <typename T, typename U> struct hash<pair<T, U>> {
hash<T> t;
hash<U> u;
size_t operator()(const pair<T, U> &p) const {
return t(p.x) ^ (u(p.y) << 7);
}
};
} // namespace std
template <typename T, typename F> T bsh(T l, T h, const F &f) {
T r = -1, m;
while (l <= h) {
m = (l + h) / 2;
if (f(m)) {
l = m + 1;
r = m;
} else {
h = m - 1;
}
}
return r;
}
template <typename F>
double bshd(double l, double h, const F &f, double p = 1e-9) {
ui r = 3 + (ui)log2((h - l) / p);
while (r--) {
double m = (l + h) / 2;
if (f(m)) {
l = m;
} else {
h = m;
}
}
return (l + h) / 2;
}
template <typename T, typename F> T bsl(T l, T h, const F &f) {
T r = -1, m;
while (l <= h) {
m = (l + h) / 2;
if (f(m)) {
h = m - 1;
r = m;
} else {
l = m + 1;
}
}
return r;
}
template <typename F>
double bsld(double l, double h, const F &f, double p = 1e-9) {
ui r = 3 + (ui)log2((h - l) / p);
while (r--) {
double m = (l + h) / 2;
if (f(m)) {
h = m;
} else {
l = m;
}
}
return (l + h) / 2;
}
template <typename T> T gcd(T a, T b) {
if (a < b)
swap(a, b);
return b ? gcd(b, a % b) : a;
}
template <typename T> class vector2 : public vector<vector<T>> {
public:
vector2() {}
vector2(size_t a, size_t b, T t = T())
: vector<vector<T>>(a, vector<T>(b, t)) {}
};
template <typename T> class vector3 : public vector<vector2<T>> {
public:
vector3() {}
vector3(size_t a, size_t b, size_t c, T t = T())
: vector<vector2<T>>(a, vector2<T>(b, c, t)) {}
};
template <typename T> class vector4 : public vector<vector3<T>> {
public:
vector4() {}
vector4(size_t a, size_t b, size_t c, size_t d, T t = T())
: vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {}
};
template <typename T> class vector5 : public vector<vector4<T>> {
public:
vector5() {}
vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T())
: vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {}
};
void fastIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
#endif
const int MAXN = 100100;
VI g[MAXN];
set<int> v;
int go(int v, int p) {
if (g[v].size() > 2)
return v;
for (auto nv : g[v])
if (nv != p)
return go(nv, v);
}
class CThreeCircuits {
public:
string solve1(std::istream &in) {
fastIO();
int n, m;
in >> n >> m;
v.clear();
REP(i, n) { g[i].clear(); }
int b, c;
REP(i, m) {
in >> b >> c;
--b;
--c;
g[b].push_back(c);
g[c].push_back(b);
}
bool bad = false;
bool has6 = false;
REP(i, n) {
if (g[i].size() % 2 == 1)
bad = true;
if (g[i].size() >= 4) {
v.insert(i);
}
if (g[i].size() >= 6)
has6 = true;
}
if (bad) {
return "No";
}
int c4 = v.size();
if (has6 || c4 >= 3) {
return "Yes";
}
if (c4 < 2) {
return "No";
}
int c1 = *v.begin();
for (auto v : g[c1]) {
if (go(v, c1) == c1)
return "Yes";
}
return "No";
}
void solve(std::istream &in, std::ostream &out) { out << solve1(in) << endl; }
};
int main() {
CThreeCircuits solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
return 0;
}
| replace | 191 | 192 | 191 | 192 | TLE | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
vector<vector<int>> grh;
int s, t;
void dfs(int crr, int prt) {
if (crr != prt && crr == s) {
cout << "Yes" << '\n';
exit(0);
}
for (int nxt : grh[crr]) {
if (nxt != prt && nxt != t) {
dfs(nxt, crr);
}
}
}
int main() {
int n, m;
cin >> n >> m;
vector<int> dgr(n, 0);
grh.resize(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
dgr[--a]++;
dgr[--b]++;
grh[a].push_back(b);
grh[b].push_back(a);
}
vector<int> pts;
for (int i = 0; i < n; i++) {
if (dgr[i] & 1) {
cout << "No" << '\n';
return 0;
} else if (dgr[i] >= 6) {
assert(false);
cout << "Yes" << '\n';
return 0;
} else if (dgr[i] == 4) {
pts.push_back(i);
}
}
if (pts.size() >= 3) {
cout << "Yes" << '\n';
return 0;
} else if (pts.size() <= 1) {
cout << "No" << '\n';
return 0;
}
s = pts[0];
t = pts[1];
dfs(s, s);
cout << "No" << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
vector<vector<int>> grh;
int s, t;
void dfs(int crr, int prt) {
if (crr != prt && crr == s) {
cout << "Yes" << '\n';
exit(0);
}
for (int nxt : grh[crr]) {
if (nxt != prt && nxt != t) {
dfs(nxt, crr);
}
}
}
int main() {
int n, m;
cin >> n >> m;
vector<int> dgr(n, 0);
grh.resize(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
dgr[--a]++;
dgr[--b]++;
grh[a].push_back(b);
grh[b].push_back(a);
}
vector<int> pts;
for (int i = 0; i < n; i++) {
if (dgr[i] & 1) {
cout << "No" << '\n';
return 0;
}
}
for (int i = 0; i < n; i++) {
if (dgr[i] >= 6) {
cout << "Yes" << '\n';
return 0;
} else if (dgr[i] == 4) {
pts.push_back(i);
}
}
if (pts.size() >= 3) {
cout << "Yes" << '\n';
return 0;
} else if (pts.size() <= 1) {
cout << "No" << '\n';
return 0;
}
s = pts[0];
t = pts[1];
dfs(s, s);
cout << "No" << '\n';
return 0;
}
| replace | 33 | 35 | 33 | 37 | -6 | 34d97a0f-600b-41dd-ba03-2e66ea7332aa.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03091/C++/s933329043.cpp:35: int main(): Assertion `false' failed.
|
p03091 | C++ | Runtime Error | // 18:10~
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
static int deg[100000];
static vector<int> edges[100000];
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
--a;
--b;
++deg[a];
++deg[b];
}
static bool odd, six;
vector<int> four;
for (int i = 0; i < n; ++i) {
if (deg[i] & 1)
odd = true;
if (deg[i] >= 6)
six = true;
if (deg[i] == 4)
four.emplace_back(i);
}
if (odd)
cout << "No" << endl;
else if (six)
cout << "Yes" << endl;
else if (four.size() >= 3)
cout << "Yes" << endl;
else if (four.size() <= 1)
cout << "No" << endl;
else {
for (int i = 0; i < 4; ++i) {
queue<pair<int, int>> q;
q.emplace(edges[four[0]][i], four[0]);
while (!q.empty()) {
auto t = q.front();
q.pop();
if (t.first == four[1])
break;
if (t.first == four[0]) {
cout << "Yes" << endl;
return 0;
}
for (int to : edges[t.first]) {
if (to == t.second)
continue;
q.emplace(to, t.first);
}
}
}
cout << "No" << endl;
}
return 0;
} | // 18:10~
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
static int deg[100000];
static vector<int> edges[100000];
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
--a;
--b;
++deg[a];
++deg[b];
edges[a].emplace_back(b);
edges[b].emplace_back(a);
}
static bool odd, six;
vector<int> four;
for (int i = 0; i < n; ++i) {
if (deg[i] & 1)
odd = true;
if (deg[i] >= 6)
six = true;
if (deg[i] == 4)
four.emplace_back(i);
}
if (odd)
cout << "No" << endl;
else if (six)
cout << "Yes" << endl;
else if (four.size() >= 3)
cout << "Yes" << endl;
else if (four.size() <= 1)
cout << "No" << endl;
else {
for (int i = 0; i < 4; ++i) {
queue<pair<int, int>> q;
q.emplace(edges[four[0]][i], four[0]);
while (!q.empty()) {
auto t = q.front();
q.pop();
if (t.first == four[1])
break;
if (t.first == four[0]) {
cout << "Yes" << endl;
return 0;
}
for (int to : edges[t.first]) {
if (to == t.second)
continue;
q.emplace(to, t.first);
}
}
}
cout << "No" << endl;
}
return 0;
} | insert | 20 | 20 | 20 | 22 | 0 | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i, a, b) for (int(i) = (a); i < (b); ++(i))
#define EFOR(i, a, b) for (int(i) = (a); i <= (b); ++(i))
#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define REP rep
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define all(X) (X).begin(), (X).end()
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD = 1e9 + 7;
#define rall(X) (X).rbegin(), (X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)), (X).end())
#define reps(X, S, Y) for (int(X) = S; (X) < (Y); ++(X))
#define rreps(X, S, Y) for (int(X) = (Y)-1; (X) >= (S); --(X))
template <class T> inline bool MX(T &l, const T &r) {
return l < r ? l = r, 1 : 0;
}
template <class T> inline bool MN(T &l, const T &r) {
return l > r ? l = r, 1 : 0;
}
int N;
int M;
set<int> es[114514];
bool used[114514];
int prv[114514];
int depth[114514];
void Erase(int u, int v) {
rep(i, 2) {
assert(es[u].count(v));
es[u].erase(v);
swap(u, v);
}
}
bool check() {
fill(used, used + N, false);
fill(prv, prv + N, -1);
queue<int> que;
int root = -1;
rep(v, N) {
if (!es[v].empty()) {
root = v;
used[v] = 1;
que.push(v);
break;
}
}
if (root == -1)
return false;
using Ans = pair<int, pii>;
Ans ans(MOD, pii(-1, -1));
while (!que.empty()) {
int v = que.front();
que.pop();
for (int u : es[v]) {
if (!used[u]) {
prv[u] = v;
used[u] = true;
depth[u] = depth[v] + 1;
que.push(u);
} else if (prv[v] != u) {
MN(ans, Ans(1 + depth[v] + depth[u], pii(v, u)));
}
}
}
if (ans.X == MOD)
return false;
int p, q;
tie(p, q) = ans.Y;
assert(p != -1);
Erase(p, q);
// cout << p << ", " << q << endl;
rep(i, 2) {
while (p != root) {
int np = prv[p];
Erase(p, np);
// cout << p << ", " << np << endl;
p = np;
}
p = q;
}
return true;
}
signed main() {
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(0);
cin >> N >> M;
rep(i, M) {
int a, b;
cin >> a >> b;
--a;
--b;
es[a].insert(b);
es[b].insert(a);
}
rep(v, N) {
if (es[v].size() % 2) {
puts("No");
return 0;
}
}
rep(i, 3) {
// cout << i << endl;
if (!check()) {
puts("No");
return 0;
}
}
puts("Yes");
}
| #include <bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i, a, b) for (int(i) = (a); i < (b); ++(i))
#define EFOR(i, a, b) for (int(i) = (a); i <= (b); ++(i))
#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define REP rep
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define all(X) (X).begin(), (X).end()
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD = 1e9 + 7;
#define rall(X) (X).rbegin(), (X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)), (X).end())
#define reps(X, S, Y) for (int(X) = S; (X) < (Y); ++(X))
#define rreps(X, S, Y) for (int(X) = (Y)-1; (X) >= (S); --(X))
template <class T> inline bool MX(T &l, const T &r) {
return l < r ? l = r, 1 : 0;
}
template <class T> inline bool MN(T &l, const T &r) {
return l > r ? l = r, 1 : 0;
}
int N;
int M;
set<int> es[114514];
bool used[114514];
int prv[114514];
int depth[114514];
void Erase(int u, int v) {
rep(i, 2) {
assert(es[u].count(v));
es[u].erase(v);
swap(u, v);
}
}
bool check() {
fill(used, used + N, false);
fill(prv, prv + N, -1);
queue<int> que;
int root = -1;
rep(v, N) {
if (!es[v].empty()) {
root = v;
used[v] = 1;
que.push(v);
break;
}
}
if (root == -1)
return false;
using Ans = pair<int, pii>;
Ans ans(MOD, pii(-1, -1));
while (!que.empty()) {
int v = que.front();
que.pop();
for (int u : es[v]) {
if (!used[u]) {
prv[u] = v;
used[u] = true;
depth[u] = depth[v] + 1;
que.push(u);
} else if (prv[v] != u) {
MN(ans, Ans(1 + depth[v] + depth[u], pii(v, u)));
}
}
}
if (ans.X == MOD)
return false;
int p, q;
tie(p, q) = ans.Y;
assert(p != -1);
Erase(p, q);
if (depth[p] < depth[q])
swap(p, q);
while (depth[p] > depth[q]) {
int np = prv[p];
Erase(p, np);
p = np;
}
while (p != q) {
int np = prv[p];
Erase(p, np);
p = np;
int nq = prv[q];
Erase(q, nq);
q = nq;
}
return true;
}
signed main() {
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(0);
cin >> N >> M;
rep(i, M) {
int a, b;
cin >> a >> b;
--a;
--b;
es[a].insert(b);
es[b].insert(a);
}
rep(v, N) {
if (es[v].size() % 2) {
puts("No");
return 0;
}
}
rep(i, 3) {
// cout << i << endl;
if (!check()) {
puts("No");
return 0;
}
}
puts("Yes");
}
| replace | 87 | 96 | 87 | 102 | 0 | |
p03091 | C++ | Runtime Error | #include <cstdio>
using namespace std;
#define N 100500
struct edge {
int t, next;
} ed[N];
int head[N], cnt = 1, in[N], n, m, ct, mx, fg, a, b, vis[N];
void adde(int f, int t) {
ed[++cnt] = (edge){t, head[f]};
head[f] = cnt;
ed[++cnt] = (edge){f, head[t]};
head[t] = cnt;
in[f]++;
in[t]++;
}
void dfs(int u, int id) {
vis[u] = 1;
if (u == b)
fg = 1, vis[u] = 0;
if (u == a && id)
return;
for (int i = head[u]; i; i = ed[i].next)
if (i != id && i != (id ^ 1) && !vis[ed[i].t])
dfs(ed[i].t, i);
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++)
scanf("%d%d", &a, &b), adde(a, b);
a = -1;
for (int i = 1; i <= n; i++)
if (in[i] & 1) {
printf("No\n");
return 0;
} else if (mx < in[i])
mx = in[i];
if (mx > 4) {
printf("Yes\n");
return 0;
}
for (int i = 1; i <= n; i++)
if (in[i] == 4) {
ct++;
if (a == -1)
a = i;
else
b = i;
}
if (ct > 2) {
printf("Yes\n");
return 0;
}
if (ct == 2)
for (int i = head[a]; i; i = ed[i].next)
if (!vis[ed[i].t]) {
fg = 0;
dfs(ed[i].t, 1);
if (!fg) {
printf("Yes\n");
return 0;
}
}
printf("No\n");
} | #include <cstdio>
using namespace std;
#define N 100500
struct edge {
int t, next;
} ed[N * 2];
int head[N], cnt = 1, in[N], n, m, ct, mx, fg, a, b, vis[N];
void adde(int f, int t) {
ed[++cnt] = (edge){t, head[f]};
head[f] = cnt;
ed[++cnt] = (edge){f, head[t]};
head[t] = cnt;
in[f]++;
in[t]++;
}
void dfs(int u, int id) {
vis[u] = 1;
if (u == b)
fg = 1, vis[u] = 0;
if (u == a && id)
return;
for (int i = head[u]; i; i = ed[i].next)
if (i != id && i != (id ^ 1) && !vis[ed[i].t])
dfs(ed[i].t, i);
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++)
scanf("%d%d", &a, &b), adde(a, b);
a = -1;
for (int i = 1; i <= n; i++)
if (in[i] & 1) {
printf("No\n");
return 0;
} else if (mx < in[i])
mx = in[i];
if (mx > 4) {
printf("Yes\n");
return 0;
}
for (int i = 1; i <= n; i++)
if (in[i] == 4) {
ct++;
if (a == -1)
a = i;
else
b = i;
}
if (ct > 2) {
printf("Yes\n");
return 0;
}
if (ct == 2)
for (int i = head[a]; i; i = ed[i].next)
if (!vis[ed[i].t]) {
fg = 0;
dfs(ed[i].t, 1);
if (!fg) {
printf("Yes\n");
return 0;
}
}
printf("No\n");
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03091 | C++ | Runtime Error | // IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>
// algorithm library
#include <algorithm>
#include <cmath>
#include <limits>
#include <numeric>
#include <random>
// contancer library
#include <bitset>
#include <deque>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using ll = long long;
using ld = long double;
/* ----- class ----- */
template <class Cost = int, class Cap = int> struct Edge {
int from, to, rev;
Cost cost;
Cap cap;
Edge(int from = -1, int to = -1, Cost cost = 1, Cap cap = 0, int rev = -1)
: from(from), to(to), cost(cost), cap(cap), rev(rev){};
bool operator<(const Edge<Cost> &e) const { return this->cost < e.cost; }
bool operator>(const Edge<Cost> &e) const { return this->cost > e.cost; }
};
template <class Cost = int, class Cap = int> class Graph {
public:
int size;
std::vector<std::vector<Edge<Cost, Cap>>> path;
explicit Graph(int N = 0) : size(N), path(size) {}
void span(int u, int v, Cost cost = 1, Cap cap = 0) {
path[u].push_back(Edge<Cost, Cap>(u, v, cost, cap));
}
std::vector<Edge<Cost, Cap>> operator[](int v) const { return path[v]; }
};
/* ----- Output Functions for Debugging ----- */
template <class T> std::ostream &operator<<(std::ostream &os, std::vector<T> v);
template <class T> std::ostream &operator<<(std::ostream &os, std::set<T> v);
template <class L, class R>
std::ostream &operator<<(std::ostream &os, std::pair<L, R> p);
template <class K, class T>
std::ostream &operator<<(std::ostream &os, std::map<K, T> v);
template <class T> std::ostream &operator<<(std::ostream &os, std::queue<T> q);
template <class T>
std::ostream &operator<<(std::ostream &os, std::priority_queue<T> q);
template <class T>
std::ostream &
operator<<(std::ostream &os,
std::priority_queue<T, std::vector<T>, std::greater<T>> q);
template <class T, class U>
std::ostream &operator<<(std::ostream &os, Edge<T, U> e);
template <class T>
std::ostream &operator<<(std::ostream &os, std::vector<T> v) {
os << "[";
for (auto vv : v)
os << vv << ",";
return os << "]";
}
template <class T> std::ostream &operator<<(std::ostream &os, std::set<T> v) {
os << "{";
for (auto vv : v)
os << vv << ",";
return os << "}";
}
template <class L, class R>
std::ostream &operator<<(std::ostream &os, std::pair<L, R> p) {
return os << "(" << p.first << "," << p.second << ")";
}
template <class K, class T>
std::ostream &operator<<(std::ostream &os, std::map<K, T> v) {
os << "{";
for (auto vv : v)
os << vv << ",";
return os << "}";
}
template <class T> std::ostream &operator<<(std::ostream &os, std::queue<T> q) {
os << "[";
while (!q.empty()) {
os << q.front() << ",";
q.pop();
}
return os << "]";
}
template <class T>
std::ostream &operator<<(std::ostream &os, std::priority_queue<T> q) {
os << "{";
while (!q.empty()) {
os << q.top() << ",";
q.pop();
}
return os << "}";
}
template <class T>
std::ostream &
operator<<(std::ostream &os,
std::priority_queue<T, std::vector<T>, std::greater<T>> q) {
os << "{";
while (!q.empty()) {
os << q.top() << ",";
q.pop();
}
return os << "}";
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, Edge<T, U> e) {
return os << "(" << e.from << "->" << e.to << ":" << e.cost << "," << e.cap
<< ")";
}
/* ----- Short Functions ----- */
template <class T> T Vec(T v) { return v; }
template <class T, class... Ts> auto Vec(size_t l, Ts... ts) {
return std::vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}
template <class T> inline T sq(T a) { return a * a; }
template <class T> inline T iceil(T n, T d) { return (n + d - 1) / d; }
template <class T> T gcd(T a, T b) {
while (b > 0) {
a %= b;
swap(a, b);
}
return a;
}
template <class T, class U> T ipow(T b, U n) {
T ret = 1;
while (n > 0) {
if (n & 1)
ret *= b;
n >>= 1;
b *= b;
}
return ret;
}
// 0-indexed
template <class T, class U> inline T kthbit(T a, U k) { return (a >> k) & 1; }
template <class T, class U> inline T mask(T a, U k) {
return a & ((1 << k) - 1);
}
/* ----- Constants ----- */
// const int INF = std::numeric_limits<int>::max();
// const ll INF = std::numeric_limits<ll>::max();
// const ld PI = acos(-1);
// const ld EPS = 1e-10;
// std::mt19937 mt(ll(time(0)));
void fail() {
std::cout << "No" << std::endl;
exit(0);
}
void ok() {
std::cout << "Yes" << std::endl;
exit(0);
}
template <class Cost = int, class Cap = int> class Lowlink {
private:
Graph<Cost, Cap> graph;
int cur;
std::vector<int> order, low;
void dfs(int v, int r) {
order[v] = low[v] = cur++;
int deg = 0;
bool is_artic = false;
for (auto e : graph[v]) {
if (order[e.to] < 0) {
++deg;
dfs(e.to, e.from);
low[e.from] = std::min(low[e.from], low[e.to]);
if (order[e.from] <= low[e.to])
is_artic = true;
if (order[e.from] < low[e.to])
bridges.push_back(e);
} else if (e.to != r) {
// eは後退辺 1回だけ遡る
low[e.from] = std::min(low[e.from], order[e.to]);
}
}
if (r < 0)
is_artic = (deg > 1);
if (is_artic)
artics.push_back(v);
}
public:
std::vector<int> artics;
std::vector<Edge<Cost, Cap>> bridges;
explicit Lowlink(const Graph<Cost, Cap> &graph)
: graph(graph), order(graph.size, -1), low(graph.size, graph.size) {
cur = 0;
for (int v = 0; v < graph.size; ++v) {
if (order[v] < 0)
dfs(v, -1);
}
}
};
int main() {
int N, M;
std::cin >> N >> M;
Graph<> graph(N);
for (int i = 0; i < M; ++i) {
int u, v;
std::cin >> u >> v;
--u, --v;
graph.span(u, v);
graph.span(v, u);
}
for (int v = 0; v < N; ++v) {
if (graph[v].size() % 2 != 0)
fail();
}
for (int v = 0; v < N; ++v) {
if (graph[v].size() >= 6)
ok();
}
std::terminate();
Lowlink<> lowlink(graph);
std::cout << (lowlink.artics.empty() ? "No" : "Yes") << std::endl;
return 0;
}
| // IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>
// algorithm library
#include <algorithm>
#include <cmath>
#include <limits>
#include <numeric>
#include <random>
// contancer library
#include <bitset>
#include <deque>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using ll = long long;
using ld = long double;
/* ----- class ----- */
template <class Cost = int, class Cap = int> struct Edge {
int from, to, rev;
Cost cost;
Cap cap;
Edge(int from = -1, int to = -1, Cost cost = 1, Cap cap = 0, int rev = -1)
: from(from), to(to), cost(cost), cap(cap), rev(rev){};
bool operator<(const Edge<Cost> &e) const { return this->cost < e.cost; }
bool operator>(const Edge<Cost> &e) const { return this->cost > e.cost; }
};
template <class Cost = int, class Cap = int> class Graph {
public:
int size;
std::vector<std::vector<Edge<Cost, Cap>>> path;
explicit Graph(int N = 0) : size(N), path(size) {}
void span(int u, int v, Cost cost = 1, Cap cap = 0) {
path[u].push_back(Edge<Cost, Cap>(u, v, cost, cap));
}
std::vector<Edge<Cost, Cap>> operator[](int v) const { return path[v]; }
};
/* ----- Output Functions for Debugging ----- */
template <class T> std::ostream &operator<<(std::ostream &os, std::vector<T> v);
template <class T> std::ostream &operator<<(std::ostream &os, std::set<T> v);
template <class L, class R>
std::ostream &operator<<(std::ostream &os, std::pair<L, R> p);
template <class K, class T>
std::ostream &operator<<(std::ostream &os, std::map<K, T> v);
template <class T> std::ostream &operator<<(std::ostream &os, std::queue<T> q);
template <class T>
std::ostream &operator<<(std::ostream &os, std::priority_queue<T> q);
template <class T>
std::ostream &
operator<<(std::ostream &os,
std::priority_queue<T, std::vector<T>, std::greater<T>> q);
template <class T, class U>
std::ostream &operator<<(std::ostream &os, Edge<T, U> e);
template <class T>
std::ostream &operator<<(std::ostream &os, std::vector<T> v) {
os << "[";
for (auto vv : v)
os << vv << ",";
return os << "]";
}
template <class T> std::ostream &operator<<(std::ostream &os, std::set<T> v) {
os << "{";
for (auto vv : v)
os << vv << ",";
return os << "}";
}
template <class L, class R>
std::ostream &operator<<(std::ostream &os, std::pair<L, R> p) {
return os << "(" << p.first << "," << p.second << ")";
}
template <class K, class T>
std::ostream &operator<<(std::ostream &os, std::map<K, T> v) {
os << "{";
for (auto vv : v)
os << vv << ",";
return os << "}";
}
template <class T> std::ostream &operator<<(std::ostream &os, std::queue<T> q) {
os << "[";
while (!q.empty()) {
os << q.front() << ",";
q.pop();
}
return os << "]";
}
template <class T>
std::ostream &operator<<(std::ostream &os, std::priority_queue<T> q) {
os << "{";
while (!q.empty()) {
os << q.top() << ",";
q.pop();
}
return os << "}";
}
template <class T>
std::ostream &
operator<<(std::ostream &os,
std::priority_queue<T, std::vector<T>, std::greater<T>> q) {
os << "{";
while (!q.empty()) {
os << q.top() << ",";
q.pop();
}
return os << "}";
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, Edge<T, U> e) {
return os << "(" << e.from << "->" << e.to << ":" << e.cost << "," << e.cap
<< ")";
}
/* ----- Short Functions ----- */
template <class T> T Vec(T v) { return v; }
template <class T, class... Ts> auto Vec(size_t l, Ts... ts) {
return std::vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}
template <class T> inline T sq(T a) { return a * a; }
template <class T> inline T iceil(T n, T d) { return (n + d - 1) / d; }
template <class T> T gcd(T a, T b) {
while (b > 0) {
a %= b;
swap(a, b);
}
return a;
}
template <class T, class U> T ipow(T b, U n) {
T ret = 1;
while (n > 0) {
if (n & 1)
ret *= b;
n >>= 1;
b *= b;
}
return ret;
}
// 0-indexed
template <class T, class U> inline T kthbit(T a, U k) { return (a >> k) & 1; }
template <class T, class U> inline T mask(T a, U k) {
return a & ((1 << k) - 1);
}
/* ----- Constants ----- */
// const int INF = std::numeric_limits<int>::max();
// const ll INF = std::numeric_limits<ll>::max();
// const ld PI = acos(-1);
// const ld EPS = 1e-10;
// std::mt19937 mt(ll(time(0)));
void fail() {
std::cout << "No" << std::endl;
exit(0);
}
void ok() {
std::cout << "Yes" << std::endl;
exit(0);
}
template <class Cost = int, class Cap = int> class Lowlink {
private:
Graph<Cost, Cap> graph;
int cur;
std::vector<int> order, low;
void dfs(int v, int r) {
order[v] = low[v] = cur++;
int deg = 0;
bool is_artic = false;
for (auto e : graph[v]) {
if (order[e.to] < 0) {
++deg;
dfs(e.to, e.from);
low[e.from] = std::min(low[e.from], low[e.to]);
if (order[e.from] <= low[e.to])
is_artic = true;
if (order[e.from] < low[e.to])
bridges.push_back(e);
} else if (e.to != r) {
// eは後退辺 1回だけ遡る
low[e.from] = std::min(low[e.from], order[e.to]);
}
}
if (r < 0)
is_artic = (deg > 1);
if (is_artic)
artics.push_back(v);
}
public:
std::vector<int> artics;
std::vector<Edge<Cost, Cap>> bridges;
explicit Lowlink(const Graph<Cost, Cap> &graph)
: graph(graph), order(graph.size, -1), low(graph.size, graph.size) {
cur = 0;
for (int v = 0; v < graph.size; ++v) {
if (order[v] < 0)
dfs(v, -1);
}
}
};
int main() {
int N, M;
std::cin >> N >> M;
Graph<> graph(N);
for (int i = 0; i < M; ++i) {
int u, v;
std::cin >> u >> v;
--u, --v;
graph.span(u, v);
graph.span(v, u);
}
for (int v = 0; v < N; ++v) {
if (graph[v].size() % 2 != 0)
fail();
}
for (int v = 0; v < N; ++v) {
if (graph[v].size() >= 6)
ok();
}
int cnt = 0;
for (int v = 0; v < N; ++v) {
if (graph[v].size() >= 4)
++cnt;
}
if (cnt <= 1)
fail();
if (cnt >= 3)
ok();
Lowlink<> lowlink(graph);
std::cout << (lowlink.artics.empty() ? "No" : "Yes") << std::endl;
return 0;
}
| replace | 254 | 255 | 254 | 264 | 0 | |
p03091 | C++ | Time Limit Exceeded | // #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
using int64 = long long int;
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
void drop(string s) {
printf("%s\n", s.c_str());
exit(0);
}
int main() {
int N, M;
cin >> N >> M;
vector<int> deg(N);
vector<vector<int>> G(N);
for (int i = 0; i < M; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
G[u].emplace_back(v);
G[v].emplace_back(u);
deg[u]++, deg[v]++;
}
// 奇数があるなら NG
int deg6 = 0, deg4 = 0, deg2 = 0;
for (int i = 0; i < N; i++) {
if (deg[i] % 2)
drop("No");
else if (deg[i] == 2)
deg2++;
else if (deg[i] == 4)
deg4++;
else
deg6++;
}
fprintf(stderr, "# %d %d %d\n", deg6, deg4, deg2);
// 次数 >= 6 なら 3 つ以上に分割可能
// 次数 == 4 が 1 個以下なら無理
// 次数 == 4 が 3 個以上なら OK
if (deg6 >= 1 or deg4 >= 3)
drop("Yes");
if (deg4 <= 1)
drop("No");
// 次数 == 4 が 2 個の場合のみ
{
int s = -1, t = -1;
for (int i = 0; i < N; i++) {
if (deg[i] == 4) {
if (s < 0)
s = i;
else
t = i;
}
}
int cnt = 0;
for (auto v : G[s]) {
int cur = v, pre = s;
while (cur != s and cur != t) {
for (auto to : G[cur]) {
if (to == pre)
continue;
pre = cur;
cur = to;
}
}
if (cur == t)
cnt++;
}
printf("%s\n", cnt == 4 ? "No" : "Yes");
}
return 0;
}
| // #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
using int64 = long long int;
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
void drop(string s) {
printf("%s\n", s.c_str());
exit(0);
}
int main() {
int N, M;
cin >> N >> M;
vector<int> deg(N);
vector<vector<int>> G(N);
for (int i = 0; i < M; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
G[u].emplace_back(v);
G[v].emplace_back(u);
deg[u]++, deg[v]++;
}
// 奇数があるなら NG
int deg6 = 0, deg4 = 0, deg2 = 0;
for (int i = 0; i < N; i++) {
if (deg[i] % 2)
drop("No");
else if (deg[i] == 2)
deg2++;
else if (deg[i] == 4)
deg4++;
else
deg6++;
}
fprintf(stderr, "# %d %d %d\n", deg6, deg4, deg2);
// 次数 >= 6 なら 3 つ以上に分割可能
// 次数 == 4 が 1 個以下なら無理
// 次数 == 4 が 3 個以上なら OK
if (deg6 >= 1 or deg4 >= 3)
drop("Yes");
if (deg4 <= 1)
drop("No");
// 次数 == 4 が 2 個の場合のみ
{
int s = -1, t = -1;
for (int i = 0; i < N; i++) {
if (deg[i] == 4) {
if (s < 0)
s = i;
else
t = i;
}
}
int cnt = 0;
for (auto v : G[s]) {
int cur = v, pre = s;
while (cur != s and cur != t) {
for (auto to : G[cur]) {
if (to == pre)
continue;
pre = cur;
cur = to;
break;
}
}
if (cur == t)
cnt++;
}
printf("%s\n", cnt == 4 ? "No" : "Yes");
}
return 0;
}
| insert | 103 | 103 | 103 | 104 | TLE | |
p03091 | C++ | Runtime Error | // Author:xht37
#include <bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double
#define pi pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)
#define vi vector<int>
#define pb push_back
#define pq priority_queue
#define dbg(x) cerr << #x " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fl(x) freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout)
using namespace std;
namespace io {
const int SI = 1 << 21 | 1;
char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
int f, t;
#define gc() \
(IS == IT \
? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) \
: *IS++)
inline void flush() { fwrite(OB, 1, OS - OB, stdout), OS = OB; }
inline void pc(char x) {
*OS++ = x;
if (OS == OT)
flush();
}
template <class I> inline void rd(I &x) {
for (f = 1, c = gc(); c < '0' || c > '9'; c = gc())
if (c == '-')
f = -1;
for (x = 0; c >= '0' && c <= '9';
x = (x << 3) + (x << 1) + (c & 15), c = gc())
;
x *= f;
}
template <class I> inline void rd(I &x, I &y) { rd(x), rd(y); }
template <class I> inline void rd(I &x, I &y, I &z) { rd(x), rd(y), rd(z); }
template <class I> inline void rda(I *a, int n) {
for (int i = 1; i <= n; i++)
rd(a[i]);
}
inline void rdc(char &c) {
for (c = gc(); c < 33 || c > 126; c = gc())
;
}
inline void rds(char *s, int &n) {
for (c = gc(); c < 33 || c > 126; c = gc())
;
for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc())
;
s[n + 1] = '\0';
}
inline void rds(string &s) {
for (c = gc(); c < 33 || c > 126; c = gc())
;
for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc())
;
}
template <class I> inline void print(I x, char k = '\n') {
if (!x)
pc('0');
if (x < 0)
pc('-'), x = -x;
while (x)
ch[++t] = x % 10 + '0', x /= 10;
while (t)
pc(ch[t--]);
pc(k);
}
template <class I> inline void print(I x, I y) { print(x, ' '), print(y); }
template <class I> inline void print(I x, I y, I z) {
print(x, ' '), print(y, ' '), print(z);
}
template <class I> inline void printa(I *a, int n) {
for (int i = 1; i <= n; i++)
print(a[i], " \n"[i == n]);
}
inline void printc(char c) { pc(c); }
inline void prints(char *s, int n) {
for (int i = 1; i <= n; i++)
pc(s[i]);
pc('\n');
}
inline void prints(string s) {
int n = s.length();
while (t < n)
pc(s[t++]);
pc('\n'), t = 0;
}
struct Flush {
~Flush() { flush(); }
} flusher;
} // namespace io
using io::print;
using io::printa;
using io::printc;
using io::prints;
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
const int N = 1e5 + 7;
int n, m, d[N], X, Y;
vi e[N];
void dfs(int x, int f) {
if (x == X)
prints("Yes"), exit(0);
for (int y : e[x])
if (y != f)
dfs(y, x);
}
int main() {
rd(n, m);
for (int i = 1, x, y; i <= m; i++)
rd(x, y), ++d[x], ++d[y], e[x].pb(y), e[y].pb(x);
for (int i = 1; i <= n; i++)
if (d[i] & 1)
return prints("No"), 0;
int mx = *max_element(d + 1, d + n + 1);
if (mx == 2)
return prints("No"), 0;
if (mx >= 6)
return prints("Yes"), 0;
int cnt = 0;
for (int i = 1; i <= n; i++)
cnt += d[i] == 4;
if (cnt == 1)
return prints("No"), 0;
if (cnt >= 3)
return prints("Yes"), 0;
for (int i = 1; i <= n; i++)
if (d[i] == 4) {
if (X)
Y = i;
else
X = i;
}
for (int z : e[X])
dfs(z, X);
prints("No");
return 0;
} | // Author:xht37
#include <bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double
#define pi pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)
#define vi vector<int>
#define pb push_back
#define pq priority_queue
#define dbg(x) cerr << #x " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fl(x) freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout)
using namespace std;
namespace io {
const int SI = 1 << 21 | 1;
char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
int f, t;
#define gc() \
(IS == IT \
? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) \
: *IS++)
inline void flush() { fwrite(OB, 1, OS - OB, stdout), OS = OB; }
inline void pc(char x) {
*OS++ = x;
if (OS == OT)
flush();
}
template <class I> inline void rd(I &x) {
for (f = 1, c = gc(); c < '0' || c > '9'; c = gc())
if (c == '-')
f = -1;
for (x = 0; c >= '0' && c <= '9';
x = (x << 3) + (x << 1) + (c & 15), c = gc())
;
x *= f;
}
template <class I> inline void rd(I &x, I &y) { rd(x), rd(y); }
template <class I> inline void rd(I &x, I &y, I &z) { rd(x), rd(y), rd(z); }
template <class I> inline void rda(I *a, int n) {
for (int i = 1; i <= n; i++)
rd(a[i]);
}
inline void rdc(char &c) {
for (c = gc(); c < 33 || c > 126; c = gc())
;
}
inline void rds(char *s, int &n) {
for (c = gc(); c < 33 || c > 126; c = gc())
;
for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc())
;
s[n + 1] = '\0';
}
inline void rds(string &s) {
for (c = gc(); c < 33 || c > 126; c = gc())
;
for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc())
;
}
template <class I> inline void print(I x, char k = '\n') {
if (!x)
pc('0');
if (x < 0)
pc('-'), x = -x;
while (x)
ch[++t] = x % 10 + '0', x /= 10;
while (t)
pc(ch[t--]);
pc(k);
}
template <class I> inline void print(I x, I y) { print(x, ' '), print(y); }
template <class I> inline void print(I x, I y, I z) {
print(x, ' '), print(y, ' '), print(z);
}
template <class I> inline void printa(I *a, int n) {
for (int i = 1; i <= n; i++)
print(a[i], " \n"[i == n]);
}
inline void printc(char c) { pc(c); }
inline void prints(char *s, int n) {
for (int i = 1; i <= n; i++)
pc(s[i]);
pc('\n');
}
inline void prints(string s) {
int n = s.length();
while (t < n)
pc(s[t++]);
pc('\n'), t = 0;
}
struct Flush {
~Flush() { flush(); }
} flusher;
} // namespace io
using io::print;
using io::printa;
using io::printc;
using io::prints;
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
const int N = 1e5 + 7;
int n, m, d[N], X, Y;
vi e[N];
void dfs(int x, int f) {
if (x == Y)
return;
if (x == X)
prints("Yes"), exit(0);
for (int y : e[x])
if (y != f)
dfs(y, x);
}
int main() {
rd(n, m);
for (int i = 1, x, y; i <= m; i++)
rd(x, y), ++d[x], ++d[y], e[x].pb(y), e[y].pb(x);
for (int i = 1; i <= n; i++)
if (d[i] & 1)
return prints("No"), 0;
int mx = *max_element(d + 1, d + n + 1);
if (mx == 2)
return prints("No"), 0;
if (mx >= 6)
return prints("Yes"), 0;
int cnt = 0;
for (int i = 1; i <= n; i++)
cnt += d[i] == 4;
if (cnt == 1)
return prints("No"), 0;
if (cnt >= 3)
return prints("Yes"), 0;
for (int i = 1; i <= n; i++)
if (d[i] == 4) {
if (X)
Y = i;
else
X = i;
}
for (int z : e[X])
dfs(z, X);
prints("No");
return 0;
} | insert | 125 | 125 | 125 | 127 | 0 | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n, m, i, d[1000005], u, v, ans, head[1000005], Next[2000005], adj[2000005],
k, s;
bool flag = true;
void Push(int u, int v) {
Next[++k] = head[u];
head[u] = k;
adj[k] = v;
}
void dfs(int i, int fa) {
if ((i == u && fa != 0) || i == v) {
if (i == v)
++s;
return;
}
int j;
for (j = head[i]; j != 0; j = Next[j])
if (adj[j] != fa)
dfs(adj[j], i);
}
int main() {
scanf("%d %d", &n, &m);
for (i = 1; i <= m; ++i) {
scanf("%d %d", &u, &v);
++d[u];
++d[v];
Push(u, v);
Push(v, u);
}
for (i = 1; i <= n; ++i) {
ans += d[i] / 2 - 1;
if (d[i] & 1)
flag = false;
}
for (i = 1; i <= n; ++i)
if (d[i] == 4)
if (u == 0)
u = i;
else
v = i;
if (ans == 2 && v != 0 && flag) {
dfs(u, 0);
if (s > 2)
flag = false;
}
puts(ans >= 2 && flag ? "Yes" : "No");
}
| #include <bits/stdc++.h>
using namespace std;
int n, m, i, d[1000005], u, v, ans, head[1000005], Next[2000005], adj[2000005],
k, s;
bool flag = true;
void Push(int u, int v) {
Next[++k] = head[u];
head[u] = k;
adj[k] = v;
}
void dfs(int i, int fa) {
if ((i == u && fa != 0) || i == v) {
if (i == v)
++s;
return;
}
int j;
for (j = head[i]; j != 0; j = Next[j])
if (adj[j] != fa)
dfs(adj[j], i);
}
int main() {
scanf("%d %d", &n, &m);
for (i = 1; i <= m; ++i) {
scanf("%d %d", &u, &v);
++d[u];
++d[v];
Push(u, v);
Push(v, u);
}
for (i = 1; i <= n; ++i) {
ans += d[i] / 2 - 1;
if (d[i] & 1)
flag = false;
}
u = v = 0;
for (i = 1; i <= n; ++i)
if (d[i] == 4)
if (u == 0)
u = i;
else
v = i;
if (ans == 2 && v != 0 && flag) {
dfs(u, 0);
if (s > 2)
flag = false;
}
puts(ans >= 2 && flag ? "Yes" : "No");
}
| insert | 35 | 35 | 35 | 36 | -11 | |
p03091 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// freopen("input.txt", "r", stdin);
int n, m;
cin >> n >> m;
vector<vector<int>> edge(n);
REP(i, m) {
int a, b;
cin >> a >> b;
--a;
--b;
edge[a].emplace_back(b);
edge[b].emplace_back(a);
}
vector<int> four;
bool six = false;
REP(i, n) {
if (edge[i].size() & 1) {
cout << "No\n";
return 0;
}
if (edge[i].size() == 4)
four.emplace_back(i);
else if (edge[i].size() >= 6)
six = true;
}
if (four.size() >= 3 || six) {
cout << "Yes\n";
return 0;
}
function<void(int, int)> dfs = [&](int par, int ver) {
for (int e : edge[ver])
if (e != par) {
if (e == four.front()) {
cout << "Yes\n";
exit(0);
}
if (e != four.back())
dfs(ver, e);
}
};
dfs(-1, four.front());
cout << "No\n";
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// freopen("input.txt", "r", stdin);
int n, m;
cin >> n >> m;
vector<vector<int>> edge(n);
REP(i, m) {
int a, b;
cin >> a >> b;
--a;
--b;
edge[a].emplace_back(b);
edge[b].emplace_back(a);
}
vector<int> four;
bool six = false;
REP(i, n) {
if (edge[i].size() & 1) {
cout << "No\n";
return 0;
}
if (edge[i].size() == 4)
four.emplace_back(i);
else if (edge[i].size() >= 6)
six = true;
}
if (four.size() >= 3 || six) {
cout << "Yes\n";
return 0;
}
if (four.size() <= 1) {
cout << "No\n";
return 0;
}
function<void(int, int)> dfs = [&](int par, int ver) {
for (int e : edge[ver])
if (e != par) {
if (e == four.front()) {
cout << "Yes\n";
exit(0);
}
if (e != four.back())
dfs(ver, e);
}
};
dfs(-1, four.front());
cout << "No\n";
return 0;
}
| insert | 63 | 63 | 63 | 67 | 0 | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < (n); ++i)
#define foor(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, n) for (int i = (n); i--;)
#define roof(i, b, a) for (int i = (b); i >= (a); --i)
#define elsif else if
#define all(x) x.begin(), x.end()
#define Sort(x) sort(all(x))
#define Reverse(x) reverse(all(x))
#define PQ priority_queue
#define NP(x) next_permutation(all(x))
#define M_PI 3.14159265358979323846
#define popcount __builtin_popcount
using namespace std;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef unsigned long long ull;
typedef vector<ull> vu;
typedef vector<vu> vvu;
typedef double dbl;
typedef vector<dbl> vd;
typedef vector<vd> vvd;
typedef string str;
typedef vector<str> vs;
typedef vector<vs> vvs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<int, int> mii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> mll;
typedef pair<dbl, dbl> pdd;
typedef vector<pdd> vpdd;
typedef map<dbl, dbl> mdd;
typedef pair<str, str> pss;
typedef vector<pss> vpss;
typedef map<str, str> mss;
typedef pair<int, ll> pil;
typedef vector<pil> vpil;
typedef map<int, ll> mil;
typedef pair<ll, int> pli;
typedef vector<pli> vpli;
typedef map<ll, int> mli;
typedef pair<dbl, int> pdi;
typedef vector<pdi> vpdi;
typedef map<dbl, int> mdi;
template <typename T> vector<T> &operator<<(vector<T> &v, const T t) {
v.push_back(t);
return v;
}
template <typename T> multiset<T> &operator<<(multiset<T> &m, const T t) {
m.insert(t);
return m;
}
template <typename T> set<T> &operator<<(set<T> &s, const T t) {
s.insert(t);
return s;
}
template <typename T> stack<T> &operator<<(stack<T> &s, const T t) {
s.push(t);
return s;
}
template <typename T> stack<T> &operator>>(stack<T> &s, T &t) {
t = s.top();
s.pop();
return s;
}
template <typename T> queue<T> &operator<<(queue<T> &q, const T t) {
q.push(t);
return q;
}
template <typename T> queue<T> &operator>>(queue<T> &q, T &t) {
t = q.front();
q.pop();
return q;
}
template <typename T, typename U>
PQ<T, vector<T>, U> &operator<<(PQ<T, vector<T>, U> &q, const T t) {
q.push(t);
return q;
}
template <typename T, typename U>
PQ<T, vector<T>, U> &operator>>(PQ<T, vector<T>, U> &q, T &t) {
t = q.top();
q.pop();
return q;
}
template <typename T, typename U>
istream &operator>>(istream &s, pair<T, U> &p) {
return s >> p.first >> p.second;
}
template <typename T> istream &operator>>(istream &s, vector<T> &v) {
fr(i, v.size()) { s >> v[i]; }
return s;
}
template <typename T, typename U>
ostream &operator<<(ostream &s, const pair<T, U> p) {
return s << p.first << " " << p.second;
}
// template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto
// a:v){s<<a<<endl;}return s;}
template <typename T> ostream &operator<<(ostream &s, const vector<T> v) {
fr(i, v.size()) { i ? s << " " << v[i] : s << v[i]; }
return s;
}
template <typename T> ostream &operator<<(ostream &s, const deque<T> d) {
fr(i, d.size()) { i ? s << " " << d[i] : s << d[i]; }
return s;
}
template <typename T> _Bit_reference operator&=(_Bit_reference b, T t) {
return b = b & t;
}
template <typename T> _Bit_reference operator^=(_Bit_reference b, T t) {
return b = b ^ t;
}
template <typename T> _Bit_reference operator|=(_Bit_reference b, T t) {
return b = b | t;
}
template <typename T, typename U>
pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
return {a.first + b.first, a.second + b.second};
}
template <typename T, typename U>
pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
return {a.first - b.first, a.second - b.second};
}
void print(void) { cout << endl; }
template <typename T> void print(T t) { cout << t << endl; }
template <typename T, typename... U> void print(T &&t, U &&...u) {
cout << t << " ";
print(forward<U>(u)...);
}
bool YN(bool b) {
print(b ? "YES" : "NO");
return b;
}
bool PI(bool b) {
print(b ? "POSSIBLE" : "IMPOSSIBLE");
return b;
}
bool Yn(bool b) {
print(b ? "Yes" : "No");
return b;
}
bool Pi(bool b) {
print(b ? "Possible" : "Impossible");
return b;
}
bool yn(bool b) {
print(b ? "yes" : "no");
return b;
}
bool pi(bool b) {
print(b ? "possible" : "impossible");
return b;
}
const int e5 = 1e5;
const int e9 = 1e9;
const int MD = 1e9 + 7;
const ll e18 = 1e18;
template <typename T> str to_string(const T &n) {
ostringstream s;
s << n;
return s.str();
}
template <typename T> T &chmax(T &a, T b) { return a = max(a, b); }
template <typename T> T &chmin(T &a, T b) { return a = min(a, b); }
template <typename T, typename U>
vector<pair<T, U>> dijkstra(const vector<vector<pair<T, U>>> &E, const U s,
const T inf) {
using P = pair<T, U>;
vector<P> d;
fr(i, E.size()) { d << P{inf, i}; }
PQ<P, vector<P>, greater<P>> pq;
pq << (d[s] = P{0, s});
while (pq.size()) {
P a = pq.top();
pq.pop();
U v = a.second;
if (d[v].first >= a.first) {
for (P e : E[v]) {
if (d[v].first + e.first < d[e.second].first) {
d[e.second] = P{d[v].first + e.first, v};
pq << P{d[v].first + e.first, e.second};
}
}
}
}
return d;
}
template <typename T, typename U>
map<U, pair<T, U>> dijkstra(map<U, vector<pair<T, U>>> E, const U s,
const T inf) {
using P = pair<T, U>;
map<U, P> d;
for (pair<U, vector<P>> e : E) {
d[e.first] = P{inf, e.first};
}
PQ<P, vector<P>, greater<P>> pq;
pq << (d[s] = P{0, s});
while (pq.size()) {
P a = pq.top();
pq.pop();
U v = a.second;
if (d[v].first >= a.first) {
for (P e : E[v]) {
if (d[v].first + e.first < d[e.second].first) {
d[e.second] = P{d[v].first + e.first, v};
pq << P{d[v].first + e.first, e.second};
}
}
}
}
return d;
}
ll maxflow(vector<mil> &E, int s, int t) {
ll z = 0;
vi b(E.size(), -1);
for (int i = 0;; ++i) {
static auto dfs = [&](int v, ll f, auto &dfs) -> ll {
if (v == t)
return f;
b[v] = i;
for (auto &p : E[v]) {
if (b[p.first] < i && p.second) {
if (ll r = dfs(p.first, min(f, p.second), dfs)) {
p.second -= r;
E[p.first][v] += r;
return r;
}
}
}
return 0;
};
ll x = dfs(s, ll(1e18), dfs);
z += x;
if (x == 0)
return z;
}
}
template <typename T> T distsq(pair<T, T> a, pair<T, T> b) {
return (a.first - b.first) * (a.first - b.first) +
(a.second - b.second) * (a.second - b.second);
}
template <typename T> T max(const vector<T> a) {
T m = a[0];
for (T e : a) {
m = max(m, e);
}
return m;
}
template <typename T> T min(const vector<T> a) {
T m = a[0];
for (T e : a) {
m = min(m, e);
}
return m;
}
template <typename T> T gcd(const T a, const T b) {
return a ? gcd(b % a, a) : b;
}
template <typename T> T gcd(const vector<T> a) {
T g = a[0];
for (T e : a) {
g = gcd(g, e);
}
return g;
}
template <typename T> vector<T> LIS(const vector<T> A) {
vector<T> B;
for (T a : A) {
auto it = lower_bound(all(B), a);
if (it == B.end()) {
B << a;
} else {
*it = a;
}
}
return B;
}
template <typename T> vector<T> LCS(vector<T> A, vector<T> B) {
int N = A.size(), M = B.size();
vector<vector<pair<int, pii>>> d(N + 1, vector<pair<int, pii>>(M + 1));
fr(i, N) {
fr(j, M) {
if (A[i] == B[j]) {
d[i + 1][j + 1] = {d[i][j].first + 1, {i, j}};
} else {
d[i + 1][j + 1] = max(d[i][j + 1], d[i + 1][j]);
}
}
}
vector<T> r;
for (pii p = {N, M}; d[p.first][p.second].first;
p = d[p.first][p.second].second) {
r << A[d[p.first][p.second].second.first];
}
Reverse(r);
return r;
}
str LCS(str S, str T) {
vector<char> s =
LCS(vector<char>(S.begin(), S.end()), vector<char>(T.begin(), T.end()));
return str(s.begin(), s.end());
}
template <typename T> vector<pair<T, T>> ConvexHull(vector<pair<T, T>> V) {
if (V.size() <= 3) {
return V;
}
Sort(V);
rf(i, V.size() - 1) V << V[i];
vector<pair<T, T>> r;
for (pair<T, T> p : V) {
int s = r.size();
while (s >= 2 &&
(p.second - r[s - 1].second) * (p.first - r[s - 2].first) <
(p.second - r[s - 2].second) * (p.first - r[s - 1].first)) {
r.pop_back();
--s;
}
r << p;
}
r.pop_back();
return r;
}
class UnionFind {
vi p, s;
void extend(int N) {
foor(i, p.size(), N) {
p << i;
s << 1;
}
}
public:
UnionFind(void) {}
UnionFind(int N) { extend(N - 1); }
int find(int i) {
extend(i);
return p[i] = p[i] == i ? i : find(p[i]);
}
void unite(int a, int b) {
extend(a);
extend(b);
if ((a = find(a)) != (b = find(b))) {
if (s[a] > s[b]) {
swap(a, b);
}
s[b] += s[a];
p[a] = b;
}
}
void unite(pii p) { return unite(p.first, p.second); }
bool same(int a, int b) {
extend(a);
extend(b);
return find(a) == find(b);
}
bool same(pii p) { return same(p.first, p.second); }
int size(int x) {
extend(x);
return s[find(x)];
}
};
ll MST(vector<pair<ll, pii>> &E) {
Sort(E);
UnionFind uf;
ll z = 0;
for (auto &e : E) {
if (!uf.same(e.second)) {
z += e.first;
uf.unite(e.second);
}
}
return z;
}
ll strmod(const str &s, const int m) {
ll x = 0;
fr(i, s.size()) { x = (x * 10 + s[i] - 48) % m; }
return x;
}
vvl mul(const vvl &A, const vvl &B, const int m) {
vvl C;
fr(y, A.size()) { C << vl(B[y].size()); }
fr(y, C.size()) {
fr(x, C[y].size()) {
fr(i, A[0].size()) { (C[y][x] += A[y][i] * B[i][x]) %= m; }
}
}
return C;
}
vvl pow(const vvl &A, const ll n, const int m) {
vvl B;
fr(y, A.size()) { B << vl(A.size()); }
if (n == 0) {
fr(i, B.size()) { B[i][i] = 1; }
}
elsif(n % 2) { B = mul(A, pow(A, n - 1, m), m); }
else {
vvl C = pow(A, n / 2, m);
B = mul(C, C, m);
}
return B;
}
ll pow(const ll a, const ll n, const int m) {
ll t;
return n ? (n & 1 ? a >= 0 ? a % m : (m - (-a % m)) % m : 1) *
(t = pow(a, n >> 1, m), t * t % m) % m
: !!a;
}
ll inv(const ll x, const int p) { return pow(x, p - 2, p); }
ll inv(const ll x) { return inv(x, MD); }
vpll fact(const int n, const int p) {
vpll v(n + 1);
v[0].first = 1;
foor(i, 1, n) { v[i].first = v[i - 1].first * i % p; }
v[n].second = inv(v[n].first, p);
roof(i, n, 1) { v[i - 1].second = v[i].second * i % p; }
return v;
}
class Combination {
const vpll f;
const int M;
public:
Combination(int n, int m) : f(fact(n, m)), M(m) {}
Combination(int n) : Combination(n, MD) {}
ll P(int n, int k) {
return n < 0 || k < 0 || n < k ? 0ll : f[n].first * f[n - k].second % M;
}
ll C(int n, int k) { return P(n, k) * f[k].second % M; }
ll H(int n, int k) { return n == 0 && k == 0 ? 1ll : C(n + k - 1, k); }
};
ll C2(const int n) { return (ll)n * ~-n / 2; }
ll sum(const vi a) {
ll s = 0;
for (int e : a) {
s += e;
}
return s;
}
ll sum(const vl a) {
ll s = 0;
for (ll e : a) {
s += e;
}
return s;
}
template <typename T> int MSB(T N) {
int r = -1;
for (; N > 0; N /= 2) {
++r;
}
return r;
}
template <typename T> class SegmentTree {
vector<T> S;
T (*const op)(T a, T b);
const T zero;
const int B;
public:
SegmentTree(int N, T (*f)(T a, T b), const T zero)
: S(1 << MSB(N - 1) + 2, zero), op(f), zero(zero),
B(1 << MSB(N - 1) + 1) {}
SegmentTree(vector<T> v, T (*f)(T a, T b), const T zero)
: SegmentTree(v.size(), f, zero) {
fr(i, v.size()) { S[S.size() / 2 + i] = v[i]; }
roof(i, S.size() / 2 - 1, 1) { S[i] = op(S[i * 2], S[i * 2 + 1]); }
}
T calc(int l, int r) {
l += B;
r += B;
if (l > r) {
return zero;
}
if (l == r) {
return S[l];
}
T L = S[l], R = S[r];
for (; l / 2 < r / 2; l /= 2, r /= 2) {
if (l % 2 == 0) {
L = op(L, S[l + 1]);
}
if (r % 2 == 1) {
R = op(S[r - 1], R);
}
}
return op(L, R);
}
void replace(int i, T x) {
for (S[i += B] = x; i != 1; i /= 2) {
if (i % 2) {
S[i / 2] = op(S[i - 1], S[i]);
} else {
S[i / 2] = op(S[i], S[i + 1]);
}
}
}
void add(int i, T x) { replace(i, op(S[B + i], x)); }
T top() { return S[1]; }
};
ll BITsum(vl &B, int i) {
ll z = 0;
while (i > 0) {
z += B[i];
i -= i & -i;
}
return z;
}
void BITadd(vl &B, int i, ll x) {
while (i < B.size()) {
B[i] += x;
i += i & -i;
}
}
ll fib(const ll n, const int m) {
ll a, b, c, d, A, B, C, D;
a = 1;
b = 0;
c = 0;
d = 1;
rf(i, 63) {
A = a * a + b * c;
B = a * b + b * d;
C = c * a + d * c;
D = c * b + d * d;
if (n >> i & 1) {
a = A;
b = B;
c = C;
d = D;
A = a + b;
B = a;
C = c + d;
D = c;
}
a = A % m;
b = B % m;
c = C % m;
d = D % m;
}
return b;
}
vi primes(int n) {
vb b(n + 1);
vi p;
foor(i, 2, n) {
if (!b[i]) {
p << i;
for (int j = 2 * i; j <= n; j += i) {
b[j] = true;
}
}
}
return p;
}
vb isprime(const int n) {
vb v(n + 1, true);
v[0] = v[1] = false;
foor(i, 2, n) {
if (v[i]) {
for (int j = 2 * i; j <= n; j += i) {
v[j] = false;
}
}
}
return v;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vvi E(N);
fr(i, M) {
int a, b;
cin >> a >> b;
E[--a] << --b;
E[b] << a;
}
bool s6 = false;
vi v4;
fr(i, N) {
if (E[i].size() % 2) {
Yn(false);
return 0;
}
if (E[i].size() == 6)
s6 = true;
if (E[i].size() == 4)
v4 << i;
}
if (s6 || v4.size() >= 3) {
Yn(true);
return 0;
}
if (v4.size() < 2) {
Yn(false);
return 0;
}
return -1;
}
| #include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < (n); ++i)
#define foor(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, n) for (int i = (n); i--;)
#define roof(i, b, a) for (int i = (b); i >= (a); --i)
#define elsif else if
#define all(x) x.begin(), x.end()
#define Sort(x) sort(all(x))
#define Reverse(x) reverse(all(x))
#define PQ priority_queue
#define NP(x) next_permutation(all(x))
#define M_PI 3.14159265358979323846
#define popcount __builtin_popcount
using namespace std;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef unsigned long long ull;
typedef vector<ull> vu;
typedef vector<vu> vvu;
typedef double dbl;
typedef vector<dbl> vd;
typedef vector<vd> vvd;
typedef string str;
typedef vector<str> vs;
typedef vector<vs> vvs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<int, int> mii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> mll;
typedef pair<dbl, dbl> pdd;
typedef vector<pdd> vpdd;
typedef map<dbl, dbl> mdd;
typedef pair<str, str> pss;
typedef vector<pss> vpss;
typedef map<str, str> mss;
typedef pair<int, ll> pil;
typedef vector<pil> vpil;
typedef map<int, ll> mil;
typedef pair<ll, int> pli;
typedef vector<pli> vpli;
typedef map<ll, int> mli;
typedef pair<dbl, int> pdi;
typedef vector<pdi> vpdi;
typedef map<dbl, int> mdi;
template <typename T> vector<T> &operator<<(vector<T> &v, const T t) {
v.push_back(t);
return v;
}
template <typename T> multiset<T> &operator<<(multiset<T> &m, const T t) {
m.insert(t);
return m;
}
template <typename T> set<T> &operator<<(set<T> &s, const T t) {
s.insert(t);
return s;
}
template <typename T> stack<T> &operator<<(stack<T> &s, const T t) {
s.push(t);
return s;
}
template <typename T> stack<T> &operator>>(stack<T> &s, T &t) {
t = s.top();
s.pop();
return s;
}
template <typename T> queue<T> &operator<<(queue<T> &q, const T t) {
q.push(t);
return q;
}
template <typename T> queue<T> &operator>>(queue<T> &q, T &t) {
t = q.front();
q.pop();
return q;
}
template <typename T, typename U>
PQ<T, vector<T>, U> &operator<<(PQ<T, vector<T>, U> &q, const T t) {
q.push(t);
return q;
}
template <typename T, typename U>
PQ<T, vector<T>, U> &operator>>(PQ<T, vector<T>, U> &q, T &t) {
t = q.top();
q.pop();
return q;
}
template <typename T, typename U>
istream &operator>>(istream &s, pair<T, U> &p) {
return s >> p.first >> p.second;
}
template <typename T> istream &operator>>(istream &s, vector<T> &v) {
fr(i, v.size()) { s >> v[i]; }
return s;
}
template <typename T, typename U>
ostream &operator<<(ostream &s, const pair<T, U> p) {
return s << p.first << " " << p.second;
}
// template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto
// a:v){s<<a<<endl;}return s;}
template <typename T> ostream &operator<<(ostream &s, const vector<T> v) {
fr(i, v.size()) { i ? s << " " << v[i] : s << v[i]; }
return s;
}
template <typename T> ostream &operator<<(ostream &s, const deque<T> d) {
fr(i, d.size()) { i ? s << " " << d[i] : s << d[i]; }
return s;
}
template <typename T> _Bit_reference operator&=(_Bit_reference b, T t) {
return b = b & t;
}
template <typename T> _Bit_reference operator^=(_Bit_reference b, T t) {
return b = b ^ t;
}
template <typename T> _Bit_reference operator|=(_Bit_reference b, T t) {
return b = b | t;
}
template <typename T, typename U>
pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
return {a.first + b.first, a.second + b.second};
}
template <typename T, typename U>
pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
return {a.first - b.first, a.second - b.second};
}
void print(void) { cout << endl; }
template <typename T> void print(T t) { cout << t << endl; }
template <typename T, typename... U> void print(T &&t, U &&...u) {
cout << t << " ";
print(forward<U>(u)...);
}
bool YN(bool b) {
print(b ? "YES" : "NO");
return b;
}
bool PI(bool b) {
print(b ? "POSSIBLE" : "IMPOSSIBLE");
return b;
}
bool Yn(bool b) {
print(b ? "Yes" : "No");
return b;
}
bool Pi(bool b) {
print(b ? "Possible" : "Impossible");
return b;
}
bool yn(bool b) {
print(b ? "yes" : "no");
return b;
}
bool pi(bool b) {
print(b ? "possible" : "impossible");
return b;
}
const int e5 = 1e5;
const int e9 = 1e9;
const int MD = 1e9 + 7;
const ll e18 = 1e18;
template <typename T> str to_string(const T &n) {
ostringstream s;
s << n;
return s.str();
}
template <typename T> T &chmax(T &a, T b) { return a = max(a, b); }
template <typename T> T &chmin(T &a, T b) { return a = min(a, b); }
template <typename T, typename U>
vector<pair<T, U>> dijkstra(const vector<vector<pair<T, U>>> &E, const U s,
const T inf) {
using P = pair<T, U>;
vector<P> d;
fr(i, E.size()) { d << P{inf, i}; }
PQ<P, vector<P>, greater<P>> pq;
pq << (d[s] = P{0, s});
while (pq.size()) {
P a = pq.top();
pq.pop();
U v = a.second;
if (d[v].first >= a.first) {
for (P e : E[v]) {
if (d[v].first + e.first < d[e.second].first) {
d[e.second] = P{d[v].first + e.first, v};
pq << P{d[v].first + e.first, e.second};
}
}
}
}
return d;
}
template <typename T, typename U>
map<U, pair<T, U>> dijkstra(map<U, vector<pair<T, U>>> E, const U s,
const T inf) {
using P = pair<T, U>;
map<U, P> d;
for (pair<U, vector<P>> e : E) {
d[e.first] = P{inf, e.first};
}
PQ<P, vector<P>, greater<P>> pq;
pq << (d[s] = P{0, s});
while (pq.size()) {
P a = pq.top();
pq.pop();
U v = a.second;
if (d[v].first >= a.first) {
for (P e : E[v]) {
if (d[v].first + e.first < d[e.second].first) {
d[e.second] = P{d[v].first + e.first, v};
pq << P{d[v].first + e.first, e.second};
}
}
}
}
return d;
}
ll maxflow(vector<mil> &E, int s, int t) {
ll z = 0;
vi b(E.size(), -1);
for (int i = 0;; ++i) {
static auto dfs = [&](int v, ll f, auto &dfs) -> ll {
if (v == t)
return f;
b[v] = i;
for (auto &p : E[v]) {
if (b[p.first] < i && p.second) {
if (ll r = dfs(p.first, min(f, p.second), dfs)) {
p.second -= r;
E[p.first][v] += r;
return r;
}
}
}
return 0;
};
ll x = dfs(s, ll(1e18), dfs);
z += x;
if (x == 0)
return z;
}
}
template <typename T> T distsq(pair<T, T> a, pair<T, T> b) {
return (a.first - b.first) * (a.first - b.first) +
(a.second - b.second) * (a.second - b.second);
}
template <typename T> T max(const vector<T> a) {
T m = a[0];
for (T e : a) {
m = max(m, e);
}
return m;
}
template <typename T> T min(const vector<T> a) {
T m = a[0];
for (T e : a) {
m = min(m, e);
}
return m;
}
template <typename T> T gcd(const T a, const T b) {
return a ? gcd(b % a, a) : b;
}
template <typename T> T gcd(const vector<T> a) {
T g = a[0];
for (T e : a) {
g = gcd(g, e);
}
return g;
}
template <typename T> vector<T> LIS(const vector<T> A) {
vector<T> B;
for (T a : A) {
auto it = lower_bound(all(B), a);
if (it == B.end()) {
B << a;
} else {
*it = a;
}
}
return B;
}
template <typename T> vector<T> LCS(vector<T> A, vector<T> B) {
int N = A.size(), M = B.size();
vector<vector<pair<int, pii>>> d(N + 1, vector<pair<int, pii>>(M + 1));
fr(i, N) {
fr(j, M) {
if (A[i] == B[j]) {
d[i + 1][j + 1] = {d[i][j].first + 1, {i, j}};
} else {
d[i + 1][j + 1] = max(d[i][j + 1], d[i + 1][j]);
}
}
}
vector<T> r;
for (pii p = {N, M}; d[p.first][p.second].first;
p = d[p.first][p.second].second) {
r << A[d[p.first][p.second].second.first];
}
Reverse(r);
return r;
}
str LCS(str S, str T) {
vector<char> s =
LCS(vector<char>(S.begin(), S.end()), vector<char>(T.begin(), T.end()));
return str(s.begin(), s.end());
}
template <typename T> vector<pair<T, T>> ConvexHull(vector<pair<T, T>> V) {
if (V.size() <= 3) {
return V;
}
Sort(V);
rf(i, V.size() - 1) V << V[i];
vector<pair<T, T>> r;
for (pair<T, T> p : V) {
int s = r.size();
while (s >= 2 &&
(p.second - r[s - 1].second) * (p.first - r[s - 2].first) <
(p.second - r[s - 2].second) * (p.first - r[s - 1].first)) {
r.pop_back();
--s;
}
r << p;
}
r.pop_back();
return r;
}
class UnionFind {
vi p, s;
void extend(int N) {
foor(i, p.size(), N) {
p << i;
s << 1;
}
}
public:
UnionFind(void) {}
UnionFind(int N) { extend(N - 1); }
int find(int i) {
extend(i);
return p[i] = p[i] == i ? i : find(p[i]);
}
void unite(int a, int b) {
extend(a);
extend(b);
if ((a = find(a)) != (b = find(b))) {
if (s[a] > s[b]) {
swap(a, b);
}
s[b] += s[a];
p[a] = b;
}
}
void unite(pii p) { return unite(p.first, p.second); }
bool same(int a, int b) {
extend(a);
extend(b);
return find(a) == find(b);
}
bool same(pii p) { return same(p.first, p.second); }
int size(int x) {
extend(x);
return s[find(x)];
}
};
ll MST(vector<pair<ll, pii>> &E) {
Sort(E);
UnionFind uf;
ll z = 0;
for (auto &e : E) {
if (!uf.same(e.second)) {
z += e.first;
uf.unite(e.second);
}
}
return z;
}
ll strmod(const str &s, const int m) {
ll x = 0;
fr(i, s.size()) { x = (x * 10 + s[i] - 48) % m; }
return x;
}
vvl mul(const vvl &A, const vvl &B, const int m) {
vvl C;
fr(y, A.size()) { C << vl(B[y].size()); }
fr(y, C.size()) {
fr(x, C[y].size()) {
fr(i, A[0].size()) { (C[y][x] += A[y][i] * B[i][x]) %= m; }
}
}
return C;
}
vvl pow(const vvl &A, const ll n, const int m) {
vvl B;
fr(y, A.size()) { B << vl(A.size()); }
if (n == 0) {
fr(i, B.size()) { B[i][i] = 1; }
}
elsif(n % 2) { B = mul(A, pow(A, n - 1, m), m); }
else {
vvl C = pow(A, n / 2, m);
B = mul(C, C, m);
}
return B;
}
ll pow(const ll a, const ll n, const int m) {
ll t;
return n ? (n & 1 ? a >= 0 ? a % m : (m - (-a % m)) % m : 1) *
(t = pow(a, n >> 1, m), t * t % m) % m
: !!a;
}
ll inv(const ll x, const int p) { return pow(x, p - 2, p); }
ll inv(const ll x) { return inv(x, MD); }
vpll fact(const int n, const int p) {
vpll v(n + 1);
v[0].first = 1;
foor(i, 1, n) { v[i].first = v[i - 1].first * i % p; }
v[n].second = inv(v[n].first, p);
roof(i, n, 1) { v[i - 1].second = v[i].second * i % p; }
return v;
}
class Combination {
const vpll f;
const int M;
public:
Combination(int n, int m) : f(fact(n, m)), M(m) {}
Combination(int n) : Combination(n, MD) {}
ll P(int n, int k) {
return n < 0 || k < 0 || n < k ? 0ll : f[n].first * f[n - k].second % M;
}
ll C(int n, int k) { return P(n, k) * f[k].second % M; }
ll H(int n, int k) { return n == 0 && k == 0 ? 1ll : C(n + k - 1, k); }
};
ll C2(const int n) { return (ll)n * ~-n / 2; }
ll sum(const vi a) {
ll s = 0;
for (int e : a) {
s += e;
}
return s;
}
ll sum(const vl a) {
ll s = 0;
for (ll e : a) {
s += e;
}
return s;
}
template <typename T> int MSB(T N) {
int r = -1;
for (; N > 0; N /= 2) {
++r;
}
return r;
}
template <typename T> class SegmentTree {
vector<T> S;
T (*const op)(T a, T b);
const T zero;
const int B;
public:
SegmentTree(int N, T (*f)(T a, T b), const T zero)
: S(1 << MSB(N - 1) + 2, zero), op(f), zero(zero),
B(1 << MSB(N - 1) + 1) {}
SegmentTree(vector<T> v, T (*f)(T a, T b), const T zero)
: SegmentTree(v.size(), f, zero) {
fr(i, v.size()) { S[S.size() / 2 + i] = v[i]; }
roof(i, S.size() / 2 - 1, 1) { S[i] = op(S[i * 2], S[i * 2 + 1]); }
}
T calc(int l, int r) {
l += B;
r += B;
if (l > r) {
return zero;
}
if (l == r) {
return S[l];
}
T L = S[l], R = S[r];
for (; l / 2 < r / 2; l /= 2, r /= 2) {
if (l % 2 == 0) {
L = op(L, S[l + 1]);
}
if (r % 2 == 1) {
R = op(S[r - 1], R);
}
}
return op(L, R);
}
void replace(int i, T x) {
for (S[i += B] = x; i != 1; i /= 2) {
if (i % 2) {
S[i / 2] = op(S[i - 1], S[i]);
} else {
S[i / 2] = op(S[i], S[i + 1]);
}
}
}
void add(int i, T x) { replace(i, op(S[B + i], x)); }
T top() { return S[1]; }
};
ll BITsum(vl &B, int i) {
ll z = 0;
while (i > 0) {
z += B[i];
i -= i & -i;
}
return z;
}
void BITadd(vl &B, int i, ll x) {
while (i < B.size()) {
B[i] += x;
i += i & -i;
}
}
ll fib(const ll n, const int m) {
ll a, b, c, d, A, B, C, D;
a = 1;
b = 0;
c = 0;
d = 1;
rf(i, 63) {
A = a * a + b * c;
B = a * b + b * d;
C = c * a + d * c;
D = c * b + d * d;
if (n >> i & 1) {
a = A;
b = B;
c = C;
d = D;
A = a + b;
B = a;
C = c + d;
D = c;
}
a = A % m;
b = B % m;
c = C % m;
d = D % m;
}
return b;
}
vi primes(int n) {
vb b(n + 1);
vi p;
foor(i, 2, n) {
if (!b[i]) {
p << i;
for (int j = 2 * i; j <= n; j += i) {
b[j] = true;
}
}
}
return p;
}
vb isprime(const int n) {
vb v(n + 1, true);
v[0] = v[1] = false;
foor(i, 2, n) {
if (v[i]) {
for (int j = 2 * i; j <= n; j += i) {
v[j] = false;
}
}
}
return v;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vvi E(N);
fr(i, M) {
int a, b;
cin >> a >> b;
E[--a] << --b;
E[b] << a;
}
bool s6 = false;
vi v4;
fr(i, N) {
if (E[i].size() % 2) {
Yn(false);
return 0;
}
if (E[i].size() == 6)
s6 = true;
if (E[i].size() == 4)
v4 << i;
}
if (s6 || v4.size() >= 3) {
Yn(true);
return 0;
}
if (v4.size() < 2) {
Yn(false);
return 0;
}
assert(v4.size() == 2);
auto f = [&](auto &f, int i, int p) -> bool {
if (i == v4[0])
return true;
if (i == v4[1])
return false;
for (int j : E[i])
if (j != p) {
return f(f, j, i);
}
};
for (int i : E[v4[0]]) {
if (f(f, i, v4[0])) {
Yn(true);
return 0;
}
}
Yn(false);
return 0;
}
| replace | 607 | 609 | 607 | 627 | 0 | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
using namespace std;
const int N = 1e5 + 100;
int n, m, dg[N], vi[N], fb;
int tot, first[N], nxt[N * 2], point[N * 2];
bool ok;
vector<int> f;
inline void add_edge(int x, int y) {
tot++;
nxt[tot] = first[x];
first[x] = tot;
point[tot] = y;
}
void dfs(int x, int fa) {
if (f[0] == x && fa != 0)
ok = 1;
for (int i = first[x]; i != -1; i = nxt[i]) {
int u = point[i];
if (u == fa || u == f[1])
continue;
dfs(u, x);
}
}
signed main() {
tot = -1;
memset(first, -1, sizeof(first));
memset(nxt, -1, sizeof(nxt));
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int u, v;
scanf("%d%d", &u, &v);
add_edge(u, v);
add_edge(v, u);
dg[u]++;
dg[v]++;
}
bool bl = 1;
for (int i = 1; i <= n; i++) {
if (dg[i] & 1) {
bl = 0;
break;
}
}
if (!bl) {
printf("No\n");
return 0;
}
int MAX = 0, cnt = 0;
for (int i = 1; i <= n; i++)
MAX = max(MAX, dg[i]);
for (int i = 1; i <= n; i++)
if (dg[i] == MAX)
cnt++;
if (MAX < 4 || (MAX == 4 && cnt < 2)) {
printf("No\n");
return 0;
}
if (MAX > 4 || (MAX == 4 && cnt > 2)) {
printf("Yes\n");
return 0;
}
for (int i = 1; i <= n; i++)
if (dg[i] == MAX)
f.push_back(i);
ok = 0;
dfs(f[0], 0);
if (ok)
printf("Yes\n");
else
printf("No\n");
} | #include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
using namespace std;
const int N = 1e5 + 100;
int n, m, dg[N], vi[N], fb;
int tot, first[N], nxt[N * 2], point[N * 2];
bool ok;
vector<int> f;
inline void add_edge(int x, int y) {
tot++;
nxt[tot] = first[x];
first[x] = tot;
point[tot] = y;
}
void dfs(int x, int fa) {
if (f[0] == x && fa != 0)
ok = 1;
if (ok)
return;
for (int i = first[x]; i != -1; i = nxt[i]) {
int u = point[i];
if (u == fa || u == f[1])
continue;
dfs(u, x);
}
}
signed main() {
tot = -1;
memset(first, -1, sizeof(first));
memset(nxt, -1, sizeof(nxt));
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int u, v;
scanf("%d%d", &u, &v);
add_edge(u, v);
add_edge(v, u);
dg[u]++;
dg[v]++;
}
bool bl = 1;
for (int i = 1; i <= n; i++) {
if (dg[i] & 1) {
bl = 0;
break;
}
}
if (!bl) {
printf("No\n");
return 0;
}
int MAX = 0, cnt = 0;
for (int i = 1; i <= n; i++)
MAX = max(MAX, dg[i]);
for (int i = 1; i <= n; i++)
if (dg[i] == MAX)
cnt++;
if (MAX < 4 || (MAX == 4 && cnt < 2)) {
printf("No\n");
return 0;
}
if (MAX > 4 || (MAX == 4 && cnt > 2)) {
printf("Yes\n");
return 0;
}
for (int i = 1; i <= n; i++)
if (dg[i] == MAX)
f.push_back(i);
ok = 0;
dfs(f[0], 0);
if (ok)
printf("Yes\n");
else
printf("No\n");
} | insert | 18 | 18 | 18 | 20 | 0 | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int, int>
#define pll pair<ll, ll>
#define PB push_back
#define fi first
#define se second
#define For(i, j, k) for (int i = (int)(j); i <= (int)(k); i++)
#define Rep(i, j, k) for (int i = (int)(j); i >= (int)(k); i--)
#define CLR(a, v) memset(a, v, sizeof(a));
#define CPY(a, b) memcpy(a, b, sizeof(a));
using namespace std;
const int N = 100005;
struct edge {
int to, next;
} e[N * 2];
int head[N], tot, n, m, cnt;
int deg[N], vis[N], q4[N];
void add(int x, int y) {
e[++tot] = (edge){y, head[x]};
head[x] = tot;
}
void findpath(int x, int fa) {
if (x == q4[2])
return ++cnt, void(0);
if (x == q4[1] && fa)
return;
for (int i = head[x]; i; i = e[i].next)
if (e[i].to != fa)
findpath(e[i].to, x);
}
int main() {
scanf("%d%d", &n, &m);
For(i, 1, m) {
int x, y;
scanf("%d%d", &x, &y);
++deg[x];
++deg[y];
add(x, y);
add(y, x);
}
int S6 = 0, S4 = 0;
For(i, 1, n) if (deg[i] & 1) return puts("No"), 0;
else if (deg[i] >= 6)++ S6;
else if (deg[i] == 4) q4[++S4] = i;
if (S6 || S4 > 3)
return puts("Yes"), 0;
if (S4 < 1)
return puts("No"), 0;
vis[q4[1]] = vis[q4[2]] = 1;
findpath(q4[1], 0);
puts(cnt == 2 ? "Yes" : "No");
}
| #include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int, int>
#define pll pair<ll, ll>
#define PB push_back
#define fi first
#define se second
#define For(i, j, k) for (int i = (int)(j); i <= (int)(k); i++)
#define Rep(i, j, k) for (int i = (int)(j); i >= (int)(k); i--)
#define CLR(a, v) memset(a, v, sizeof(a));
#define CPY(a, b) memcpy(a, b, sizeof(a));
using namespace std;
const int N = 100005;
struct edge {
int to, next;
} e[N * 2];
int head[N], tot, n, m, cnt;
int deg[N], vis[N], q4[N];
void add(int x, int y) {
e[++tot] = (edge){y, head[x]};
head[x] = tot;
}
void findpath(int x, int fa) {
if (x == q4[2])
return ++cnt, void(0);
if (x == q4[1] && fa)
return;
for (int i = head[x]; i; i = e[i].next)
if (e[i].to != fa)
findpath(e[i].to, x);
}
int main() {
scanf("%d%d", &n, &m);
For(i, 1, m) {
int x, y;
scanf("%d%d", &x, &y);
++deg[x];
++deg[y];
add(x, y);
add(y, x);
}
int S6 = 0, S4 = 0;
For(i, 1, n) if (deg[i] & 1) return puts("No"), 0;
else if (deg[i] >= 6)++ S6;
else if (deg[i] == 4) q4[++S4] = i;
if (S6 || S4 >= 3)
return puts("Yes"), 0;
if (S4 < 1)
return puts("No"), 0;
vis[q4[1]] = vis[q4[2]] = 1;
findpath(q4[1], 0);
puts(cnt == 2 ? "Yes" : "No");
}
| replace | 47 | 48 | 47 | 48 | 0 | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
vector<int> edge[100005];
int dfn[100005], dfnn, X, Y;
int dfs(int x, int p, int c) {
int ret = 0;
dfn[x] = ++dfnn;
if (x == Y)
c = 1;
for (auto i : edge[x]) {
if (i == p)
continue;
if (dfn[i]) {
if (i == X && c)
ret++;
continue;
}
ret += dfs(i, x, c);
}
return ret;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int N, M;
cin >> N >> M;
for (int i = 0; i < M; ++i) {
int x, y;
cin >> x >> y;
edge[x].push_back(y);
edge[y].push_back(x);
}
int flag = 0;
vector<int> vec;
for (int i = 1; i <= N; ++i) {
if (edge[i].size() & 1)
return !puts("No");
if (edge[i].size() >= 6)
flag = 1;
if (edge[i].size() == 4)
vec.push_back(i);
}
if (flag || vec.size() > 2)
puts("Yes");
else {
X = vec[0];
Y = vec[1];
if (vec.size() == 2 && dfs(vec[0], 0, 0) == 1)
puts("Yes");
else
puts("No");
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
vector<int> edge[100005];
int dfn[100005], dfnn, X, Y;
int dfs(int x, int p, int c) {
int ret = 0;
dfn[x] = ++dfnn;
if (x == Y)
c = 1;
for (auto i : edge[x]) {
if (i == p)
continue;
if (dfn[i]) {
if (i == X && c)
ret++;
continue;
}
ret += dfs(i, x, c);
}
return ret;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int N, M;
cin >> N >> M;
for (int i = 0; i < M; ++i) {
int x, y;
cin >> x >> y;
edge[x].push_back(y);
edge[y].push_back(x);
}
int flag = 0;
vector<int> vec;
for (int i = 1; i <= N; ++i) {
if (edge[i].size() & 1)
return !puts("No");
if (edge[i].size() >= 6)
flag = 1;
if (edge[i].size() == 4)
vec.push_back(i);
}
if (flag || vec.size() > 2)
puts("Yes");
else {
if (vec.size() == 2) {
X = vec[0];
Y = vec[1];
}
if (vec.size() == 2 && dfs(vec[0], 0, 0) == 1)
puts("Yes");
else
puts("No");
}
return 0;
} | replace | 47 | 49 | 47 | 51 | 0 | |
p03091 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define rep(i, n) for (long i = 0; i < n; i++)
using namespace std;
int main(void) {
long N, M;
cin >> N >> M;
unordered_map<long, unordered_set<long>> connect;
rep(i, M) {
long a, b;
cin >> a >> b;
connect[a].insert(b);
connect[b].insert(a);
}
long odd_nodes = 0;
long four_nodes = 0;
long six_nodes = 0;
vector<long> four_node_indexes;
for (auto it : connect) {
long size = it.second.size();
if (size % 2 == 1)
odd_nodes++;
if (size == 4) {
four_nodes++;
four_node_indexes.push_back(it.first);
}
if (size % 2 == 0 and size >= 6)
six_nodes++;
}
if (odd_nodes != 0) {
cout << "No" << endl;
return 0;
}
if (six_nodes != 0) {
cout << "Yes" << endl;
return 0;
}
if (four_nodes < 2) {
cout << "No" << endl;
return 0;
}
if (four_nodes > 2) {
cout << "Yes" << endl;
return 0;
}
for (auto it : connect[four_node_indexes[0]]) {
long current = it;
unordered_set<long> walked;
walked.insert(four_node_indexes[0]);
while (true) {
}
if (current == four_node_indexes[1]) {
break;
}
unordered_set<long> neibor = connect[current];
auto it2 = neibor.begin();
long foo = *it2;
it2++;
long bar = *it2;
if (walked.count(foo) != 0 and walked.count(bar) != 0) {
cout << "Yes" << endl;
return 0;
long next = walked.count(foo) == 0 ? foo : bar;
walked.insert(current);
current = next;
}
}
cout << "No" << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define rep(i, n) for (long i = 0; i < n; i++)
using namespace std;
int main(void) {
long N, M;
cin >> N >> M;
unordered_map<long, unordered_set<long>> connect;
rep(i, M) {
long a, b;
cin >> a >> b;
connect[a].insert(b);
connect[b].insert(a);
}
long odd_nodes = 0;
long four_nodes = 0;
long six_nodes = 0;
vector<long> four_node_indexes;
for (auto it : connect) {
long size = it.second.size();
if (size % 2 == 1)
odd_nodes++;
if (size == 4) {
four_nodes++;
four_node_indexes.push_back(it.first);
}
if (size % 2 == 0 and size >= 6)
six_nodes++;
}
if (odd_nodes != 0) {
cout << "No" << endl;
return 0;
}
if (six_nodes != 0) {
cout << "Yes" << endl;
return 0;
}
if (four_nodes < 2) {
cout << "No" << endl;
return 0;
}
if (four_nodes > 2) {
cout << "Yes" << endl;
return 0;
}
for (auto it : connect[four_node_indexes[0]]) {
long current = it;
unordered_set<long> walked;
walked.insert(four_node_indexes[0]);
while (true) {
if (current == four_node_indexes[1]) {
break;
}
unordered_set<long> neibor = connect[current];
auto it2 = neibor.begin();
long foo = *it2;
it2++;
long bar = *it2;
if (walked.count(foo) != 0 and walked.count(bar) != 0) {
cout << "Yes" << endl;
return 0;
}
long next = walked.count(foo) == 0 ? foo : bar;
walked.insert(current);
current = next;
}
}
cout << "No" << endl;
return 0;
}
| replace | 61 | 73 | 61 | 73 | TLE | |
p03091 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
vector<int> G[100006];
int life[100006];
void dfs(int now, int par, int home) {
int e;
rep(i, G[now].size()) {
int f = G[now][i];
if (f == par)
continue;
if (life[f] == 0)
continue;
e = f;
}
// cout << now << ' ' << e << endl;
life[now]--;
if (e == home)
return;
dfs(e, now, home);
return;
}
signed main() {
int n, m;
cin >> n >> m;
rep(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
int flg1 = 0, maxo = 0;
rep(i, n) {
if (G[i].size() & 1)
flg1++;
maxo = max(maxo, (int)G[i].size());
}
if (flg1 || maxo < 3) {
cout << "No" << endl;
return 0;
}
if (maxo >= 6) {
cout << "Yes" << endl;
return 0;
}
int cnt4 = 0;
rep(i, n) if (G[i].size() == 4) cnt4++;
if (cnt4 == 1) {
cout << "No" << endl;
return 0;
}
if (cnt4 == 3) {
cout << "Yes" << endl;
return 0;
}
rep(i, n) life[i] = G[i].size() / 2;
int v1 = -1, v2;
rep(i, n) {
if (G[i].size() == 4) {
if (v1 == -1)
v1 = i;
else
v2 = i;
}
}
dfs(v1, -1, v1);
life[v2]++;
dfs(v2, -1, v2);
life[v2]--;
rep(i, n) {
if (life[i]) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
} | #include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
vector<int> G[100006];
int life[100006];
void dfs(int now, int par, int home) {
int e;
rep(i, G[now].size()) {
int f = G[now][i];
if (f == par)
continue;
if (life[f] == 0)
continue;
e = f;
break;
}
// cout << now << ' ' << e << endl;
life[now]--;
if (e == home)
return;
dfs(e, now, home);
return;
}
signed main() {
int n, m;
cin >> n >> m;
rep(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
int flg1 = 0, maxo = 0;
rep(i, n) {
if (G[i].size() & 1)
flg1++;
maxo = max(maxo, (int)G[i].size());
}
if (flg1 || maxo < 3) {
cout << "No" << endl;
return 0;
}
if (maxo >= 6) {
cout << "Yes" << endl;
return 0;
}
int cnt4 = 0;
rep(i, n) if (G[i].size() == 4) cnt4++;
if (cnt4 == 1) {
cout << "No" << endl;
return 0;
}
if (cnt4 == 3) {
cout << "Yes" << endl;
return 0;
}
rep(i, n) life[i] = G[i].size() / 2;
int v1 = -1, v2;
rep(i, n) {
if (G[i].size() == 4) {
if (v1 == -1)
v1 = i;
else
v2 = i;
}
}
dfs(v1, -1, v1);
life[v2]++;
dfs(v2, -1, v2);
life[v2]--;
rep(i, n) {
if (life[i]) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
} | insert | 16 | 16 | 16 | 17 | TLE | |
p03091 | C++ | Runtime Error | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
typedef tuple<int, int, int> t3;
int n, m;
int deg[100010];
vector<pii> E[100010];
t3 edge[100010];
int chk[100010];
void dfs(int x, int st) {
chk[x] = 1;
t3 e = edge[x];
int a, b, idx;
tie(a, b, idx) = e;
if (st == b)
swap(a, b);
int f = -1;
for (int i = 0; i < szz(E[b]); i++)
if (E[b][i].Fi == a)
f = i;
f ^= 1;
if (chk[E[b][f].Se] == 0)
dfs(E[b][f].Se, b);
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int x, y;
scanf("%d%d", &x, &y);
deg[x]++;
deg[y]++;
E[x].pb(pii(y, i));
E[y].pb(pii(x, i));
edge[i] = t3(x, y, i);
}
for (int i = 1; i <= n; i++)
if (deg[i] & 1) {
puts("No");
return 0;
}
for (int i = 1; i <= n; i++)
if (deg[i] >= 6) {
puts("Yes");
return 0;
}
int ans = 0;
for (int i = 1; i <= n; i++)
if (deg[i] == 4)
++ans;
if (ans >= 3)
puts("Yes");
else if (ans == 1)
puts("No");
else {
int fa = -1, fb = -1;
for (int i = 1; i <= n; i++)
if (deg[i] == 4) {
if (fa == -1)
fa = i;
else
fb = i;
}
int ok = 0;
rep(a, 3) {
rep(b, 3) {
int cc = 0;
memset(chk, 0, sizeof chk);
for (int i = 1; i <= m; i++)
if (chk[i] == 0) {
++cc;
dfs(i, get<0>(edge[i]));
}
if (cc >= 3)
ok = 1;
rotate(E[fa].begin() + 1, E[fa].begin() + 2, E[fa].begin() + 4);
}
rotate(E[fb].begin() + 1, E[fb].begin() + 2, E[fb].begin() + 4);
}
printf("%s\n", ok ? "Yes" : "No");
}
return 0;
} | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
typedef tuple<int, int, int> t3;
int n, m;
int deg[100010];
vector<pii> E[100010];
t3 edge[100010];
int chk[100010];
void dfs(int x, int st) {
chk[x] = 1;
t3 e = edge[x];
int a, b, idx;
tie(a, b, idx) = e;
if (st == b)
swap(a, b);
int f = -1;
for (int i = 0; i < szz(E[b]); i++)
if (E[b][i].Fi == a)
f = i;
f ^= 1;
if (chk[E[b][f].Se] == 0)
dfs(E[b][f].Se, b);
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int x, y;
scanf("%d%d", &x, &y);
deg[x]++;
deg[y]++;
E[x].pb(pii(y, i));
E[y].pb(pii(x, i));
edge[i] = t3(x, y, i);
}
for (int i = 1; i <= n; i++)
if (deg[i] & 1) {
puts("No");
return 0;
}
for (int i = 1; i <= n; i++)
if (deg[i] >= 6) {
puts("Yes");
return 0;
}
int ans = 0;
for (int i = 1; i <= n; i++)
if (deg[i] == 4)
++ans;
if (ans >= 3)
puts("Yes");
else if (ans <= 1)
puts("No");
else {
int fa = -1, fb = -1;
for (int i = 1; i <= n; i++)
if (deg[i] == 4) {
if (fa == -1)
fa = i;
else
fb = i;
}
int ok = 0;
rep(a, 3) {
rep(b, 3) {
int cc = 0;
memset(chk, 0, sizeof chk);
for (int i = 1; i <= m; i++)
if (chk[i] == 0) {
++cc;
dfs(i, get<0>(edge[i]));
}
if (cc >= 3)
ok = 1;
rotate(E[fa].begin() + 1, E[fa].begin() + 2, E[fa].begin() + 4);
}
rotate(E[fb].begin() + 1, E[fb].begin() + 2, E[fb].begin() + 4);
}
printf("%s\n", ok ? "Yes" : "No");
}
return 0;
} | replace | 80 | 81 | 80 | 81 | 0 | |
p03091 | C++ | Runtime Error | #include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long int ll;
struct Edge {
int to, rev;
ll cap;
Edge(int to, ll cap, int rev) : to(to), cap(cap), rev(rev) {}
};
// ここの値に注意!!
const int N = 20500;
const ll INF = 1e9;
vector<Edge> g[N];
int level[N];
int iter[N];
void add_edge(int s, int t, ll c) {
g[s].push_back(Edge(t, c, g[t].size()));
g[t].push_back(Edge(s, 0, g[s].size() - 1));
}
void bfs(int s) {
memset(level, -1, sizeof(level));
queue<int> q;
level[s] = 0;
q.push(s);
while (q.size()) {
int v = q.front();
q.pop();
for (auto &e : g[v]) {
if (e.cap > 0 && level[e.to] < 0) {
level[e.to] = level[v] + 1;
q.push(e.to);
}
}
}
}
ll dfs(int v, int t, ll f) {
if (v == t)
return f;
for (int &i = iter[v]; i < g[v].size(); i++) {
Edge &e = g[v][i];
if (e.cap > 0 && level[v] < level[e.to]) {
int d = dfs(e.to, t, min(f, e.cap));
if (d > 0) {
e.cap -= d;
g[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
ll max_flow(int s, int t) {
ll flow = 0;
while (1) {
bfs(s);
if (level[t] < 0)
return flow;
memset(iter, 0, sizeof(iter));
int f;
while ((f = dfs(s, t, INF)) > 0) {
flow += f;
}
}
}
vector<int> gg[100100];
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
gg[x].push_back(y);
gg[y].push_back(x);
add_edge(x, y, 1);
add_edge(y, x, 1);
}
int six = 0;
int four = 0;
vector<int> v;
for (int i = 0; i < n; i++) {
if (gg[i].size() % 2) {
cout << "No" << endl;
return 0;
}
if (gg[i].size() == 6)
six++;
if (gg[i].size() == 4) {
four++;
v.push_back(i);
}
}
if (six) {
cout << "Yes" << endl;
return 0;
}
if (four >= 3) {
cout << "Yes" << endl;
return 0;
} else {
if (four == 2) {
if (max_flow(v[0], v[1]) == 2) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} else {
cout << "No" << endl;
return 0;
}
}
}
| #include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long int ll;
struct Edge {
int to, rev;
ll cap;
Edge(int to, ll cap, int rev) : to(to), cap(cap), rev(rev) {}
};
// ここの値に注意!!
const int N = 205000;
const ll INF = 1e9;
vector<Edge> g[N];
int level[N];
int iter[N];
void add_edge(int s, int t, ll c) {
g[s].push_back(Edge(t, c, g[t].size()));
g[t].push_back(Edge(s, 0, g[s].size() - 1));
}
void bfs(int s) {
memset(level, -1, sizeof(level));
queue<int> q;
level[s] = 0;
q.push(s);
while (q.size()) {
int v = q.front();
q.pop();
for (auto &e : g[v]) {
if (e.cap > 0 && level[e.to] < 0) {
level[e.to] = level[v] + 1;
q.push(e.to);
}
}
}
}
ll dfs(int v, int t, ll f) {
if (v == t)
return f;
for (int &i = iter[v]; i < g[v].size(); i++) {
Edge &e = g[v][i];
if (e.cap > 0 && level[v] < level[e.to]) {
int d = dfs(e.to, t, min(f, e.cap));
if (d > 0) {
e.cap -= d;
g[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
ll max_flow(int s, int t) {
ll flow = 0;
while (1) {
bfs(s);
if (level[t] < 0)
return flow;
memset(iter, 0, sizeof(iter));
int f;
while ((f = dfs(s, t, INF)) > 0) {
flow += f;
}
}
}
vector<int> gg[100100];
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
gg[x].push_back(y);
gg[y].push_back(x);
add_edge(x, y, 1);
add_edge(y, x, 1);
}
int six = 0;
int four = 0;
vector<int> v;
for (int i = 0; i < n; i++) {
if (gg[i].size() % 2) {
cout << "No" << endl;
return 0;
}
if (gg[i].size() == 6)
six++;
if (gg[i].size() == 4) {
four++;
v.push_back(i);
}
}
if (six) {
cout << "Yes" << endl;
return 0;
}
if (four >= 3) {
cout << "Yes" << endl;
return 0;
} else {
if (four == 2) {
if (max_flow(v[0], v[1]) == 2) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} else {
cout << "No" << endl;
return 0;
}
}
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p03091 | C++ | Runtime Error | /*
This Submission is to determine how many 120/240 min const. delivery point there
are.
//info
120 req. steps <= 5
*/
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 1000000007
#define seg_size 262144
#define REP(a, b) for (long long a = 0; a < b; ++a)
unsigned long xor128() {
static unsigned long x = time(NULL), y = 362436069, z = 521288629,
w = 88675123;
unsigned long t = (x ^ (x << 11));
x = y;
y = z;
z = w;
return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
double dot(complex<double> a, complex<double> b) {
return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
double cosine = dot(a, b) / (leng(a) * leng(b));
double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
double kaku = acos(min((double)1.0, max((double)-1.0, cosine)));
if (sine <= 0) {
kaku = 2 * Ma_PI - kaku;
}
return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
vector<int> ans;
double now_minnest = a[0].real();
int now_itr = 0;
REP(i, a.size()) {
if (now_minnest > a[i].real()) {
now_minnest = a[i].real();
now_itr = i;
}
}
ans.push_back(now_itr);
complex<double> ba(0, 1);
while (true) {
int now_go = 0;
double now_min = 0;
double now_length = 0;
int starter = ans[ans.size() - 1];
for (int i = 0; i < a.size(); ++i) {
if (i != starter) {
double goa = angles(ba, a[i] - a[starter]);
if (goa - now_min >= eps ||
(abs(goa - now_min) <= eps &&
(abs(a[i] - a[starter]) - now_length) >= eps)) {
now_min = goa;
now_go = i;
now_length = abs(a[i] - a[starter]);
}
}
}
if (now_go == ans[0])
break;
ans.push_back(now_go);
ba = complex<double>(a[now_go] - a[starter]);
}
return ans;
}
vector<int> vertexs[200000];
int visited[200000];
vector<int> hoge;
int target = 0;
int dfs(int now, int back) {
for (int q = 0; q < vertexs[now].size(); ++q) {
if (vertexs[now][q] == back)
continue;
if (vertexs[now][q] == target)
return 1;
int bad = 0;
REP(j, 2) {
if (vertexs[now][q] == hoge[j]) {
bad = 1;
break;
}
}
if (bad == 1)
continue;
if (visited[vertexs[now][q]] == 1)
continue;
visited[vertexs[now][q]] = 1;
int now = dfs(vertexs[now][q], now);
if (now == 1)
return 1;
}
return 0;
}
int main() {
int n, m;
cin >> n >> m;
REP(i, m) {
int a, b;
cin >> a >> b;
vertexs[a].push_back(b);
vertexs[b].push_back(a);
}
REP(i, n) {
if (vertexs[i + 1].size() % 2 == 1) {
cout << "No" << endl;
return 0;
}
}
REP(i, n) {
if (vertexs[i + 1].size() >= 6) {
cout << "Yes" << endl;
return 0;
}
if (vertexs[i + 1].size() == 4) {
hoge.push_back(i + 1);
}
}
if (hoge.size() >= 3) {
cout << "Yes" << endl;
return 0;
}
if (hoge.size() <= 1) {
cout << "No" << endl;
return 0;
}
REP(q, 2) {
target = hoge[q];
visited[target] = 1;
int tmp = dfs(target, -1);
if (tmp == 0) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | /*
This Submission is to determine how many 120/240 min const. delivery point there
are.
//info
120 req. steps <= 5
*/
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 1000000007
#define seg_size 262144
#define REP(a, b) for (long long a = 0; a < b; ++a)
unsigned long xor128() {
static unsigned long x = time(NULL), y = 362436069, z = 521288629,
w = 88675123;
unsigned long t = (x ^ (x << 11));
x = y;
y = z;
z = w;
return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
double dot(complex<double> a, complex<double> b) {
return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
double cosine = dot(a, b) / (leng(a) * leng(b));
double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
double kaku = acos(min((double)1.0, max((double)-1.0, cosine)));
if (sine <= 0) {
kaku = 2 * Ma_PI - kaku;
}
return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
vector<int> ans;
double now_minnest = a[0].real();
int now_itr = 0;
REP(i, a.size()) {
if (now_minnest > a[i].real()) {
now_minnest = a[i].real();
now_itr = i;
}
}
ans.push_back(now_itr);
complex<double> ba(0, 1);
while (true) {
int now_go = 0;
double now_min = 0;
double now_length = 0;
int starter = ans[ans.size() - 1];
for (int i = 0; i < a.size(); ++i) {
if (i != starter) {
double goa = angles(ba, a[i] - a[starter]);
if (goa - now_min >= eps ||
(abs(goa - now_min) <= eps &&
(abs(a[i] - a[starter]) - now_length) >= eps)) {
now_min = goa;
now_go = i;
now_length = abs(a[i] - a[starter]);
}
}
}
if (now_go == ans[0])
break;
ans.push_back(now_go);
ba = complex<double>(a[now_go] - a[starter]);
}
return ans;
}
vector<int> vertexs[200000];
int visited[200000];
vector<int> hoge;
int target = 0;
int dfs(int now, int back) {
for (int q = 0; q < vertexs[now].size(); ++q) {
if (vertexs[now][q] == back)
continue;
if (vertexs[now][q] == target)
return 1;
int bad = 0;
REP(j, 2) {
if (vertexs[now][q] == hoge[j]) {
bad = 1;
break;
}
}
if (bad == 1)
continue;
if (visited[vertexs[now][q]] == 1)
continue;
visited[vertexs[now][q]] = 1;
int nowa = dfs(vertexs[now][q], now);
if (nowa == 1)
return 1;
}
return 0;
}
int main() {
int n, m;
cin >> n >> m;
REP(i, m) {
int a, b;
cin >> a >> b;
vertexs[a].push_back(b);
vertexs[b].push_back(a);
}
REP(i, n) {
if (vertexs[i + 1].size() % 2 == 1) {
cout << "No" << endl;
return 0;
}
}
REP(i, n) {
if (vertexs[i + 1].size() >= 6) {
cout << "Yes" << endl;
return 0;
}
if (vertexs[i + 1].size() == 4) {
hoge.push_back(i + 1);
}
}
if (hoge.size() >= 3) {
cout << "Yes" << endl;
return 0;
}
if (hoge.size() <= 1) {
cout << "No" << endl;
return 0;
}
REP(q, 2) {
target = hoge[q];
visited[target] = 1;
int tmp = dfs(target, -1);
if (tmp == 0) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | replace | 132 | 134 | 132 | 134 | 0 | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
template <class T> void debug(T itr1, T itr2) {
auto now = itr1;
while (now < itr2) {
cout << *now << " ";
now++;
}
cout << endl;
}
#define repr(i, from, to) for (int i = (int)from; i < (int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i, N) repr(i, 0, N)
#define per(i, N) for (int i = (int)N - 1; i >= 0; i--)
const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;
vector<vector<int>> adj;
vector<bool> passed;
int dfs(int n, int to, int p = -1) {
passed[n] = true;
ll result = 0;
for (auto x : adj[n]) {
if (x == p)
continue;
if (x == to)
result++;
else
result += dfs(x, to, n);
}
return result;
}
int main() {
int N, M;
cin >> N >> M;
adj.resize(N);
rep(i, M) {
int a, b;
cin >> a >> b;
a--;
b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
bool ok = true, to6 = false;
vector<int> to4;
rep(i, N) {
if (adj[i].size() % 2)
ok = false;
if (adj[i].size() == 4)
to4.push_back(i);
if (adj[i].size() >= 6)
to6 = true;
}
string result = "No";
if (ok) {
if (to6 || to4.size() >= 3)
result = "Yes";
else if (to4.size() == 2) {
passed.resize(N, false);
if (dfs(to4[0], to4[1]) == 2)
result = "Yes";
}
}
cout << result << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
template <class T> void debug(T itr1, T itr2) {
auto now = itr1;
while (now < itr2) {
cout << *now << " ";
now++;
}
cout << endl;
}
#define repr(i, from, to) for (int i = (int)from; i < (int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i, N) repr(i, 0, N)
#define per(i, N) for (int i = (int)N - 1; i >= 0; i--)
const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;
vector<vector<int>> adj;
vector<bool> passed;
int dfs(int n, int to, int p = -1) {
passed[n] = true;
ll result = 0;
for (auto x : adj[n]) {
if (x == p || passed[x])
continue;
if (x == to)
result++;
else
result += dfs(x, to, n);
}
return result;
}
int main() {
int N, M;
cin >> N >> M;
adj.resize(N);
rep(i, M) {
int a, b;
cin >> a >> b;
a--;
b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
bool ok = true, to6 = false;
vector<int> to4;
rep(i, N) {
if (adj[i].size() % 2)
ok = false;
if (adj[i].size() == 4)
to4.push_back(i);
if (adj[i].size() >= 6)
to6 = true;
}
string result = "No";
if (ok) {
if (to6 || to4.size() >= 3)
result = "Yes";
else if (to4.size() == 2) {
passed.resize(N, false);
if (dfs(to4[0], to4[1]) == 2)
result = "Yes";
}
}
cout << result << endl;
return 0;
} | replace | 30 | 31 | 30 | 31 | 0 | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORD(i, a, b) for (int i = a; i >= b; --i)
using namespace std;
typedef long long LL;
typedef pair<int, int> pa;
typedef vector<int> vec;
void getint(int &v) {
char ch, fu = 0;
for (ch = '*'; (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
;
if (ch == '-')
fu = 1, ch = getchar();
for (v = 0; ch >= '0' && ch <= '9'; ch = getchar())
v = v * 10 + ch - '0';
if (fu)
v = -v;
}
bool v[500010];
int nedge, too[500010], hed[500010], x[500010], y[500010], nxt[500010], n, m,
d[500010], d4, A, B;
void ae(int x, int y) {
nxt[++nedge] = hed[x];
hed[x] = nedge;
too[nedge] = y;
}
void dfs(int x) {
v[x] = 1;
for (int i = hed[x]; i; i = nxt[i]) {
int y = too[i];
if (y == B)
continue;
dfs(y);
}
}
int main() {
cin >> n >> m;
if (n == 1)
return puts("No"), 0;
FOR(i, 1, m) {
getint(x[i]), getint(y[i]);
++d[x[i]], ++d[y[i]];
ae(x[i], y[i]), ae(y[i], x[i]);
}
FOR(i, 1, n) if (d[i] & 1) return puts("No"), 0;
FOR(i, 1, n) if (d[i] >= 6) return puts("Yes"), 0;
FOR(i, 1, n) if (d[i] >= 4)++ d4;
if (d4 >= 3)
return puts("Yes"), 0;
if (d4 <= 1)
return puts("No"), 0;
FOR(i, 1, n) if (d[i] == 4) A = i;
FOR(i, 1, n) if (d[i] == 4 && i != A) B = i;
dfs(A);
for (int i = hed[B]; i; i = nxt[i]) {
int y = too[i];
if (!v[y])
return puts("Yes"), 0;
}
puts("No");
return 0;
} | #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORD(i, a, b) for (int i = a; i >= b; --i)
using namespace std;
typedef long long LL;
typedef pair<int, int> pa;
typedef vector<int> vec;
void getint(int &v) {
char ch, fu = 0;
for (ch = '*'; (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
;
if (ch == '-')
fu = 1, ch = getchar();
for (v = 0; ch >= '0' && ch <= '9'; ch = getchar())
v = v * 10 + ch - '0';
if (fu)
v = -v;
}
bool v[500010];
int nedge, too[500010], hed[500010], x[500010], y[500010], nxt[500010], n, m,
d[500010], d4, A, B;
void ae(int x, int y) {
nxt[++nedge] = hed[x];
hed[x] = nedge;
too[nedge] = y;
}
void dfs(int x) {
v[x] = 1;
for (int i = hed[x]; i; i = nxt[i]) {
int y = too[i];
if (y == B || v[y])
continue;
dfs(y);
}
}
int main() {
cin >> n >> m;
if (n == 1)
return puts("No"), 0;
FOR(i, 1, m) {
getint(x[i]), getint(y[i]);
++d[x[i]], ++d[y[i]];
ae(x[i], y[i]), ae(y[i], x[i]);
}
FOR(i, 1, n) if (d[i] & 1) return puts("No"), 0;
FOR(i, 1, n) if (d[i] >= 6) return puts("Yes"), 0;
FOR(i, 1, n) if (d[i] >= 4)++ d4;
if (d4 >= 3)
return puts("Yes"), 0;
if (d4 <= 1)
return puts("No"), 0;
FOR(i, 1, n) if (d[i] == 4) A = i;
FOR(i, 1, n) if (d[i] == 4 && i != A) B = i;
dfs(A);
for (int i = hed[B]; i; i = nxt[i]) {
int y = too[i];
if (!v[y])
return puts("Yes"), 0;
}
puts("No");
return 0;
} | replace | 35 | 36 | 35 | 36 | 0 | |
p03091 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define mkp make_pair
#define mkt make_tuple
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
template <class T> void chmin(T &a, const T &b) {
if (a > b)
a = b;
}
template <class T> void chmax(T &a, const T &b) {
if (a < b)
a = b;
}
int N, M;
vector<int> g[100010];
int countCycles() {
vector<int> deg(N, 0);
rep(i, N) deg[i] = g[i].size();
int res = 0;
map<pair<int, int>, int> mp;
vector<int> used(N, 0);
vector<int> pos(N, 0);
for (int i = 0; i < N; i++) {
if (deg[i] == 0)
continue;
stack<int> st;
st.push(i);
used[i] = 1;
while (1) {
int now = st.top();
int nex = -1;
for (; pos[now] < g[now].size(); pos[now]++) {
int tar = g[now][pos[now]];
if (mp.count(mkp(now, tar)))
continue;
nex = tar;
pos[now]++;
break;
}
if (nex == -1)
break;
if (used[nex]) {
deg[now]--;
deg[nex]--;
mp[mkp(now, nex)] = 1;
mp[mkp(nex, now)] = 1;
while (st.top() != nex) {
int tmp = st.top();
st.pop();
used[tmp] = 0;
}
res++;
continue;
} else {
st.push(nex);
deg[now]--;
deg[nex]--;
used[nex] = 1;
mp[mkp(now, nex)] = 1;
mp[mkp(nex, now)] = 1;
}
}
used[i] = 0;
}
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N >> M;
rep(i, M) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
rep(i, N) {
if (g[i].size() % 2) {
cout << "No" << endl;
return 0;
}
}
for (int k = 0; k < 50; k++) {
random_device rg;
mt19937 engine(rg());
rep(i, N) shuffle(g[i].begin(), g[i].end(), engine);
int cycles = countCycles();
if (cycles >= 3) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define mkp make_pair
#define mkt make_tuple
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
template <class T> void chmin(T &a, const T &b) {
if (a > b)
a = b;
}
template <class T> void chmax(T &a, const T &b) {
if (a < b)
a = b;
}
int N, M;
vector<int> g[100010];
int countCycles() {
vector<int> deg(N, 0);
rep(i, N) deg[i] = g[i].size();
int res = 0;
map<pair<int, int>, int> mp;
vector<int> used(N, 0);
vector<int> pos(N, 0);
for (int i = 0; i < N; i++) {
if (deg[i] == 0)
continue;
stack<int> st;
st.push(i);
used[i] = 1;
while (1) {
int now = st.top();
int nex = -1;
for (; pos[now] < g[now].size(); pos[now]++) {
int tar = g[now][pos[now]];
if (mp.count(mkp(now, tar)))
continue;
nex = tar;
pos[now]++;
break;
}
if (nex == -1)
break;
if (used[nex]) {
deg[now]--;
deg[nex]--;
mp[mkp(now, nex)] = 1;
mp[mkp(nex, now)] = 1;
while (st.top() != nex) {
int tmp = st.top();
st.pop();
used[tmp] = 0;
}
res++;
continue;
} else {
st.push(nex);
deg[now]--;
deg[nex]--;
used[nex] = 1;
mp[mkp(now, nex)] = 1;
mp[mkp(nex, now)] = 1;
}
}
used[i] = 0;
}
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N >> M;
rep(i, M) {
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
rep(i, N) {
if (g[i].size() % 2) {
cout << "No" << endl;
return 0;
}
}
for (int k = 0; k < 10; k++) {
random_device rg;
mt19937 engine(rg());
rep(i, N) shuffle(g[i].begin(), g[i].end(), engine);
int cycles = countCycles();
if (cycles >= 3) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
}
| replace | 107 | 108 | 107 | 108 | TLE | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> g(n);
int odd = 0;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--, b--;
g[a].emplace_back(b);
g[b].emplace_back(a);
}
int mx = 0, cnt = 0;
for (int i = 0; i < n; i++) {
mx = max(mx, (int)g[i].size());
if (g[i].size() == 4) {
cnt++;
}
if (g[i].size() % 2 == 1) {
puts("No");
return 0;
}
}
if (mx >= 6 || cnt >= 3) {
puts("Yes");
return 0;
}
if (mx == 2 || cnt < 2) {
puts("No");
return 0;
}
int x = -1, y;
for (int i = 0; i < n; i++) {
if (g[i].size() == 4) {
y = i;
if (x == -1) {
swap(x, y);
}
}
}
int ok = 4;
function<void(int, int)> dfs = [&](int v, int p) {
for (int to : g[v]) {
if (to == p)
continue;
if (to == y) {
ok--;
break;
}
dfs(to, v);
}
};
dfs(x, -1);
if (ok) {
puts("Yes");
} else {
puts("No");
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> g(n);
int odd = 0;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--, b--;
g[a].emplace_back(b);
g[b].emplace_back(a);
}
int mx = 0, cnt = 0;
for (int i = 0; i < n; i++) {
mx = max(mx, (int)g[i].size());
if (g[i].size() == 4) {
cnt++;
}
if (g[i].size() % 2 == 1) {
puts("No");
return 0;
}
}
if (mx >= 6 || cnt >= 3) {
puts("Yes");
return 0;
}
if (mx == 2 || cnt < 2) {
puts("No");
return 0;
}
int x = -1, y;
for (int i = 0; i < n; i++) {
if (g[i].size() == 4) {
y = i;
if (x == -1) {
swap(x, y);
}
}
}
int ok = 4;
function<void(int, int)> dfs = [&](int v, int p) {
for (int to : g[v]) {
if (to == p)
continue;
if (to == y) {
ok--;
break;
}
if (to == x) {
break;
}
dfs(to, v);
}
};
dfs(x, -1);
if (ok) {
puts("Yes");
} else {
puts("No");
}
return 0;
} | insert | 60 | 60 | 60 | 63 | 0 | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL LINF = 1e18;
const LL MOD = 998244353;
class UnionFind {
public:
vector<int> data;
UnionFind(int size) : data(size, -1) {}
bool connect(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (data[y] < data[x])
swap(x, y);
data[x] += data[y];
data[y] = x;
}
return x != y;
}
bool same(int x, int y) { return root(x) == root(y); }
int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
int size(int x) { return -data[root(x)]; }
};
int main() {
int N, M;
cin >> N >> M;
vector<int> zisuu(N);
vector<pair<int, int>> E;
int cnt1 = 0;
int cnt2 = 0;
for (int a = 0; a < M; a++) {
int b, c;
cin >> b >> c;
b--, c--;
E.push_back({b, c});
zisuu.at(b)++;
zisuu.at(c)++;
}
bool r = true;
for (int a = 0; a < N; a++) {
if (zisuu.at(a) % 2 == 1)
r = false;
if (zisuu.at(a) >= 6)
cnt1++;
if (zisuu.at(a) == 4)
cnt2++;
}
if (r) {
if (cnt1 || cnt2 >= 3) {
cout << "Yes" << endl;
} else if (cnt2 == 2) {
vector<int> flag;
for (int a = 0; a < N; a++) {
if (zisuu.at(a) == 4) {
flag.push_back(a);
}
}
for (auto x : flag) {
UnionFind Uni(N);
for (int a = 0; a < E.size(); a++) {
if (x != E.at(a).first && x != E.at(a).second) {
Uni.connect(E.at(a).first, E.at(a).second);
}
}
if (Uni.size(0) == N - 1) {
cout << "No" << endl;
return 0;
}
}
abort();
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} else {
cout << "No" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL LINF = 1e18;
const LL MOD = 998244353;
class UnionFind {
public:
vector<int> data;
UnionFind(int size) : data(size, -1) {}
bool connect(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (data[y] < data[x])
swap(x, y);
data[x] += data[y];
data[y] = x;
}
return x != y;
}
bool same(int x, int y) { return root(x) == root(y); }
int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
int size(int x) { return -data[root(x)]; }
};
int main() {
int N, M;
cin >> N >> M;
vector<int> zisuu(N);
vector<pair<int, int>> E;
int cnt1 = 0;
int cnt2 = 0;
for (int a = 0; a < M; a++) {
int b, c;
cin >> b >> c;
b--, c--;
E.push_back({b, c});
zisuu.at(b)++;
zisuu.at(c)++;
}
bool r = true;
for (int a = 0; a < N; a++) {
if (zisuu.at(a) % 2 == 1)
r = false;
if (zisuu.at(a) >= 6)
cnt1++;
if (zisuu.at(a) == 4)
cnt2++;
}
if (r) {
if (cnt1 || cnt2 >= 3) {
cout << "Yes" << endl;
} else if (cnt2 == 2) {
vector<int> flag;
for (int a = 0; a < N; a++) {
if (zisuu.at(a) == 4) {
flag.push_back(a);
}
}
for (auto x : flag) {
UnionFind Uni(N);
for (int a = 0; a < E.size(); a++) {
if (x != E.at(a).first && x != E.at(a).second) {
Uni.connect(E.at(a).first, E.at(a).second);
}
}
if (Uni.size(0) == N - 1) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} else {
cout << "No" << endl;
}
}
| delete | 74 | 75 | 74 | 74 | 0 | |
p03091 | C++ | Runtime Error | #include <bits/stdc++.h>
const int N = 100005;
int n, m, deg[N], head[N], tot;
struct edge {
int to, nxt;
} e[N << 1];
void link(int x, int y) {
e[++tot] = {y, head[x]}, head[x] = tot;
e[++tot] = {x, head[y]}, head[y] = tot;
}
int dfs(int x, int start, int target, int f = 0) {
if (x == target)
return 1;
int ret = 0;
for (int i = head[x]; i; i = e[i].nxt)
if (e[i].to != start && e[i].to != f)
ret += dfs(e[i].to, start, target);
return ret;
}
int main() {
std::ios::sync_with_stdio(0), std::cin.tie(0);
std::cin >> n >> m;
for (int i = 1, x, y; i <= m; ++i)
std::cin >> x >> y, ++deg[x], ++deg[y], link(x, y);
// partition Euler circuit into three circuits
for (int i = 1; i <= n; ++i)
if (deg[i] & 1) // no Euler circuit
return std::cout << "No" << '\n', 0;
for (int i = 1; i <= n; ++i)
if (deg[i] >= 6) { // AAA => A + A + A
return std::cout << "Yes" << '\n', 0;
}
int cnt = 0;
for (int i = 1; i <= n; ++i)
cnt += deg[i] == 4;
if (cnt >= 3) {
// ABCABC, ABCACB, ABCBAC => AB + BC + CA
// ABCBCA => A + ABC + BC
// ABCCAB => AB + ABC + C
// ABCCBA => A + ABCB + C
return std::cout << "Yes" << '\n', 0;
} else if (cnt <= 1) {
// AA : no solution
return std::cout << "No" << '\n', 0;
}
// ABBA => A + AB + B
// ABAB : no solution
int L = 0, R = 0;
for (int i = 1; i <= n; ++i)
if (deg[i] == 4)
(L ? R : L) = i;
std::cout << (dfs(L, L, R) == 2 ? "Yes\n" : "No\n");
return 0;
} | #include <bits/stdc++.h>
const int N = 100005;
int n, m, deg[N], head[N], tot;
struct edge {
int to, nxt;
} e[N << 1];
void link(int x, int y) {
e[++tot] = {y, head[x]}, head[x] = tot;
e[++tot] = {x, head[y]}, head[y] = tot;
}
int dfs(int x, int start, int target, int f = 0) {
if (x == target)
return 1;
int ret = 0;
for (int i = head[x]; i; i = e[i].nxt)
if (e[i].to != start && e[i].to != f)
ret += dfs(e[i].to, start, target, x);
return ret;
}
int main() {
std::ios::sync_with_stdio(0), std::cin.tie(0);
std::cin >> n >> m;
for (int i = 1, x, y; i <= m; ++i)
std::cin >> x >> y, ++deg[x], ++deg[y], link(x, y);
// partition Euler circuit into three circuits
for (int i = 1; i <= n; ++i)
if (deg[i] & 1) // no Euler circuit
return std::cout << "No" << '\n', 0;
for (int i = 1; i <= n; ++i)
if (deg[i] >= 6) { // AAA => A + A + A
return std::cout << "Yes" << '\n', 0;
}
int cnt = 0;
for (int i = 1; i <= n; ++i)
cnt += deg[i] == 4;
if (cnt >= 3) {
// ABCABC, ABCACB, ABCBAC => AB + BC + CA
// ABCBCA => A + ABC + BC
// ABCCAB => AB + ABC + C
// ABCCBA => A + ABCB + C
return std::cout << "Yes" << '\n', 0;
} else if (cnt <= 1) {
// AA : no solution
return std::cout << "No" << '\n', 0;
}
// ABBA => A + AB + B
// ABAB : no solution
int L = 0, R = 0;
for (int i = 1; i <= n; ++i)
if (deg[i] == 4)
(L ? R : L) = i;
std::cout << (dfs(L, L, R) == 2 ? "Yes\n" : "No\n");
return 0;
} | replace | 19 | 20 | 19 | 20 | 0 | |
p03092 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
ll dp[1005][1005];
// 数字iまで見たときに、iを絶対位置j番目に置くような場合の数
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
ll n, a, b;
cin >> n >> a >> b;
ll p[n];
map<ll, int> pos;
for (int i = 0; i < n; i++) {
cin >> p[i];
pos[p[i]] = i;
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < n; j++) {
dp[i][j] = dp[i - 1][j];
if (j < pos[i])
dp[i][j] += b;
if (j > pos[i])
dp[i][j] += a;
if (j)
dp[i][j] = min(dp[i][j], dp[i][j - 1]);
}
}
cout << dp[n][n - 1] << "\n";
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
ll dp[5005][5005];
// 数字iまで見たときに、iを絶対位置j番目に置くような場合の数
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
ll n, a, b;
cin >> n >> a >> b;
ll p[n];
map<ll, int> pos;
for (int i = 0; i < n; i++) {
cin >> p[i];
pos[p[i]] = i;
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < n; j++) {
dp[i][j] = dp[i - 1][j];
if (j < pos[i])
dp[i][j] += b;
if (j > pos[i])
dp[i][j] += a;
if (j)
dp[i][j] = min(dp[i][j], dp[i][j - 1]);
}
}
cout << dp[n][n - 1] << "\n";
return 0;
} | replace | 17 | 18 | 17 | 18 | 0 | |
p03092 | C++ | Runtime Error | // khodaya khodet komak kon
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;
const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 3e3 + 10;
const ll INF = 1e18;
const ll LOG = 20;
ll Place[N][N], a[N], n, A, B; /*Place[i][j] = where is the maximum number in
first i element and max <= j*/
ll dp[N][N]; /*dp[i][j] = int the first i element answer for the numbers who ai
<= j*/
ll inv[N][N];
int main() {
IOS;
cin >> n >> A >> B;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
inv[i][j] = inv[i][j - 1];
if (a[i] > a[j])
inv[i][j]++;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
Place[i][j] = Place[i - 1][j];
if (a[i] <= j) {
if (a[i] > a[Place[i - 1][j]]) {
Place[i][j] = i;
}
}
// cout << i << ' ' << j << ' ' << Place[i][j] << '\n';
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (Place[i][j] == 0)
continue;
dp[i][j] = min(dp[i][a[Place[i][j]] - 1] + A,
dp[Place[i][j] - 1][j] + inv[Place[i][j]][i] * B);
}
}
cout << dp[n][n];
return 0;
}
/*
,---, ___ ,--,
' .' \ ,--.'|_ ,--.'| ,--,
/ ; '. | | :,' | | : ,--.'|
,---. ,---, : : \ : : ' : : : ' .--.--. | |,
' ,'\ ,-+-. / | : | /\ \ .;__,' / ,--.--. | ' | ,--.--.
/ / ' `--'_ / / | ,--.'|' | | : ' ;. : | | | / \ ' | |
/ \ | : /`./ ,' ,'| . ; ,. :| | ,"' | | | ;/ \ \:__,'| :
.--. .-. || | : .--. .-. | | : ;_ ' | | ' | |: :| | / | | ' :
| \ \ ,' ' : |__ \__\/: . .' : |__ \__\/: . . \ \ `. | | : ' |
.; :| | | | | | | ' '--' | | '.'| ," .--.; || | '.'| ," .--.; |
`----. \' : |_| : || | | |/ | : : ; : ;/ / ,. |;
: ;/ / ,. | / /`--' /| | '.'\ \ / | | |--' | | ,' |
, /; : .' \ , /; : .' \'--'. / ; : ;`----' | |/
`--'' ---`-' | , .-./---`-' | , .-./ `--'---' | , /
'---'
`--`---' `--`---' ---`-'
*/
| // khodaya khodet komak kon
#include <bits/stdc++.h>
#define pb push_back
#define ers erase
#define ins insert
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl
#define kill(x) return cout << x, 0;
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vpl;
const ld Pi = 3.14159265359;
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 5e3 + 10;
const ll INF = 1e18;
const ll LOG = 20;
ll Place[N][N], a[N], n, A, B; /*Place[i][j] = where is the maximum number in
first i element and max <= j*/
ll dp[N][N]; /*dp[i][j] = int the first i element answer for the numbers who ai
<= j*/
ll inv[N][N];
int main() {
IOS;
cin >> n >> A >> B;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
inv[i][j] = inv[i][j - 1];
if (a[i] > a[j])
inv[i][j]++;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
Place[i][j] = Place[i - 1][j];
if (a[i] <= j) {
if (a[i] > a[Place[i - 1][j]]) {
Place[i][j] = i;
}
}
// cout << i << ' ' << j << ' ' << Place[i][j] << '\n';
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (Place[i][j] == 0)
continue;
dp[i][j] = min(dp[i][a[Place[i][j]] - 1] + A,
dp[Place[i][j] - 1][j] + inv[Place[i][j]][i] * B);
}
}
cout << dp[n][n];
return 0;
}
/*
,---, ___ ,--,
' .' \ ,--.'|_ ,--.'| ,--,
/ ; '. | | :,' | | : ,--.'|
,---. ,---, : : \ : : ' : : : ' .--.--. | |,
' ,'\ ,-+-. / | : | /\ \ .;__,' / ,--.--. | ' | ,--.--.
/ / ' `--'_ / / | ,--.'|' | | : ' ;. : | | | / \ ' | |
/ \ | : /`./ ,' ,'| . ; ,. :| | ,"' | | | ;/ \ \:__,'| :
.--. .-. || | : .--. .-. | | : ;_ ' | | ' | |: :| | / | | ' :
| \ \ ,' ' : |__ \__\/: . .' : |__ \__\/: . . \ \ `. | | : ' |
.; :| | | | | | | ' '--' | | '.'| ," .--.; || | '.'| ," .--.; |
`----. \' : |_| : || | | |/ | : : ; : ;/ / ,. |;
: ;/ / ,. | / /`--' /| | '.'\ \ / | | |--' | | ,' |
, /; : .' \ , /; : .' \'--'. / ; : ;`----' | |/
`--'' ---`-' | , .-./---`-' | , .-./ `--'---' | , /
'---'
`--`---' `--`---' ---`-'
*/
| replace | 26 | 27 | 26 | 27 | -11 | |
p03092 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
ll n, d[5000][5000], A, B;
int main() {
cin >> n >> A >> B;
for (ll i = 1; i <= n; i++) {
ll a;
scanf("%lld", &a);
for (ll j = 0; j <= n; j++) {
if (j < a)
d[i][j] = d[i - 1][j] + A;
else if (j == a)
d[i][j] = d[i - 1][j];
else
d[i][j] = d[i - 1][j] + B;
if (j)
d[i][j] = min(d[i][j], d[i][j - 1]);
}
}
cout << d[n][n];
} | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
ll n, d[5001][5001], A, B;
int main() {
cin >> n >> A >> B;
for (ll i = 1; i <= n; i++) {
ll a;
scanf("%lld", &a);
for (ll j = 0; j <= n; j++) {
if (j < a)
d[i][j] = d[i - 1][j] + A;
else if (j == a)
d[i][j] = d[i - 1][j];
else
d[i][j] = d[i - 1][j] + B;
if (j)
d[i][j] = min(d[i][j], d[i][j - 1]);
}
}
cout << d[n][n];
} | replace | 15 | 16 | 15 | 16 | -11 | |
p03092 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e3 + 10;
int n, A, B, p[N];
ll dp[N];
int main() {
scanf("%d %d %d", &n, &A, &B);
for (int i = 1; i <= n; i++) {
scanf("%d", &p[i]);
}
p[++n] = n;
for (int i = 1; i <= n; i++) {
dp[i] = (ll)1e18;
ll tmp = 0;
for (int j = i - 1; j >= 0; j--) {
if (p[j] < p[i]) {
dp[i] = min(dp[i], dp[j] + tmp);
tmp += B;
} else {
tmp += A;
}
}
}
printf("%lld\n", dp[n]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e3 + 10;
int n, A, B, p[N];
ll dp[N];
int main() {
scanf("%d %d %d", &n, &A, &B);
for (int i = 1; i <= n; i++) {
scanf("%d", &p[i]);
}
p[++n] = n;
for (int i = 1; i <= n; i++) {
dp[i] = (ll)1e18;
ll tmp = 0;
for (int j = i - 1; j >= 0; j--) {
if (p[j] < p[i]) {
dp[i] = min(dp[i], dp[j] + tmp);
tmp += B;
} else {
tmp += A;
}
}
}
printf("%lld\n", dp[n]);
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03092 | C++ | Runtime Error | #include <cstdio>
#include <iostream>
#define MN 5010
typedef long long ll;
ll Min[MN], lazy[MN];
void add(int x, ll v) {
lazy[x] += v;
Min[x] += v;
}
void pushdown(int x) {
if (lazy[x]) {
add(x << 1, lazy[x]);
add(x << 1 | 1, lazy[x]);
lazy[x] = 0;
}
}
void modify(int x, int l, int r, int L, int R, ll v, int t) {
if (L > R)
return;
if (l == L && r == R) {
if (t == 0)
add(x, v);
else
Min[x] = v;
return;
}
pushdown(x);
int mid = l + r >> 1;
if (R <= mid)
modify(x << 1, l, mid, L, R, v, t);
else if (L > mid)
modify(x << 1 | 1, mid + 1, r, L, R, v, t);
else
modify(x << 1, l, mid, L, mid, v, t),
modify(x << 1 | 1, mid + 1, r, mid + 1, R, v, t);
Min[x] = std::min(Min[x << 1], Min[x << 1 | 1]);
}
ll query(int x, int l, int r, int L, int R) {
if (l == L && r == R)
return Min[x];
pushdown(x);
int mid = l + r >> 1;
if (R <= mid)
return query(x << 1, l, mid, L, R);
else if (L > mid)
return query(x << 1 | 1, mid + 1, r, L, R);
else
return std::min(query(x << 1, l, mid, L, mid),
query(x << 1 | 1, mid + 1, r, mid + 1, R));
}
int main() {
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
modify(1, 0, n, 0, n, 1e18, 0);
modify(1, 0, n, 0, 0, 0, 1);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
modify(1, 0, n, x, x, query(1, 0, n, 0, x), 1);
modify(1, 0, n, 0, x - 1, a, 0);
modify(1, 0, n, x + 1, n, b, 0);
}
printf("%lld\n", query(1, 0, n, 0, n));
} | #include <cstdio>
#include <iostream>
#define MN 20010
typedef long long ll;
ll Min[MN], lazy[MN];
void add(int x, ll v) {
lazy[x] += v;
Min[x] += v;
}
void pushdown(int x) {
if (lazy[x]) {
add(x << 1, lazy[x]);
add(x << 1 | 1, lazy[x]);
lazy[x] = 0;
}
}
void modify(int x, int l, int r, int L, int R, ll v, int t) {
if (L > R)
return;
if (l == L && r == R) {
if (t == 0)
add(x, v);
else
Min[x] = v;
return;
}
pushdown(x);
int mid = l + r >> 1;
if (R <= mid)
modify(x << 1, l, mid, L, R, v, t);
else if (L > mid)
modify(x << 1 | 1, mid + 1, r, L, R, v, t);
else
modify(x << 1, l, mid, L, mid, v, t),
modify(x << 1 | 1, mid + 1, r, mid + 1, R, v, t);
Min[x] = std::min(Min[x << 1], Min[x << 1 | 1]);
}
ll query(int x, int l, int r, int L, int R) {
if (l == L && r == R)
return Min[x];
pushdown(x);
int mid = l + r >> 1;
if (R <= mid)
return query(x << 1, l, mid, L, R);
else if (L > mid)
return query(x << 1 | 1, mid + 1, r, L, R);
else
return std::min(query(x << 1, l, mid, L, mid),
query(x << 1 | 1, mid + 1, r, mid + 1, R));
}
int main() {
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
modify(1, 0, n, 0, n, 1e18, 0);
modify(1, 0, n, 0, 0, 0, 1);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
modify(1, 0, n, x, x, query(1, 0, n, 0, x), 1);
modify(1, 0, n, 0, x - 1, a, 0);
modify(1, 0, n, x + 1, n, b, 0);
}
printf("%lld\n", query(1, 0, n, 0, n));
} | replace | 2 | 3 | 2 | 3 | 0 | |
p03092 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll A, B;
int n;
const int N = 2010;
int a[N], pos[N];
ll f[N][N];
int main() {
scanf("%d%lld%lld", &n, &A, &B);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
pos[a[i]] = i;
}
for (int i = 0; i <= n; i++)
f[0][i] = B * i;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n; j++) {
f[i][j] = f[i - 1][j];
if (j)
f[i][j] = min(f[i][j], f[i][j - 1] + (pos[j] > i ? B : A));
if (j && pos[j] == i)
f[i][j] = min(f[i][j], f[i - 1][j - 1]);
// cout<<i<<" "<<j<<" :: "<<f[i][j]<<endl;
}
}
cout << f[n][n] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll A, B;
int n;
const int N = 5010;
int a[N], pos[N];
ll f[N][N];
int main() {
scanf("%d%lld%lld", &n, &A, &B);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
pos[a[i]] = i;
}
for (int i = 0; i <= n; i++)
f[0][i] = B * i;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n; j++) {
f[i][j] = f[i - 1][j];
if (j)
f[i][j] = min(f[i][j], f[i][j - 1] + (pos[j] > i ? B : A));
if (j && pos[j] == i)
f[i][j] = min(f[i][j], f[i - 1][j - 1]);
// cout<<i<<" "<<j<<" :: "<<f[i][j]<<endl;
}
}
cout << f[n][n] << endl;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p03092 | Python | Time Limit Exceeded | from bisect import bisect
n, a, b = map(int, input().split())
ppp = map(int, input().split())
qqq = [0] * n
for i, p in enumerate(ppp, start=1):
qqq[p - 1] = i
dp = [(0, 0)]
for i in qqq:
s = bisect(dp, (i,))
ndp = [(j, cost + b) for j, cost in dp[:s]]
stay_cost = dp[s - 1][1]
ndp.append((i, stay_cost))
ndp.extend((j, cost + a) for j, cost in dp[s:] if stay_cost > cost + a)
dp = ndp
print(dp[-1][1])
| from bisect import bisect
n, a, b = map(int, input().split())
ppp = map(int, input().split())
qqq = [0] * n
for i, p in enumerate(ppp, start=1):
qqq[p - 1] = i
dp = [(0, 0)]
for i in qqq:
s = bisect(dp, (i,))
ndp = [(j, cost + b) for j, cost in dp[:s]]
stay_cost = dp[s - 1][1]
ndp.append((i, stay_cost))
remain = iter(dp[s:])
for j, cost in remain:
if stay_cost > cost + a:
ndp.append((j, cost + a))
break
ndp.extend((j, cost + a) for j, cost in remain)
dp = ndp
print(dp[-1][1])
| replace | 14 | 15 | 14 | 20 | TLE | |
p03092 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <random>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
// #define int ll
// #define int __int128
// #define ll __int128
// typedef __int128 long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for (int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;
#ifdef MAX_HOME
#define cerr cout
#else
#define cerr \
if (false) \
cerr
#endif
const double PI = 2 * acos(0.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
template <class T0, class T1>
inline ostream &operator<<(ostream &out, pair<T0, T1> &a) {
return out << "{" << a.first << ", " << a.second << "}";
}
template <class T0, class T1, class T2>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) {
return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
<< "}";
}
template <class T0, class T1, class T2, class T3>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) {
return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
<< ", " << get<3>(a) << "}";
}
template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) {
out << "[";
fori(i, a.size()) out << a[i]
<< vector<string>{", ", "] "}[i + 1 == a.size()];
return out;
}
void smain();
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef MAX_HOME
freopen("input.txt", "r", stdin);
clock_t start = clock();
#else
freopen("disconnected.in", "r", stdin);
freopen("disconnected.out", "w", stdout);
#endif
cout << setprecision(12) << fixed;
smain();
#ifdef MAX_HOME
cout << "\n\n\n\nTOTAL EXECUTION TIME: "
<< float(clock() - start) / CLOCKS_PER_SEC << endl;
#endif
}
const int N = 5009;
const ll oo = 1e18;
ll a, b;
int p[N];
int n;
ll dp[N][2];
void smain() {
cin >> n >> a >> b;
fori(i, n) { cin >> p[i + 1]; }
int pr = 0, cr = 1;
fori(i, N) fori(j, 2) dp[i][j] = oo;
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int mx = 0; mx <= n; ++mx) {
if (dp[mx][pr] < oo) {
if (mx > p[i]) {
inmin(dp[mx][cr], dp[mx][pr] + b);
} else {
inmin(dp[p[i]][cr], dp[mx][pr]);
inmin(dp[mx][cr], dp[mx][pr] + a);
}
}
dp[mx][pr] = oo;
}
swap(pr, cr);
}
ll ans = oo;
fori(mx, n + 1) { inmin(ans, dp[mx][pr]); }
cout << ans;
} | #include <bits/stdc++.h>
#include <random>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
// #define int ll
// #define int __int128
// #define ll __int128
// typedef __int128 long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for (int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;
#ifdef MAX_HOME
#define cerr cout
#else
#define cerr \
if (false) \
cerr
#endif
const double PI = 2 * acos(0.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
template <class T0, class T1>
inline ostream &operator<<(ostream &out, pair<T0, T1> &a) {
return out << "{" << a.first << ", " << a.second << "}";
}
template <class T0, class T1, class T2>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) {
return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
<< "}";
}
template <class T0, class T1, class T2, class T3>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) {
return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
<< ", " << get<3>(a) << "}";
}
template <class T> inline ostream &operator<<(ostream &out, vector<T> &a) {
out << "[";
fori(i, a.size()) out << a[i]
<< vector<string>{", ", "] "}[i + 1 == a.size()];
return out;
}
void smain();
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef MAX_HOME
freopen("input.txt", "r", stdin);
clock_t start = clock();
#endif
cout << setprecision(12) << fixed;
smain();
#ifdef MAX_HOME
cout << "\n\n\n\nTOTAL EXECUTION TIME: "
<< float(clock() - start) / CLOCKS_PER_SEC << endl;
#endif
}
const int N = 5009;
const ll oo = 1e18;
ll a, b;
int p[N];
int n;
ll dp[N][2];
void smain() {
cin >> n >> a >> b;
fori(i, n) { cin >> p[i + 1]; }
int pr = 0, cr = 1;
fori(i, N) fori(j, 2) dp[i][j] = oo;
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int mx = 0; mx <= n; ++mx) {
if (dp[mx][pr] < oo) {
if (mx > p[i]) {
inmin(dp[mx][cr], dp[mx][pr] + b);
} else {
inmin(dp[p[i]][cr], dp[mx][pr]);
inmin(dp[mx][cr], dp[mx][pr] + a);
}
}
dp[mx][pr] = oo;
}
swap(pr, cr);
}
ll ans = oo;
fori(mx, n + 1) { inmin(ans, dp[mx][pr]); }
cout << ans;
} | delete | 91 | 94 | 91 | 91 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.