problem_id
stringlengths 6
6
| buggy_code
stringlengths 8
526k
| fixed_code
stringlengths 12
526k
| labels
listlengths 0
15
⌀ | buggy_submission_id
int64 1
1.54M
| fixed_submission_id
int64 2
1.54M
| user_id
stringlengths 10
10
| language
stringclasses 8
values |
|---|---|---|---|---|---|---|---|
p02924
|
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
cout << (n * (n - 1)) / 2 << endl;
}
|
#include <iostream>
using namespace std;
int main() {
long long n;
cin >> n;
cout << (n * (n - 1)) / 2 << endl;
}
|
[
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 728,913
| 728,914
|
u231230182
|
cpp
|
p02924
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define db double
#define ui unsigned int
#define ll long long
#define ull unsiged ll
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define boots \
ios::sync_with_stdio(0); \
cin.tie(0)
#define pb push_back
#define pp pop_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mod 1000000007
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define inf 0x3f3f3f3f
#define lnf LLONG_MAX
#define mii map<int, int>
#define mll map<ll, ll>
#define mil map<int, ll>
#define umii unordered_map<char, int>
#define umll unordered_map<ll, ll>
#define umcc unordered_map<char, char>
#define si(n) scanf("%d", &n)
#define sl(n) scanf("%lld", &n)
#define pf(n) printf("%lld\n", n)
#define sz size()
using namespace std;
const db pi = 3.1415926535898;
const int MX = 5e6 + 7;
const int esp = 1e-6;
ll INV2, INV6;
ll modulo(ll num, ll MOD = mod) { return ((num % MOD) + MOD) % MOD; }
ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); }
unordered_map<ui, ll> mp1, mp;
int p[MX];
int sum[MX];
char s[MX / 10];
vector<int> pri;
vector<bool> isp(MX, true);
int k;
ll qpow(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1)
ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
ll INV(ll n) { return qpow(n, mod - 2); }
ll get_sum(ll d) {
if (d == 1)
return k - 1;
return d * d % mod * (qpow(d, k) * INV(d) - 1) % mod * INV(d - 1) % mod;
}
ll get_sum2(int n) {
return n * (n + 1) % mod * (2 * n + 1) % mod * INV6 % mod;
}
int main() {
boots;
int n;
cin >> n;
cout << (1 + n) * n / 2 - n << endl;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define db double
#define ui unsigned int
#define ll long long
#define ull unsiged ll
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define boots \
ios::sync_with_stdio(0); \
cin.tie(0)
#define pb push_back
#define pp pop_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mod 1000000007
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define inf 0x3f3f3f3f
#define lnf LLONG_MAX
#define mii map<int, int>
#define mll map<ll, ll>
#define mil map<int, ll>
#define umii unordered_map<char, int>
#define umll unordered_map<ll, ll>
#define umcc unordered_map<char, char>
#define si(n) scanf("%d", &n)
#define sl(n) scanf("%lld", &n)
#define pf(n) printf("%lld\n", n)
#define sz size()
using namespace std;
const db pi = 3.1415926535898;
const int MX = 5e6 + 7;
const int esp = 1e-6;
ll INV2, INV6;
ll modulo(ll num, ll MOD = mod) { return ((num % MOD) + MOD) % MOD; }
ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); }
unordered_map<ui, ll> mp1, mp;
int p[MX];
int sum[MX];
char s[MX / 10];
vector<int> pri;
vector<bool> isp(MX, true);
int k;
ll qpow(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1)
ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
ll INV(ll n) { return qpow(n, mod - 2); }
ll get_sum(ll d) {
if (d == 1)
return k - 1;
return d * d % mod * (qpow(d, k) * INV(d) - 1) % mod * INV(d - 1) % mod;
}
ll get_sum2(int n) {
return n * (n + 1) % mod * (2 * n + 1) % mod * INV6 % mod;
}
int main() {
boots;
ll n;
cin >> n;
cout << (1 + n) * n / 2 - n << endl;
}
|
[
"variable_declaration.type.change"
] | 728,915
| 728,916
|
u393604857
|
cpp
|
p02924
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
cout << n * (n - 1) / 2 << endl;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
long long n;
cin >> n;
cout << n * (n - 1) / 2 << endl;
}
|
[
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 728,917
| 728,918
|
u244203620
|
cpp
|
p02924
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << n * (n - 1) / 2 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
cout << n * (n - 1) / 2 << endl;
return 0;
}
|
[
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 728,925
| 728,926
|
u788717734
|
cpp
|
p02924
|
#include <bits/stdc++.h>
using namespace std;
constexpr int64_t mod = 1e9 + 7;
int main() {
int n;
cin >> n;
if (n == 1) {
cout << 0;
return 0;
}
cout << (n - 1) * n / 2;
}
|
#include <bits/stdc++.h>
using namespace std;
constexpr int64_t mod = 1e9 + 7;
int main() {
int64_t n;
cin >> n;
if (n == 1) {
cout << 0;
return 0;
}
cout << (n - 1) * n / 2;
}
|
[
"variable_declaration.type.primitive.change"
] | 728,927
| 728,928
|
u849073847
|
cpp
|
p02924
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF(1 << 30);
int main() {
ll N;
cin >> N;
if (N == 1) {
cout << 0 << endl;
return 0;
} else if (N == 2) {
cout << 1 << endl;
return 0;
}
ll ans;
if ((N - 2) % 2 == 0) {
ans = ((N - 2) / 2) * (N + 1);
} else {
ans = ((N + 1) / 2) * (N - 2) + 1;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF(1 << 30);
int main() {
ll N;
cin >> N;
if (N == 1) {
cout << 0 << endl;
return 0;
} else if (N == 2) {
cout << 1 << endl;
return 0;
}
ll ans;
if ((N - 2) % 2 == 0) {
ans = ((N - 2) / 2) * (N + 1) + 1;
// ans = ((N-2)/2) * (N+1);
} else {
ans = ((N + 1) / 2) * (N - 2) + 1;
}
cout << ans << endl;
return 0;
}
|
[
"assignment.change"
] | 728,931
| 728,932
|
u730946954
|
cpp
|
p02924
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans;
if (n == 1)
ans = 0;
else {
ans = (n - 1) * (n) / 2;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long ans;
if (n == 1)
ans = 0;
else {
ans = (n - 1) * (n) / 2;
}
cout << ans << endl;
}
|
[
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 728,933
| 728,934
|
u756514276
|
cpp
|
p02924
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
n--;
cout << ((1 + n) * n) / 2;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long int n;
cin >> n;
n--;
cout << ((1 + n) * n) / 2;
}
|
[
"variable_declaration.type.widen.change"
] | 728,935
| 728,936
|
u016726316
|
cpp
|
p02924
|
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX / 2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions
#endif
int main_D() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
int ans = N * (N - 1) / 2;
cout << ans << endl;
return 0;
}
|
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX / 2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions
#endif
int main_D() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
ll ans = N * (N - 1) / 2;
cout << ans << endl;
return 0;
}
|
[
"variable_declaration.type.change"
] | 728,937
| 728,938
|
u404244809
|
cpp
|
p02924
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
int n;
cin >> n;
cout << (n * (n - 1)) / 2 << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
long long n;
cin >> n;
cout << (n * (n - 1)) / 2 << "\n";
return 0;
}
|
[
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 728,939
| 728,940
|
u261237205
|
cpp
|
p02924
|
//#define NDEBUG
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <mutex>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <thread>
#include <vector>
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define ALL(t) (t).begin(), (t).end()
#define FILL(a, c) fill(a, a + sizeof(a) / sizeof(*a), c)
#define FILL2D(A, c) fill(A[0], A[0] + sizeof(A) / sizeof(**A), c)
#define FILL3D(A, c) fill(A[0][0], A[0][0] + sizeof(A) / sizeof(***A), c)
#define REP(i, m) for (int i = 0; i < (m); ++i)
// closed interval, inverse repeat
#define CIREP(i, start, fin) for (int i = (start); i >= (fin); i--)
#define CREP(i, start, fin) for (int i = (start); i <= (fin); i++)
#define RNG(i, start, fin) for (int i = (start); i < (fin); i++)
#define IN(a, x, b) (a <= x && x < b)
#define PB push_back
#define SZ(x) (int)(x).size()
using namespace std;
using LL = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<LL, LL>;
using VI = vector<int>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VVI = vector<VI>;
const LL LINF = 1001002003004005006ll;
/*
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,SZ(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;REP(i,SZ(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const vector<T>&v)
{if(SZ(v))o<<join(v);return o;}
*/
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;
}
/*
constant values
*/
// const int dx[] = {1,0,-1,0};
// const int dy[] = {0,1,0,-1};
// const int MX = 31001;
// const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9
// Main program
void solve() {
int N;
cin >> N;
int ans;
ans = N * (N - 1) / 2;
cout << ans << endl;
return;
}
// ----------------------------------------------
int main() {
int T = 1;
for (int i = 0; i < T; ++i) {
solve();
}
return 0;
}
|
//#define NDEBUG
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <mutex>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <thread>
#include <vector>
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define ALL(t) (t).begin(), (t).end()
#define FILL(a, c) fill(a, a + sizeof(a) / sizeof(*a), c)
#define FILL2D(A, c) fill(A[0], A[0] + sizeof(A) / sizeof(**A), c)
#define FILL3D(A, c) fill(A[0][0], A[0][0] + sizeof(A) / sizeof(***A), c)
#define REP(i, m) for (int i = 0; i < (m); ++i)
// closed interval, inverse repeat
#define CIREP(i, start, fin) for (int i = (start); i >= (fin); i--)
#define CREP(i, start, fin) for (int i = (start); i <= (fin); i++)
#define RNG(i, start, fin) for (int i = (start); i < (fin); i++)
#define IN(a, x, b) (a <= x && x < b)
#define PB push_back
#define SZ(x) (int)(x).size()
using namespace std;
using LL = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<LL, LL>;
using VI = vector<int>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VVI = vector<VI>;
const LL LINF = 1001002003004005006ll;
/*
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,SZ(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;REP(i,SZ(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const vector<T>&v)
{if(SZ(v))o<<join(v);return o;}
*/
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;
}
/*
constant values
*/
// const int dx[] = {1,0,-1,0};
// const int dy[] = {0,1,0,-1};
// const int MX = 31001;
// const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9
// Main program
void solve() {
LL N;
cin >> N;
LL ans;
ans = N * (N - 1) / 2;
cout << ans << endl;
return;
}
// ----------------------------------------------
int main() {
int T = 1;
for (int i = 0; i < T; ++i) {
solve();
}
return 0;
}
|
[
"variable_declaration.type.change"
] | 728,943
| 728,944
|
u495072453
|
cpp
|
p02924
|
#include <bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define mp make_pair
#define pii pair<int, int>
#define pb push_back
#define r1 rt << 1
#define r2 rt << 1 | 1
#define ri register int
#define rep(i, a, b) for (ri i = (a); i <= (b); ++i)
#define rep2(i, a, b, c) for (ri i = (a); i <= (b); i += (c))
#define REP(i, a, b) for (ri i = (a); i >= (b); --i)
#define REP2(i, a, b, c) for (ri i = (a); i >= (b); i -= (c))
using namespace std;
inline ll read() {
ll 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 ^ '0'), c = getchar();
return x * f;
}
inline void write(ll x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
int main() {
ll n;
cin >> n;
ll x = n * ((n - 1) / 2);
cout << x << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define mp make_pair
#define pii pair<int, int>
#define pb push_back
#define r1 rt << 1
#define r2 rt << 1 | 1
#define ri register int
#define rep(i, a, b) for (ri i = (a); i <= (b); ++i)
#define rep2(i, a, b, c) for (ri i = (a); i <= (b); i += (c))
#define REP(i, a, b) for (ri i = (a); i >= (b); --i)
#define REP2(i, a, b, c) for (ri i = (a); i >= (b); i -= (c))
using namespace std;
inline ll read() {
ll 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 ^ '0'), c = getchar();
return x * f;
}
inline void write(ll x) {
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
int main() {
ll n;
cin >> n;
ll x = n * (n - 1) / 2;
cout << x << endl;
return 0;
}
|
[] | 728,945
| 728,946
|
u329585799
|
cpp
|
p02924
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
long long ans = 0;
ans = (N - 1) * N / 2;
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
cin >> N;
long long ans = 0;
ans = (N - 1) * N / 2;
cout << ans << endl;
}
|
[
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 728,949
| 728,950
|
u032068406
|
cpp
|
p02924
|
#include "bits/stdc++.h"
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))
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;
}
const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;
const long long kMod = 1000000007;
const long kMAX = 1000000000;
using namespace std;
using ll = long long;
inline int readInt() {
char c = getchar();
while (!isdigit(c) && c != '-')
c = getchar();
int sigma = 1;
if (c == '-') {
sigma = -1;
c = getchar();
}
int x = 0;
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
return x * sigma;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
string s;
ll ans;
int n, m;
vector<ll> a, b;
cin >> n;
ans = n * (n - 1) / 2;
cout << ans << endl;
}
|
#include "bits/stdc++.h"
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))
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;
}
const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;
const long long kMod = 1000000007;
const long kMAX = 1000000000;
using namespace std;
using ll = long long;
inline int readInt() {
char c = getchar();
while (!isdigit(c) && c != '-')
c = getchar();
int sigma = 1;
if (c == '-') {
sigma = -1;
c = getchar();
}
int x = 0;
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
return x * sigma;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
string s;
ll ans;
ll n, m;
vector<ll> a, b;
cin >> n;
ans = n * (n - 1) / 2;
cout << ans << endl;
}
|
[
"variable_declaration.type.change"
] | 728,953
| 728,954
|
u449221649
|
cpp
|
p02924
|
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int MOD = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int N;
cin >> N;
cout << N * (N - 1) / 2;
}
|
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int MOD = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
long long N;
cin >> N;
cout << N * (N - 1) / 2;
}
|
[
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 728,959
| 728,960
|
u554988565
|
cpp
|
p02924
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
int N;
cin >> N;
int ans = N * (N - 1) / 2;
cout << ans << endl;
}
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
long N;
cin >> N;
long ans = N * (N - 1) / 2;
cout << ans << endl;
}
|
[
"variable_declaration.type.primitive.change"
] | 728,961
| 728,962
|
u521602455
|
cpp
|
p02924
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
int n;
scanf("%d", &n);
ll sum = (1 + n - 1) * (n - 1) / 2;
printf("%lld\n", sum);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
ll n;
scanf("%lld", &n);
ll sum = (1 + n - 1) * (n - 1) / 2;
printf("%lld\n", sum);
return 0;
}
|
[
"variable_declaration.type.change",
"literal.string.change",
"call.arguments.change"
] | 728,965
| 728,966
|
u175426149
|
cpp
|
p02924
|
#include <iostream>
using namespace std;
main() {
int n;
cin >> n;
cout << n * (n - 1) / 2 << endl;
}
|
#include <iostream>
using namespace std;
main() {
long long n;
cin >> n;
cout << n * (n - 1) / 2 << endl;
}
|
[
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 728,967
| 728,968
|
u771099984
|
cpp
|
p02924
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans;
cin >> n;
ans = (n - 1) * n / 2;
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, ans;
cin >> n;
ans = (n - 1) * n / 2;
cout << ans << endl;
}
|
[
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 728,969
| 728,970
|
u082801599
|
cpp
|
p02924
|
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
#define LL long long
int main() {
int n;
cin >> n;
cout << (n * (n - 1)) / 2 << '\n';
return 0;
}
|
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
#define LL long long
int main() {
LL n;
cin >> n;
cout << (n * (n - 1)) / 2 << '\n';
return 0;
}
|
[
"variable_declaration.type.change"
] | 728,975
| 728,976
|
u924429544
|
cpp
|
p02924
|
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;
int main() {
int N;
cin >> N;
cout << N * (N - 1) / 2 << endl;
}
|
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;
int main() {
LLONG N;
cin >> N;
cout << N * (N - 1) / 2 << endl;
}
|
[
"variable_declaration.type.change"
] | 728,977
| 728,978
|
u214685595
|
cpp
|
p02924
|
#include <algorithm>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define rep(i, a, b) for (auto i = (a); i < (b); i++)
#define rrep(i, a, b) for (auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) \
{ \
for (auto x : v) \
cout << x << ' '; \
cout << endl; \
}
#define printn(v, n) \
{ \
for (int _i = 0; _i < n; _i++) \
cout << *(v + _i) << ' '; \
cout << endl; \
}
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
const int MAXN = 1e5 + 20;
int n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
cout << n * (n - 1) / 2 << endl;
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define rep(i, a, b) for (auto i = (a); i < (b); i++)
#define rrep(i, a, b) for (auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) \
{ \
for (auto x : v) \
cout << x << ' '; \
cout << endl; \
}
#define printn(v, n) \
{ \
for (int _i = 0; _i < n; _i++) \
cout << *(v + _i) << ' '; \
cout << endl; \
}
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
const int MAXN = 1e5 + 20;
long long n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
cout << n * (n - 1) / 2 << endl;
return 0;
}
|
[
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 728,979
| 728,980
|
u096453658
|
cpp
|
p02924
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long int
#define rep(i, x, y) for (int i = x; i < y; i++)
#define rel(i, x, y) for (int i = x - 1; i >= y; i--)
#define all(x) x.begin(), x.end()
using namespace std;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
cout << (n - 1) * n / 2 << endl;
}
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long int
#define rep(i, x, y) for (int i = x; i < y; i++)
#define rel(i, x, y) for (int i = x - 1; i >= y; i--)
#define all(x) x.begin(), x.end()
using namespace std;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n;
cin >> n;
cout << (n - 1) * n / 2 << endl;
}
|
[
"variable_declaration.type.change"
] | 728,983
| 728,984
|
u352200121
|
cpp
|
p02924
|
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int N;
int main() {
scanf("%d", &N);
printf("%d\n", N * (N - 1) / 2);
return 0;
}
|
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll N;
int main() {
scanf("%lld", &N);
printf("%lld\n", N * (N - 1) / 2);
return 0;
}
|
[
"variable_declaration.type.change",
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 728,985
| 728,986
|
u810616694
|
cpp
|
p02924
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int> vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000; // 1e18
const ll MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;
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;
}
template <class T> inline void add(T &a, T b) {
a = ((a + b) % MOD + MOD) % MOD;
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
cout << N * (N - 1) / 2 << endl;
}
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int> vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000; // 1e18
const ll MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;
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;
}
template <class T> inline void add(T &a, T b) {
a = ((a + b) % MOD + MOD) % MOD;
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
cout << N * (N - 1) / 2 << endl;
}
|
[
"variable_declaration.type.change"
] | 728,987
| 728,988
|
u493750228
|
cpp
|
p02924
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
int main() {
cin >> N;
cout << (N - 1) * N / 2 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N;
int main() {
cin >> N;
cout << (N - 1) * N / 2 << endl;
return 0;
}
|
[
"variable_declaration.type.change"
] | 728,989
| 728,990
|
u488352661
|
cpp
|
p02924
|
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define dup(x, y) (((x) + (y)-1) / (y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
// std::cout<<std::fixed<<std::setprecision(10);
int main() {
ll N;
cin >> N;
int ans = N * (N - 1) / 2;
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define dup(x, y) (((x) + (y)-1) / (y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
// std::cout<<std::fixed<<std::setprecision(10);
int main() {
ll N;
cin >> N;
ll ans = N * (N - 1) / 2;
cout << ans << endl;
return 0;
}
|
[
"variable_declaration.type.change"
] | 728,991
| 728,992
|
u017293723
|
cpp
|
p02924
|
#include <bits/stdc++.h>
#define debug(n) cerr << #n << ':' << n << endl;
using namespace std;
using ll = long long;
template <class T, class U> using umap = unordered_map<T, U>;
template <class T> using uset = unordered_set<T>;
template <class T> inline bool change_max(T &a, const T &b) {
if (b > a) {
a = b;
return true;
}
return false;
}
template <class T> inline bool change_min(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main() {
int n;
cin >> n;
cout << ((n - 1) * n) / 2 << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define debug(n) cerr << #n << ':' << n << endl;
using namespace std;
using ll = long long;
template <class T, class U> using umap = unordered_map<T, U>;
template <class T> using uset = unordered_set<T>;
template <class T> inline bool change_max(T &a, const T &b) {
if (b > a) {
a = b;
return true;
}
return false;
}
template <class T> inline bool change_min(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main() {
ll n;
cin >> n;
cout << ((n - 1) * n) / 2 << endl;
return 0;
}
|
[
"variable_declaration.type.change"
] | 728,993
| 728,994
|
u691380397
|
cpp
|
p02924
|
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N;
cin >> N;
cout << N * (N - 1) / 2;
return 0;
}
|
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll N;
cin >> N;
cout << N * (N - 1) / 2;
return 0;
}
|
[
"variable_declaration.type.change"
] | 728,997
| 728,998
|
u854904794
|
cpp
|
p02924
|
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
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;
}
using namespace std;
const ll BIG = 1000000007LL;
int inputValue() {
int a;
cin >> a;
return a;
};
template <typename T> void inputArray(T *p, int a){rep(i, a){cin >> p[i];
}
}
;
template <typename T> void inputVector(vector<T> *p, int a) {
rep(i, a) {
T input;
cin >> input;
p->push_back(input);
}
}
template <typename T> void output(T a, int precision = 0) {
if (precision > 0) {
cout << setprecision(precision) << a << "\n";
} else {
cout << a << "\n";
}
}
int N;
ll solve(int n) {
if (n == 1)
return 0;
if (n == 2)
return 1;
return n * (n - 1) / 2;
}
int main(int argc, const char *argv[]) {
cin >> N;
output(solve(N));
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
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;
}
using namespace std;
const ll BIG = 1000000007LL;
int inputValue() {
int a;
cin >> a;
return a;
};
template <typename T> void inputArray(T *p, int a){rep(i, a){cin >> p[i];
}
}
;
template <typename T> void inputVector(vector<T> *p, int a) {
rep(i, a) {
T input;
cin >> input;
p->push_back(input);
}
}
template <typename T> void output(T a, int precision = 0) {
if (precision > 0) {
cout << setprecision(precision) << a << "\n";
} else {
cout << a << "\n";
}
}
ll N;
ll solve(ll n) {
if (n == 1)
return 0;
if (n == 2)
return 1;
return n * (n - 1) / 2LL;
}
int main(int argc, const char *argv[]) {
cin >> N;
output(solve(N));
return 0;
}
|
[
"variable_declaration.type.change",
"literal.number.type.widen.change"
] | 728,999
| 729,000
|
u909601929
|
cpp
|
p02924
|
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int, int> P;
typedef vector<int> Vi;
int const MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
return a = b;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
return a = b;
}
return false;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
cout << n * (n - 1) / 2 << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
using Int = long long unsigned;
typedef pair<int, int> P;
typedef vector<int> Vi;
int const MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
return a = b;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
return a = b;
}
return false;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
Int n;
cin >> n;
cout << n * (n - 1) / 2 << '\n';
}
|
[
"variable_declaration.type.widen.change",
"variable_declaration.type.change"
] | 729,001
| 729,002
|
u735089337
|
cpp
|
p02924
|
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int n;
cin >> n;
cout << n * (n - 1) / 2 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
long long int n;
cin >> n;
cout << n * (n - 1) / 2 << endl;
return 0;
}
|
[
"variable_declaration.type.widen.change"
] | 729,003
| 729,004
|
u073082475
|
cpp
|
p02924
|
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using ull = unsigned long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using ii = pair<int, int>;
using vii = vector<ii>;
using vvii = vector<vii>;
using dd = pair<double, double>;
using vdd = vector<dd>;
using vvdd = vector<vdd>;
using Mii = map<int, int>;
using vMii = vector<Mii>;
using Si = set<int>;
using vSi = vector<Si>;
using vvSi = vector<vSi>;
#define fi first
#define se second
#define INF 1e9 + 5
#define mod(a, m) (a % m + m) % m
#define PB push_back
#define MP make_pair
int main() {
// cout.setf(ios::fixed);
// cout.precision(4);
int n;
while (cin >> n) {
ll ans = n * (n - 1) / 2;
cout << ans << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using ull = unsigned long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using ii = pair<int, int>;
using vii = vector<ii>;
using vvii = vector<vii>;
using dd = pair<double, double>;
using vdd = vector<dd>;
using vvdd = vector<vdd>;
using Mii = map<int, int>;
using vMii = vector<Mii>;
using Si = set<int>;
using vSi = vector<Si>;
using vvSi = vector<vSi>;
#define fi first
#define se second
#define INF 1e9 + 5
#define mod(a, m) (a % m + m) % m
#define PB push_back
#define MP make_pair
int main() {
// cout.setf(ios::fixed);
// cout.precision(4);
ll n;
while (cin >> n) {
ll ans = n * (n - 1) / 2;
cout << ans << '\n';
}
}
|
[
"variable_declaration.type.change"
] | 729,015
| 729,016
|
u525888949
|
cpp
|
p02924
|
#include <bits/stdc++.h>
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int, int> fd[] = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1),
make_pair(0, -1)};
vector<int> init(int size) {
vector<int> par(size, -1);
return par;
}
int root(int x, vector<int> &par) {
if (par[x] < 0) {
return x;
} else {
return par[x] = root(par[x], par);
}
}
bool same(int x, int y, vector<int> &par) {
return root(x, par) == root(y, par);
}
void unite(int x, int y, vector<int> &par) {
x = root(x, par), y = root(y, par);
if (same(x, y, par))
return;
par[x] += par[y];
par[y] = x;
}
int size(int x, vector<int> &par) { return -par[root(x, par)]; }
int pow(int x, int n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return pow(x * x % MOD, n / 2);
else
return x * pow(x, n - 1) % MOD;
}
vector<int> divisor(int n) {
vector<int> ret;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret), greater<int>());
return (ret);
}
signed main() {
int n;
cin >> n;
cout << n * (n + 1) / 2 << endl;
}
|
#include <bits/stdc++.h>
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int, int> fd[] = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1),
make_pair(0, -1)};
vector<int> init(int size) {
vector<int> par(size, -1);
return par;
}
int root(int x, vector<int> &par) {
if (par[x] < 0) {
return x;
} else {
return par[x] = root(par[x], par);
}
}
bool same(int x, int y, vector<int> &par) {
return root(x, par) == root(y, par);
}
void unite(int x, int y, vector<int> &par) {
x = root(x, par), y = root(y, par);
if (same(x, y, par))
return;
par[x] += par[y];
par[y] = x;
}
int size(int x, vector<int> &par) { return -par[root(x, par)]; }
int pow(int x, int n) {
if (n == 0)
return 1;
if (n % 2 == 0)
return pow(x * x % MOD, n / 2);
else
return x * pow(x, n - 1) % MOD;
}
vector<int> divisor(int n) {
vector<int> ret;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret), greater<int>());
return (ret);
}
signed main() {
int n;
cin >> n;
n--;
cout << n * (n + 1) / 2 << endl;
}
|
[
"expression.unary.arithmetic.add"
] | 729,017
| 729,018
|
u317754719
|
cpp
|
p02913
|
#include <bits/stdc++.h>
using namespace std;
// iterator
#define REP(i, init, n) for (lli i = init; i < n; i++)
#define REPE(i, init, n) for (lli i = init; i <= n; i++)
#define REPIT(it, container) \
for (auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it, container) \
for (auto it = container.rbegin(); it != container.rend(); it++)
// input
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define ncin1(n, x) \
REP(i, 0, n) { cin1(x[i]); }
#define ncin2(n, x, y) \
REP(i, 0, n) { cin2(x[i], y[i]); }
#define ncin3(n, x, y, z) \
REP(i, 0, n) { cin3(x[i], y[i], z[i]); }
// output
#define cout1(x) cout << #x << ": " << x << endl;
#define cout2(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z) \
cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " \
<< z << endl; \
;
#define ncout1(n, x) \
REP(i, 0, n) { cout << #x << "[" << i << "]: " << x[i] << endl; }
#define coutp(p) \
cout << #p << ":" \
<< " (" << p.first << ", " << p.second << ")" << endl;
// sort
#define sort_r(x, y) sort(x, y, greater<lli>()); // 降順(5,4,3,,,)
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
void z_algorithm(const string s, lli *z) {
lli len = s.length();
// 0文字目に何を入れたいかに依る
z[0] = 0;
lli left = 0;
lli right = 0;
REP(i, 1, len) {
if (i > right) {
left = right = i;
while (true) {
if (right >= len || s[right - left] != s[right])
break;
right++;
}
z[i] = right - left;
right--;
} else {
lli j = i - left;
// z-box の範囲に収まっている場合はそのままz-boxの値を入れれば良い
if (z[j] < right - i + 1) {
z[i] = z[j];
} else {
left = i;
while (true) {
if (right >= len || s[right - left] != s[right])
break;
right++;
}
z[i] = right - left;
right--;
}
}
}
}
int main() {
lli n;
string s;
cin1(n);
cin1(s);
lli ans = 0;
REP(i, 1, n) {
// cout << s.substr(i,n-i) << endl;
lli z[n - i] = {0};
z_algorithm(s.substr(i), z);
// cout << s.substr(i).length() <<endl;
// cout1(n-i);
REP(j, 0, n - i) { ans = max(ans, min(z[j], j)); }
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
// iterator
#define REP(i, init, n) for (lli i = init; i < n; i++)
#define REPE(i, init, n) for (lli i = init; i <= n; i++)
#define REPIT(it, container) \
for (auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it, container) \
for (auto it = container.rbegin(); it != container.rend(); it++)
// input
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define ncin1(n, x) \
REP(i, 0, n) { cin1(x[i]); }
#define ncin2(n, x, y) \
REP(i, 0, n) { cin2(x[i], y[i]); }
#define ncin3(n, x, y, z) \
REP(i, 0, n) { cin3(x[i], y[i], z[i]); }
// output
#define cout1(x) cout << #x << ": " << x << endl;
#define cout2(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z) \
cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " \
<< z << endl; \
;
#define ncout1(n, x) \
REP(i, 0, n) { cout << #x << "[" << i << "]: " << x[i] << endl; }
#define coutp(p) \
cout << #p << ":" \
<< " (" << p.first << ", " << p.second << ")" << endl;
// sort
#define sort_r(x, y) sort(x, y, greater<lli>()); // 降順(5,4,3,,,)
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
void z_algorithm(const string s, lli *z) {
lli len = s.length();
// 0文字目に何を入れたいかに依る
z[0] = 0;
lli left = 0;
lli right = 0;
REP(i, 1, len) {
if (i > right) {
left = right = i;
while (true) {
if (right >= len || s[right - left] != s[right])
break;
right++;
}
z[i] = right - left;
right--;
} else {
lli j = i - left;
// z-box の範囲に収まっている場合はそのままz-boxの値を入れれば良い
if (z[j] < right - i + 1) {
z[i] = z[j];
} else {
left = i;
while (true) {
if (right >= len || s[right - left] != s[right])
break;
right++;
}
z[i] = right - left;
right--;
}
}
}
}
int main() {
lli n;
string s;
cin1(n);
cin1(s);
lli ans = 0;
REP(i, 0, n) {
lli z[n - i];
z_algorithm(s.substr(i), z);
// cout << s.substr(i,n-i) << endl;
REP(j, 0, n - i) {
ans = max(ans, min(z[j], j));
// cout << z[j];
}
// cout << endl;
}
cout << ans << endl;
}
|
[
"literal.number.change",
"call.arguments.change"
] | 729,024
| 729,025
|
u058297300
|
cpp
|
p02913
|
#include <bits/stdc++.h>
using namespace std;
// iterator
#define REP(i, init, n) for (lli i = init; i < n; i++)
#define REPE(i, init, n) for (lli i = init; i <= n; i++)
#define REPIT(it, container) \
for (auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it, container) \
for (auto it = container.rbegin(); it != container.rend(); it++)
// input
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define ncin1(n, x) \
REP(i, 0, n) { cin1(x[i]); }
#define ncin2(n, x, y) \
REP(i, 0, n) { cin2(x[i], y[i]); }
#define ncin3(n, x, y, z) \
REP(i, 0, n) { cin3(x[i], y[i], z[i]); }
// output
#define cout1(x) cout << #x << ": " << x << endl;
#define cout2(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z) \
cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " \
<< z << endl; \
;
#define ncout1(n, x) \
REP(i, 0, n) { cout << #x << "[" << i << "]: " << x[i] << endl; }
#define coutp(p) \
cout << #p << ":" \
<< " (" << p.first << ", " << p.second << ")" << endl;
// sort
#define sort_r(x, y) sort(x, y, greater<lli>()); // 降順(5,4,3,,,)
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
void z_algorithm(const string s, lli *z) {
lli len = s.length();
// 0文字目に何を入れたいかに依る
z[0] = 0;
lli left = 0;
lli right = 0;
REP(i, 1, len) {
if (i > right) {
left = right = i;
while (true) {
if (right >= len || s[right - left] != s[right])
break;
right++;
}
z[i] = right - left;
right--;
} else {
lli j = i - left;
// z-box の範囲に収まっている場合はそのままz-boxの値を入れれば良い
if (z[j] < right - i + 1) {
z[i] = z[j];
} else {
left = i;
while (true) {
if (right >= len || s[right - left] != s[right])
break;
right++;
}
z[i] = right - left;
right--;
}
}
}
}
int main() {
lli n;
string s;
cin1(n);
cin1(s);
lli ans = 0;
REP(i, 1, n) {
// cout << s.substr(i,n-i) << endl;
lli z[n - i];
z_algorithm(s.substr(i), z);
REP(j, 0, n - i) { ans = max(ans, min(z[j], j)); }
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
// iterator
#define REP(i, init, n) for (lli i = init; i < n; i++)
#define REPE(i, init, n) for (lli i = init; i <= n; i++)
#define REPIT(it, container) \
for (auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it, container) \
for (auto it = container.rbegin(); it != container.rend(); it++)
// input
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define ncin1(n, x) \
REP(i, 0, n) { cin1(x[i]); }
#define ncin2(n, x, y) \
REP(i, 0, n) { cin2(x[i], y[i]); }
#define ncin3(n, x, y, z) \
REP(i, 0, n) { cin3(x[i], y[i], z[i]); }
// output
#define cout1(x) cout << #x << ": " << x << endl;
#define cout2(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z) \
cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " \
<< z << endl; \
;
#define ncout1(n, x) \
REP(i, 0, n) { cout << #x << "[" << i << "]: " << x[i] << endl; }
#define coutp(p) \
cout << #p << ":" \
<< " (" << p.first << ", " << p.second << ")" << endl;
// sort
#define sort_r(x, y) sort(x, y, greater<lli>()); // 降順(5,4,3,,,)
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
void z_algorithm(const string s, lli *z) {
lli len = s.length();
// 0文字目に何を入れたいかに依る
z[0] = 0;
lli left = 0;
lli right = 0;
REP(i, 1, len) {
if (i > right) {
left = right = i;
while (true) {
if (right >= len || s[right - left] != s[right])
break;
right++;
}
z[i] = right - left;
right--;
} else {
lli j = i - left;
// z-box の範囲に収まっている場合はそのままz-boxの値を入れれば良い
if (z[j] < right - i + 1) {
z[i] = z[j];
} else {
left = i;
while (true) {
if (right >= len || s[right - left] != s[right])
break;
right++;
}
z[i] = right - left;
right--;
}
}
}
}
int main() {
lli n;
string s;
cin1(n);
cin1(s);
lli ans = 0;
REP(i, 0, n) {
lli z[n - i];
z_algorithm(s.substr(i), z);
// cout << s.substr(i,n-i) << endl;
REP(j, 0, n - i) {
ans = max(ans, min(z[j], j));
// cout << z[j];
}
// cout << endl;
}
cout << ans << endl;
}
|
[
"literal.number.change",
"call.arguments.change"
] | 729,026
| 729,025
|
u058297300
|
cpp
|
p02913
|
#include <bits/stdc++.h>
using namespace std;
// iterator
#define REP(i, init, n) for (lli i = init; i < n; i++)
#define REPE(i, init, n) for (lli i = init; i <= n; i++)
#define REPIT(it, container) \
for (auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it, container) \
for (auto it = container.rbegin(); it != container.rend(); it++)
// input
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define ncin1(n, x) \
REP(i, 0, n) { cin1(x[i]); }
#define ncin2(n, x, y) \
REP(i, 0, n) { cin2(x[i], y[i]); }
#define ncin3(n, x, y, z) \
REP(i, 0, n) { cin3(x[i], y[i], z[i]); }
// output
#define cout1(x) cout << #x << ": " << x << endl;
#define cout2(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z) \
cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " \
<< z << endl; \
;
#define ncout1(n, x) \
REP(i, 0, n) { cout << #x << "[" << i << "]: " << x[i] << endl; }
#define coutp(p) \
cout << #p << ":" \
<< " (" << p.first << ", " << p.second << ")" << endl;
// sort
#define sort_r(x, y) sort(x, y, greater<lli>()); // 降順(5,4,3,,,)
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
void z_algorithm(const string s, lli *z) {
lli len = s.length();
// 0文字目に何を入れたいかに依る
z[0] = 0;
lli left = 0;
lli right = 0;
REP(i, 1, len) {
if (i > right) {
left = right = i;
while (true) {
if (right >= len || s[right - left] != s[right])
break;
right++;
}
z[i] = right - left;
right--;
} else {
lli j = i - left;
// z-box の範囲に収まっている場合はそのままz-boxの値を入れれば良い
if (z[j] < right - i + 1) {
z[i] = z[j];
} else {
left = i;
while (true) {
if (right >= len || s[right - left] != s[right])
break;
right++;
}
z[i] = right - left;
right--;
}
}
}
}
int main() {
lli n;
string s;
cin1(n);
cin1(s);
lli ans = 0;
REP(i, 1, n) {
// cout << s.substr(i,n-i) << endl;
lli z[n - i];
z_algorithm(s.substr(i, n - i), z);
REP(j, 0, n - i) { ans = max(ans, min(z[j], j)); }
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
// iterator
#define REP(i, init, n) for (lli i = init; i < n; i++)
#define REPE(i, init, n) for (lli i = init; i <= n; i++)
#define REPIT(it, container) \
for (auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it, container) \
for (auto it = container.rbegin(); it != container.rend(); it++)
// input
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define ncin1(n, x) \
REP(i, 0, n) { cin1(x[i]); }
#define ncin2(n, x, y) \
REP(i, 0, n) { cin2(x[i], y[i]); }
#define ncin3(n, x, y, z) \
REP(i, 0, n) { cin3(x[i], y[i], z[i]); }
// output
#define cout1(x) cout << #x << ": " << x << endl;
#define cout2(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z) \
cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " \
<< z << endl; \
;
#define ncout1(n, x) \
REP(i, 0, n) { cout << #x << "[" << i << "]: " << x[i] << endl; }
#define coutp(p) \
cout << #p << ":" \
<< " (" << p.first << ", " << p.second << ")" << endl;
// sort
#define sort_r(x, y) sort(x, y, greater<lli>()); // 降順(5,4,3,,,)
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
void z_algorithm(const string s, lli *z) {
lli len = s.length();
// 0文字目に何を入れたいかに依る
z[0] = 0;
lli left = 0;
lli right = 0;
REP(i, 1, len) {
if (i > right) {
left = right = i;
while (true) {
if (right >= len || s[right - left] != s[right])
break;
right++;
}
z[i] = right - left;
right--;
} else {
lli j = i - left;
// z-box の範囲に収まっている場合はそのままz-boxの値を入れれば良い
if (z[j] < right - i + 1) {
z[i] = z[j];
} else {
left = i;
while (true) {
if (right >= len || s[right - left] != s[right])
break;
right++;
}
z[i] = right - left;
right--;
}
}
}
}
int main() {
lli n;
string s;
cin1(n);
cin1(s);
lli ans = 0;
REP(i, 0, n) {
lli z[n - i];
z_algorithm(s.substr(i), z);
// cout << s.substr(i,n-i) << endl;
REP(j, 0, n - i) {
ans = max(ans, min(z[j], j));
// cout << z[j];
}
// cout << endl;
}
cout << ans << endl;
}
|
[
"literal.number.change",
"call.arguments.change"
] | 729,027
| 729,025
|
u058297300
|
cpp
|
p02913
|
#include <bits/stdc++.h>
using namespace std;
// iterator
#define REP(i, init, n) for (lli i = init; i < n; i++)
#define REPE(i, init, n) for (lli i = init; i <= n; i++)
#define REPIT(it, container) \
for (auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it, container) \
for (auto it = container.rbegin(); it != container.rend(); it++)
// input
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define ncin1(n, x) \
REP(i, 0, n) { cin1(x[i]); }
#define ncin2(n, x, y) \
REP(i, 0, n) { cin2(x[i], y[i]); }
#define ncin3(n, x, y, z) \
REP(i, 0, n) { cin3(x[i], y[i], z[i]); }
// output
#define cout1(x) cout << #x << ": " << x << endl;
#define cout2(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z) \
cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " \
<< z << endl; \
;
#define ncout1(n, x) \
REP(i, 0, n) { cout << #x << "[" << i << "]: " << x[i] << endl; }
#define coutp(p) \
cout << #p << ":" \
<< " (" << p.first << ", " << p.second << ")" << endl;
// sort
#define sort_r(x, y) sort(x, y, greater<lli>()); // 降順(5,4,3,,,)
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
void z_algorithm(const string s, lli *z) {
lli len = s.length();
// 0文字目に何を入れたいかに依る
z[0] = 0;
lli left = 0;
lli right = 0;
REP(i, 1, len) {
if (i > right) {
left = right = i;
while (true) {
if (right >= len || s[right - left] != s[right])
break;
right++;
}
z[i] = right - left;
right--;
} else {
lli j = i - left;
// z-box の範囲に収まっている場合はそのままz-boxの値を入れれば良い
if (z[j] < right - i + 1) {
z[i] = z[j];
} else {
left = i;
while (true) {
if (right >= len || s[right - left] != s[right])
break;
right++;
}
z[i] = right - left;
right--;
}
}
}
}
int main() {
lli n;
string s;
cin1(n);
cin1(s);
lli ans = 0;
REP(i, 1, n) {
// cout << s.substr(i,n) << endl;
lli z[n - i];
z_algorithm(s.substr(i, n), z);
REP(j, 0, n - i) { ans = max(ans, min(z[j], j)); }
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
// iterator
#define REP(i, init, n) for (lli i = init; i < n; i++)
#define REPE(i, init, n) for (lli i = init; i <= n; i++)
#define REPIT(it, container) \
for (auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it, container) \
for (auto it = container.rbegin(); it != container.rend(); it++)
// input
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define ncin1(n, x) \
REP(i, 0, n) { cin1(x[i]); }
#define ncin2(n, x, y) \
REP(i, 0, n) { cin2(x[i], y[i]); }
#define ncin3(n, x, y, z) \
REP(i, 0, n) { cin3(x[i], y[i], z[i]); }
// output
#define cout1(x) cout << #x << ": " << x << endl;
#define cout2(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z) \
cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " \
<< z << endl; \
;
#define ncout1(n, x) \
REP(i, 0, n) { cout << #x << "[" << i << "]: " << x[i] << endl; }
#define coutp(p) \
cout << #p << ":" \
<< " (" << p.first << ", " << p.second << ")" << endl;
// sort
#define sort_r(x, y) sort(x, y, greater<lli>()); // 降順(5,4,3,,,)
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
void z_algorithm(const string s, lli *z) {
lli len = s.length();
// 0文字目に何を入れたいかに依る
z[0] = 0;
lli left = 0;
lli right = 0;
REP(i, 1, len) {
if (i > right) {
left = right = i;
while (true) {
if (right >= len || s[right - left] != s[right])
break;
right++;
}
z[i] = right - left;
right--;
} else {
lli j = i - left;
// z-box の範囲に収まっている場合はそのままz-boxの値を入れれば良い
if (z[j] < right - i + 1) {
z[i] = z[j];
} else {
left = i;
while (true) {
if (right >= len || s[right - left] != s[right])
break;
right++;
}
z[i] = right - left;
right--;
}
}
}
}
int main() {
lli n;
string s;
cin1(n);
cin1(s);
lli ans = 0;
REP(i, 0, n) {
lli z[n - i];
z_algorithm(s.substr(i), z);
// cout << s.substr(i,n-i) << endl;
REP(j, 0, n - i) {
ans = max(ans, min(z[j], j));
// cout << z[j];
}
// cout << endl;
}
cout << ans << endl;
}
|
[
"literal.number.change",
"call.arguments.change"
] | 729,028
| 729,025
|
u058297300
|
cpp
|
p02913
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool rk(string t, string p) {
int k = 1000007, m = 1000000007;
long long ht = 0;
long long po = 1;
for (int i = 0; i < p.size(); i++) {
po *= k;
po %= m;
}
po %= m;
for (int i = 0; i < p.size(); i++) {
ht *= k;
ht += t[i];
ht %= m;
}
long long hp = 0;
for (int i = 0; i < p.size(); i++) {
hp *= k;
hp += p[i];
hp %= m;
}
for (int i = 0; i < t.size() - p.size() + 1; i++) {
if (hp == ht) {
if (t.substr(i, p.size()) == p) {
return true;
}
}
if (i + p.size() < t.size()) {
ht *= k;
ht -= t[i] * po;
ht += t[i + p.size()];
ht %= m;
if (ht < 0) {
ht += m;
}
}
}
return false;
}
bool calc(string s, int n) {
if (n == 0) {
return true;
}
for (int i = 0; i + n * 2 < s.size(); i++) {
string ss1 = s.substr(i, n);
string ss2 = s.substr(i + n);
if (rk(ss2, ss1)) {
return true;
}
}
return false;
}
int main() {
int n;
string s;
cin >> n;
cin >> s;
int left = 0;
int right = n / 2 + 1;
while (left < right) {
int i = left + (right - left) / 2;
if (calc(s, i)) {
left = i + 1;
} else {
right = i;
}
}
cout << left - 1 << endl;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool rk(string t, string p) {
int k = 1000007, m = 1000000007;
long long ht = 0;
long long po = 1;
for (int i = 0; i < p.size(); i++) {
po *= k;
po %= m;
}
po %= m;
for (int i = 0; i < p.size(); i++) {
ht *= k;
ht += t[i];
ht %= m;
}
long long hp = 0;
for (int i = 0; i < p.size(); i++) {
hp *= k;
hp += p[i];
hp %= m;
}
for (int i = 0; i < t.size() - p.size() + 1; i++) {
if (hp == ht) {
if (t.substr(i, p.size()) == p) {
return true;
}
}
if (i + p.size() < t.size()) {
ht *= k;
ht -= t[i] * po;
ht += t[i + p.size()];
ht %= m;
if (ht < 0) {
ht += m;
}
}
}
return false;
}
bool calc(string s, int n) {
if (n == 0) {
return true;
}
for (int i = 0; i + n * 2 <= s.size(); i++) {
string ss1 = s.substr(i, n);
string ss2 = s.substr(i + n);
if (rk(ss2, ss1)) {
return true;
}
}
return false;
}
int main() {
int n;
string s;
cin >> n;
cin >> s;
int left = 0;
int right = n / 2 + 1;
while (left < right) {
int i = left + (right - left) / 2;
if (calc(s, i)) {
left = i + 1;
} else {
right = i;
}
}
cout << left - 1 << endl;
}
|
[
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 729,031
| 729,032
|
u553461888
|
cpp
|
p02913
|
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (n); i < (m); i++)
#define rrep(i, n, m) for (int i = (n)-1; i >= (m); i--)
using namespace std;
using ll = long long;
int zalgorithm(string s) {
int i = 1;
int j = 0;
vector<int> a(s.size(), s.size());
while (i < s.size()) {
while (i + j < s.size() and s[i + j] == s[j])
j++;
a[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < s.size() and k + a[k] <= j)
a[i + k] = a[k], ++k;
j -= k;
i += k;
}
int res = 0;
rep(i, 1, a.size()) {
res = max(res, min(i, a[i]));
// cout << i << ": " << a[i] << ' ' << s << endl;
}
return res;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
int ans = 0;
rep(i, 0, s.size()) {
int now = zalgorithm(s.substr(i, s.size() - i));
ans = max(ans, now);
// cout << i << ' ' << now << endl;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (n); i < (m); i++)
#define rrep(i, n, m) for (int i = (n)-1; i >= (m); i--)
using namespace std;
using ll = long long;
int zalgorithm(string s) {
int i = 1;
int j = 0;
vector<int> a(s.size(), s.size());
while (i < s.size()) {
while (i + j < s.size() and s[i + j] == s[j])
j++;
a[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < s.size() and k + a[k] < j)
a[i + k] = a[k], ++k;
j -= k;
i += k;
}
int res = 0;
rep(i, 1, a.size()) {
res = max(res, min(i, a[i]));
// cout << i << ": " << a[i] << ' ' << s << endl;
}
return res;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
int ans = 0;
rep(i, 0, s.size()) {
int now = zalgorithm(s.substr(i, s.size() - i));
ans = max(ans, now);
// cout << i << ' ' << now << endl;
}
cout << ans << endl;
return 0;
}
|
[
"expression.operator.compare.change",
"control_flow.loop.condition.change"
] | 729,033
| 729,034
|
u052247353
|
cpp
|
p02913
|
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (n); i < (m); i++)
#define rrep(i, n, m) for (int i = (n)-1; i >= (m); i--)
using namespace std;
using ll = long long;
int zalgorithm(string s) {
int i = 1;
int j = 0;
vector<int> a(s.size(), s.size());
while (i < s.size()) {
while (i + j < s.size() and s[i + j] == s[j])
j++;
a[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < s.size() and k + a[k] < j)
a[i + k] = a[k], ++k;
j -= k;
i += k;
}
int res = 0;
rep(i, 1, a.size()) {
res = max(res, min(i + 1, a[i]));
// cout << i << ": " << a[i] << ' ' << s << endl;
}
return res;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
int ans = 0;
rep(i, 0, s.size()) {
int now = zalgorithm(s.substr(i, s.size() - i));
ans = max(ans, now);
// cout << i << ' ' << now << endl;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (n); i < (m); i++)
#define rrep(i, n, m) for (int i = (n)-1; i >= (m); i--)
using namespace std;
using ll = long long;
int zalgorithm(string s) {
int i = 1;
int j = 0;
vector<int> a(s.size(), s.size());
while (i < s.size()) {
while (i + j < s.size() and s[i + j] == s[j])
j++;
a[i] = j;
if (j == 0) {
++i;
continue;
}
int k = 1;
while (i + k < s.size() and k + a[k] < j)
a[i + k] = a[k], ++k;
j -= k;
i += k;
}
int res = 0;
rep(i, 1, a.size()) {
res = max(res, min(i, a[i]));
// cout << i << ": " << a[i] << ' ' << s << endl;
}
return res;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
int ans = 0;
rep(i, 0, s.size()) {
int now = zalgorithm(s.substr(i, s.size() - i));
ans = max(ans, now);
// cout << i << ' ' << now << endl;
}
cout << ans << endl;
return 0;
}
|
[
"expression.operation.binary.remove"
] | 729,035
| 729,034
|
u052247353
|
cpp
|
p02913
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#define N 5005
int n, ans;
char a[N];
int main() {
scanf("%d%s", &n, a + 1);
for (register int i = 1; i <= (n >> 1); ++i) {
int s = 0;
for (register int j = 1; j <= n - i; ++j)
a[j] == a[j + i] && s < i ? ++s, ans = std ::max(ans, s) : s = 0;
}
printf("%d\n", ans);
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#define N 5005
int n, ans;
char a[N];
int main() {
scanf("%d%s", &n, a + 1);
for (register int i = 1; i <= n; ++i) {
int s = 0;
for (register int j = 1; j <= n - i; ++j)
a[j] == a[j + i] && s < i ? ++s, ans = std ::max(ans, s) : s = 0;
}
printf("%d\n", ans);
}
|
[
"control_flow.loop.for.condition.change"
] | 729,050
| 729,051
|
u684791042
|
cpp
|
p02913
|
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
ll dp[5001][5001]; // dp[i][j]はi番目とj番目から始めたときの部分列の
//共通の長さで,i<jとする.
int main() {
int N;
cin >> N;
string s;
cin >> s;
for (int i = 1; i <= N - 1; i++) {
for (int j = i + 1; j <= N; j++) {
if (s[i] == s[j])
dp[i][j] = min(dp[i - 1][j - 1] + 1, (ll)j - i);
}
}
ll ans = 0;
for (int i = 1; i <= N - 1; i++) {
for (int j = i + 1; j <= N; j++) {
ans = max(ans, dp[i][j]);
}
}
cout << ans << endl;
}
|
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
ll dp[5001][5000];
int main() {
int N;
cin >> N;
string s;
cin >> s;
for (int i = 1; i <= N - 1; i++) {
for (int j = i + 1; j <= N; j++) {
if (s[i - 1] == s[j - 1])
dp[i][j] = min(dp[i - 1][j - 1] + 1, (ll)j - i);
}
}
ll ans = 0;
for (int i = 1; i <= N - 1; i++) {
for (int j = i + 1; j <= N; j++) {
ans = max(ans, dp[i][j]);
}
}
cout << ans << endl;
}
|
[
"literal.number.change",
"variable_declaration.array_dimensions.change",
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 729,052
| 729,053
|
u963055157
|
cpp
|
p02913
|
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
ll dp[5001][5001]; // dp[i][j]はi番目とj番目から始めたときの部分列の
//共通の長さで,i<jとする.
int main() {
int N;
cin >> N;
string s;
cin >> s;
for (int i = 1; i <= N - 1; i++) {
for (int j = i + 1; j <= N; j++) {
if (s[i] == s[j])
dp[i][j] = min(dp[i - 1][j - 1] + 1, (ll)j - i);
}
}
ll ans = 0;
for (int i = 1; i <= N - 1; i++) {
for (int j = i + 1; j <= N; j++) {
ans = max(ans, dp[i][j]);
}
}
cout << ans << endl;
}
|
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
ll dp[5000][5000];
int main() {
int N;
cin >> N;
string s;
cin >> s;
for (int i = 1; i <= N - 1; i++) {
for (int j = i + 1; j <= N; j++) {
if (s[i - 1] == s[j - 1])
dp[i][j] = min(dp[i - 1][j - 1] + 1, (ll)j - i);
}
}
ll ans = 0;
for (int i = 1; i <= N - 1; i++) {
for (int j = i + 1; j <= N; j++) {
ans = max(ans, dp[i][j]);
}
}
cout << ans << endl;
}
|
[
"literal.number.change",
"variable_declaration.array_dimensions.change",
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 729,052
| 729,054
|
u963055157
|
cpp
|
p02913
|
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i, N) for (int i = 0; i < (N); i++)
#define repr(i, N) for (int i = (N)-1; i >= 0; i--)
#define rep1(i, N) for (int i = 1; i <= (N); i++)
#define repr1(i, N) for (int i = (N); i > 0; i--)
#define each(x, v) for (auto &x : v)
#define all(v) (v).begin(), (v).end()
#define sz(v) ((int)(v).size())
#define vrep(v, it) for (auto it = v.begin(); it != v.end(); it++)
#define vrepr(v, it) for (auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) \
int __VA_ARGS__; \
in(__VA_ARGS__)
#define inl(...) \
ll __VA_ARGS__; \
in(__VA_ARGS__)
#define ins(...) \
string __VA_ARGS__; \
in(__VA_ARGS__)
using namespace std;
void solve();
using ll = long long;
using vl = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {
IoSetupNya() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
cerr << fixed << setprecision(7);
}
} iosetupnya;
template <typename T, typename U> inline bool amin(T &x, U y) {
return (y < x) ? (x = y, true) : false;
}
template <typename T, typename U> inline bool amax(T &x, U y) {
return (x < y) ? (x = y, true) : false;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
int s = (int)v.size();
rep(i, s) os << (i ? " " : "") << v[i];
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &x : v)
is >> x;
return is;
}
void in() {}
template <typename T, class... U> void in(T &t, U &...u) {
cin >> t;
in(u...);
}
void out() { cout << "\n"; }
template <typename T, class... U> void out(const T &t, const U &...u) {
cout << t;
if (sizeof...(u))
cout << " ";
out(u...);
}
template <typename T> void die(T x) {
out(x);
exit(0);
}
#ifdef NyaanDebug
#include "NyaanDebug.h"
#define trc(...) \
do { \
cerr << #__VA_ARGS__ << " = "; \
dbg_out(__VA_ARGS__); \
} while (0)
#define trca(v, ...) \
do { \
cerr << #v << " = "; \
array_out(v, __VA_ARGS__); \
} while (0)
#else
#define trc(...)
#define trca(...)
int main() { solve(); }
#endif
using P = pair<int, int>;
using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
/////////////////
// 使い方
// 文字列のハッシュ列 Roriha s_rori(S);
// 配列のハッシュ列 RollingHash<vector<int>> vrori(v);
template <typename string_t> struct RollingHash {
using ull = unsigned long long;
using Pu = pair<ull, ull>;
string_t &data;
vector<Pu> hashed, power;
int size_;
static Pu basis;
static constexpr ull rmod = (1ull << 61) - 1;
static constexpr ull mul(const ull a, const ull b) {
ull l1 = (uint32_t)a, h1 = a >> 32, l2 = (uint32_t)b, h2 = b >> 32;
ull l = l1 * l2, m = l1 * h2 + l2 * h1, h = h1 * h2;
ull ret = (l & rmod) + (l >> 61) + (h << 3) + (m >> 29) + (m << 35 >> 3);
if (ret > rmod)
ret = (ret & rmod) + (ret >> 61);
if (ret >= rmod)
ret -= rmod;
return ret;
}
static constexpr ull mul_plus(const ull a, const ull b, const ull c) {
ull l1 = (uint32_t)a, h1 = a >> 32, l2 = (uint32_t)b, h2 = b >> 32;
ull l = l1 * l2, m = l1 * h2 + l2 * h1, h = h1 * h2;
ull ret =
(l & rmod) + (l >> 61) + (h << 3) + (m >> 29) + (m << 35 >> 3) + c;
if (ret > rmod)
ret = (ret & rmod) + (ret >> 61);
if (ret >= rmod)
ret -= rmod;
return ret;
}
static constexpr ull modpow(ull a, ull b) {
a %= rmod;
ull r = 1;
while (b) {
if (b & 1)
r = mul(r, a);
a = mul(a, a);
b >>= 1;
}
return r;
}
static constexpr bool isPrimitive(ull x, vector<ull> &ds) {
for (ll d : ds)
if (d != rmod - 1) {
if (modpow(x, (rmod - 1) / d) == 1)
return false;
}
return true;
}
static constexpr Pu get_basis() {
vector<ull> ds = {2, 3, 5, 7, 11, 13, 31, 41, 61, 151, 331, 1321};
auto rand_time =
chrono::duration_cast<chrono::nanoseconds>(
chrono::high_resolution_clock::now().time_since_epoch())
.count();
mt19937_64 rng(rand_time);
ull a = -1, b = -1;
do {
a = rng() % rmod;
} while (isPrimitive(a, ds) == false);
do {
b = rng() % rmod;
} while (a == b || isPrimitive(b, ds) == false);
return Pu(a, b);
}
// Rolling Hashの構築 O( |S| )
// basis_flagがtrueの時はbasisを乱数で初期化、falseの時はbでbasisを初期化
RollingHash(string_t &S) : data(S), size_((int)S.size()) {
// hashed[i] 部分列[0 , i)のハッシュを記録 hashed[0] = (0,0)
// power[i] basisのi乗を記録
hashed.resize(size_ + 1);
power.resize(size_ + 1);
power[0] = Pu(1, 1);
hashed[0] = Pu(0, 0);
for (int i = 1; i <= size_; i++) {
power[i].fi = mul(power[i - 1].fi, basis.fi);
power[i].se = mul(power[i - 1].se, basis.se);
hashed[i].fi = mul_plus(hashed[i - 1].fi, basis.fi, S[i - 1]);
hashed[i].se = mul_plus(hashed[i - 1].se, basis.se, S[i - 1]);
}
}
// 部分文字列[ l , r )のハッシュを取得 O(1)
Pu get(const int l, const int r) {
Pu ret;
ret.fi =
rmod - mul_plus(hashed[l].fi, power[r - l].fi, rmod - hashed[r].fi);
ret.se =
rmod - mul_plus(hashed[l].se, power[r - l].se, rmod - hashed[r].se);
return ret;
}
// 別の文字列のハッシュを取得 O( |T| )
Pu get_hash(string_t &T) {
Pu ret = Pu(0, 0);
for (int i = 0; i < (int)T.size(); i++) {
ret.fi = mul_plus(ret.fi, basis.fi, T[i]);
ret.se = mul_plus(ret.se, basis.se, T[i]);
}
return ret;
}
// 別の文字列と一致判定 O ( |S| + |T| )
// 存在するときは最初の文字を、存在しないときは-1を返す
int find(string_t &T) {
auto t_hash = get_hash(T);
int t_size = (int)(T.size());
// |S| < |T|の時はfor文の中に入らないことに留意する
for (int i = 0; i <= size_ - t_size; i++) {
if (t_hash == get(i, i + t_size))
return i;
}
return -1;
}
// 別の文字列と一致判定 O ( |S| + |T| )
// 一致する文字列のindexをすべて返す
vector<int> find_all(string_t &T) {
auto t_hash = get_hash(T);
int t_size = (int)(T.size());
vector<int> ret;
// |S| < |T|の時はfor文の中に入らないことに留意する
for (int i = 0; i <= size_ - t_size; i++) {
if (t_hash == get(i, i + t_size))
ret.push_back(i);
}
return ret;
}
// Longest Common Prefix(最長共通接頭辞) O( log |S| )
// Sの[al , ar)とTの[bl , br)の最長共通接頭辞の長さを求める
// 引数 (文字列Tのハッシュ列 , 文字列Sの開始地点a , 文字列Tの開始地点b)
// 返り値 最長共通接頭辞の長さ
int LongestCommonPrefix(RollingHash<string_t> &t, int al, int bl, int ar = -1,
int br = -1) {
if (ar == -1)
ar = size_;
if (br == -1)
br = t.size_;
int ok = 0, ng = min(ar - al, br - bl) + 1;
while (ok + 1 < ng) {
int med = (ok + ng) / 2;
if (get(al, med + al) == t.get(bl, med + bl))
ok = med;
else
ng = med;
}
return ok;
}
// 文字列の大小比較 O( log |S + T| )
// Sの[al , ar)とTの[bl , br)の最長共通接頭辞の長さを求める
// 返り値 1 Sのほうが大きい 0 同じ -1 Tのほうが大きい
int strcmp(RollingHash<string_t> &t, int al, int bl, int ar = -1,
int br = -1) {
if (ar == -1)
ar = size_;
if (br == -1)
br = t.size_;
int n = LongestCommonPrefix(t, al, bl, ar, br);
if (al + n == ar)
return (bl + n == br) ? 0 : 1;
else if (bl + n == br)
return -1;
else
return (data[al + n] < t.data[bl + n]) ? 1 : -1;
}
// 文字列内の最長一致部分文字列を検索 O ( |S| (log|S|)^2 )
int LongestCommonSubString() {
auto func = [&](int len) -> bool {
map<Pu, int> m;
for (int i = 0; i <= size_ - len; i++) {
if ((m[get(i, i + len)] += 1) != 1)
return true;
}
return false;
};
int ok = 0, ng = size_;
while (ok + 1 < ng) {
int med = (ok + ng) / 2;
if (func(med))
ok = med;
else
ng = med;
}
return ok;
}
};
// ロリハのハッシュの初期化
template <typename T>
pair<unsigned long long, unsigned long long>
RollingHash<T>::basis = RollingHash<T>::get_basis();
using Roriha = RollingHash<string>;
struct SuffixArray {
int _size;
vector<int> sa;
string &s;
SuffixArray(string &str) : s(str), _size(str.size()) {
sa.resize(_size + 1);
vector<int> rank(_size + 1), tmp(_size + 1);
int k;
// 比較用の関数
// ダブリングを用いてiから2k文字とjから2k文字をO(1)で比較する関数
auto comp = [&](int i, int j) {
if (rank[i] != rank[j])
return rank[i] < rank[j];
int ri = i + k <= _size ? rank[i + k] : -1;
int rj = j + k <= _size ? rank[j + k] : -1;
return ri < rj;
};
// 初期化 asciiを用いて1文字の部分列を辞書順ソート
for (int i = 0; i <= _size; i++) {
sa[i] = i;
rank[i] = (i < _size ? str[i] : -1);
}
// ダブリング
for (k = 1; k <= _size; k *= 2) {
// 2k文字でソート
sort(sa.begin(), sa.end(), comp);
// 更新
tmp[sa[0]] = 0;
for (int i = 1; i <= _size; i++) {
tmp[sa[i]] = tmp[sa[i - 1]] + (comp(sa[i - 1], sa[i]) ? 1 : 0);
}
for (int i = 0; i <= _size; i++)
rank[i] = tmp[i];
}
}
// デバッグ用に実装
void output() {
for (int i = 0; i < size(); i++) {
cout << i << ": " << sa[i] << endl;
}
}
// sa.size()と表せると便利なので実装
int size() const { return _size + 1; }
// sa[]と表せると便利なのでオーバーロードしておく
int operator[](int k) const { return sa[k]; }
};
struct LCPArray {
const SuffixArray &SA;
vector<int> LCP, rank;
int max, left, right;
LCPArray(const SuffixArray &sa) : SA(sa), max(-1) {
LCP.resize(SA.size());
rank.resize(SA.size());
// 初期化 rankはsaの逆関数
for (int i = 0; i < SA.size(); i++) {
rank[SA[i]] = i;
}
LCP[0] = 0;
// 構築
for (int i = 0, h = 0; i < SA.size() - 1; i++) {
int j = SA[rank[i] - 1];
h ? h-- : h;
// ここで尺取り法に近い手法を使うことでO(N)でLCPの構築をしている
while ((i > j ? i : j) + h < SA.size() - 1 &&
SA.s[i + h] == SA.s[j + h] && ++h)
;
if (max < (LCP[rank[i] - 1] = h)) {
max = h;
left = SA[rank[i] - 1];
right = i;
if (left > right) {
int hoge = left;
left = right;
right = hoge;
}
}
}
}
// デバッグ用に実装
void output() {
cout << "max : i = " << left + 1 << ", j = " << right + 1 << ", k = " << max
<< endl;
for (int i = 0; i < SA.size(); i++) {
cout << SA.sa[i] << " " << LCP[i] << " " << endl;
}
}
};
// セグ木
template <typename T, typename F> struct ST {
int size;
vector<T> seg;
const F func;
const T UNIT;
ST(int N, F func, T UNIT) : func(func), UNIT(UNIT) {
size = 1;
while (size < N)
size <<= 1;
seg.assign(2 * size, UNIT);
}
ST(const vector<T> &v, F func, T UNIT) : func(func), UNIT(UNIT) {
// initialize
int N = (int)v.size();
size = 1;
while (size < N)
size <<= 1;
seg.assign(2 * size, UNIT);
// set
for (int i = 0; i < N; i++) {
seg[i + size] = v[i];
}
build();
}
void set(int k, T x) { seg[k + size] = x; }
void build() {
for (int k = size - 1; k > 0; k--) {
seg[k] = func(seg[2 * k], seg[2 * k + 1]);
}
}
void update(int k, T x) {
k += size;
seg[k] = x;
while (k >>= 1) {
seg[k] = func(seg[2 * k], seg[2 * k + 1]);
}
}
// 半開区間[a,b)へのクエリ
T query(int a, int b) {
T L = UNIT, R = UNIT;
for (a += size, b += size; a < b; a >>= 1, b >>= 1) {
if (a & 1)
L = func(L, seg[a++]);
if (b & 1)
R = func(seg[--b], R);
}
return func(L, R);
}
T operator[](const int &k) const { return seg[k + size]; }
};
void solve() {
ini(N);
ins(S);
SuffixArray sa(S);
LCPArray lcp(sa);
int ans = 0;
lcp.output();
auto f = [&](int a, int b) { return min(a, b); };
ST<int, decltype(f)> st(lcp.LCP, f, inf);
rep(i, N) rep(j, N) {
if (i == j)
continue;
if (lcp.rank[i] > lcp.rank[j])
continue;
amax(ans, min(abs(i - j), st.query(lcp.rank[i], lcp.rank[j])));
}
out(ans);
}
|
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i, N) for (int i = 0; i < (N); i++)
#define repr(i, N) for (int i = (N)-1; i >= 0; i--)
#define rep1(i, N) for (int i = 1; i <= (N); i++)
#define repr1(i, N) for (int i = (N); i > 0; i--)
#define each(x, v) for (auto &x : v)
#define all(v) (v).begin(), (v).end()
#define sz(v) ((int)(v).size())
#define vrep(v, it) for (auto it = v.begin(); it != v.end(); it++)
#define vrepr(v, it) for (auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) \
int __VA_ARGS__; \
in(__VA_ARGS__)
#define inl(...) \
ll __VA_ARGS__; \
in(__VA_ARGS__)
#define ins(...) \
string __VA_ARGS__; \
in(__VA_ARGS__)
using namespace std;
void solve();
using ll = long long;
using vl = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {
IoSetupNya() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
cerr << fixed << setprecision(7);
}
} iosetupnya;
template <typename T, typename U> inline bool amin(T &x, U y) {
return (y < x) ? (x = y, true) : false;
}
template <typename T, typename U> inline bool amax(T &x, U y) {
return (x < y) ? (x = y, true) : false;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
int s = (int)v.size();
rep(i, s) os << (i ? " " : "") << v[i];
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &x : v)
is >> x;
return is;
}
void in() {}
template <typename T, class... U> void in(T &t, U &...u) {
cin >> t;
in(u...);
}
void out() { cout << "\n"; }
template <typename T, class... U> void out(const T &t, const U &...u) {
cout << t;
if (sizeof...(u))
cout << " ";
out(u...);
}
template <typename T> void die(T x) {
out(x);
exit(0);
}
#ifdef NyaanDebug
#include "NyaanDebug.h"
#define trc(...) \
do { \
cerr << #__VA_ARGS__ << " = "; \
dbg_out(__VA_ARGS__); \
} while (0)
#define trca(v, ...) \
do { \
cerr << #v << " = "; \
array_out(v, __VA_ARGS__); \
} while (0)
#else
#define trc(...)
#define trca(...)
int main() { solve(); }
#endif
using P = pair<int, int>;
using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
/////////////////
// 使い方
// 文字列のハッシュ列 Roriha s_rori(S);
// 配列のハッシュ列 RollingHash<vector<int>> vrori(v);
template <typename string_t> struct RollingHash {
using ull = unsigned long long;
using Pu = pair<ull, ull>;
string_t &data;
vector<Pu> hashed, power;
int size_;
static Pu basis;
static constexpr ull rmod = (1ull << 61) - 1;
static constexpr ull mul(const ull a, const ull b) {
ull l1 = (uint32_t)a, h1 = a >> 32, l2 = (uint32_t)b, h2 = b >> 32;
ull l = l1 * l2, m = l1 * h2 + l2 * h1, h = h1 * h2;
ull ret = (l & rmod) + (l >> 61) + (h << 3) + (m >> 29) + (m << 35 >> 3);
if (ret > rmod)
ret = (ret & rmod) + (ret >> 61);
if (ret >= rmod)
ret -= rmod;
return ret;
}
static constexpr ull mul_plus(const ull a, const ull b, const ull c) {
ull l1 = (uint32_t)a, h1 = a >> 32, l2 = (uint32_t)b, h2 = b >> 32;
ull l = l1 * l2, m = l1 * h2 + l2 * h1, h = h1 * h2;
ull ret =
(l & rmod) + (l >> 61) + (h << 3) + (m >> 29) + (m << 35 >> 3) + c;
if (ret > rmod)
ret = (ret & rmod) + (ret >> 61);
if (ret >= rmod)
ret -= rmod;
return ret;
}
static constexpr ull modpow(ull a, ull b) {
a %= rmod;
ull r = 1;
while (b) {
if (b & 1)
r = mul(r, a);
a = mul(a, a);
b >>= 1;
}
return r;
}
static constexpr bool isPrimitive(ull x, vector<ull> &ds) {
for (ll d : ds)
if (d != rmod - 1) {
if (modpow(x, (rmod - 1) / d) == 1)
return false;
}
return true;
}
static constexpr Pu get_basis() {
vector<ull> ds = {2, 3, 5, 7, 11, 13, 31, 41, 61, 151, 331, 1321};
auto rand_time =
chrono::duration_cast<chrono::nanoseconds>(
chrono::high_resolution_clock::now().time_since_epoch())
.count();
mt19937_64 rng(rand_time);
ull a = -1, b = -1;
do {
a = rng() % rmod;
} while (isPrimitive(a, ds) == false);
do {
b = rng() % rmod;
} while (a == b || isPrimitive(b, ds) == false);
return Pu(a, b);
}
// Rolling Hashの構築 O( |S| )
// basis_flagがtrueの時はbasisを乱数で初期化、falseの時はbでbasisを初期化
RollingHash(string_t &S) : data(S), size_((int)S.size()) {
// hashed[i] 部分列[0 , i)のハッシュを記録 hashed[0] = (0,0)
// power[i] basisのi乗を記録
hashed.resize(size_ + 1);
power.resize(size_ + 1);
power[0] = Pu(1, 1);
hashed[0] = Pu(0, 0);
for (int i = 1; i <= size_; i++) {
power[i].fi = mul(power[i - 1].fi, basis.fi);
power[i].se = mul(power[i - 1].se, basis.se);
hashed[i].fi = mul_plus(hashed[i - 1].fi, basis.fi, S[i - 1]);
hashed[i].se = mul_plus(hashed[i - 1].se, basis.se, S[i - 1]);
}
}
// 部分文字列[ l , r )のハッシュを取得 O(1)
Pu get(const int l, const int r) {
Pu ret;
ret.fi =
rmod - mul_plus(hashed[l].fi, power[r - l].fi, rmod - hashed[r].fi);
ret.se =
rmod - mul_plus(hashed[l].se, power[r - l].se, rmod - hashed[r].se);
return ret;
}
// 別の文字列のハッシュを取得 O( |T| )
Pu get_hash(string_t &T) {
Pu ret = Pu(0, 0);
for (int i = 0; i < (int)T.size(); i++) {
ret.fi = mul_plus(ret.fi, basis.fi, T[i]);
ret.se = mul_plus(ret.se, basis.se, T[i]);
}
return ret;
}
// 別の文字列と一致判定 O ( |S| + |T| )
// 存在するときは最初の文字を、存在しないときは-1を返す
int find(string_t &T) {
auto t_hash = get_hash(T);
int t_size = (int)(T.size());
// |S| < |T|の時はfor文の中に入らないことに留意する
for (int i = 0; i <= size_ - t_size; i++) {
if (t_hash == get(i, i + t_size))
return i;
}
return -1;
}
// 別の文字列と一致判定 O ( |S| + |T| )
// 一致する文字列のindexをすべて返す
vector<int> find_all(string_t &T) {
auto t_hash = get_hash(T);
int t_size = (int)(T.size());
vector<int> ret;
// |S| < |T|の時はfor文の中に入らないことに留意する
for (int i = 0; i <= size_ - t_size; i++) {
if (t_hash == get(i, i + t_size))
ret.push_back(i);
}
return ret;
}
// Longest Common Prefix(最長共通接頭辞) O( log |S| )
// Sの[al , ar)とTの[bl , br)の最長共通接頭辞の長さを求める
// 引数 (文字列Tのハッシュ列 , 文字列Sの開始地点a , 文字列Tの開始地点b)
// 返り値 最長共通接頭辞の長さ
int LongestCommonPrefix(RollingHash<string_t> &t, int al, int bl, int ar = -1,
int br = -1) {
if (ar == -1)
ar = size_;
if (br == -1)
br = t.size_;
int ok = 0, ng = min(ar - al, br - bl) + 1;
while (ok + 1 < ng) {
int med = (ok + ng) / 2;
if (get(al, med + al) == t.get(bl, med + bl))
ok = med;
else
ng = med;
}
return ok;
}
// 文字列の大小比較 O( log |S + T| )
// Sの[al , ar)とTの[bl , br)の最長共通接頭辞の長さを求める
// 返り値 1 Sのほうが大きい 0 同じ -1 Tのほうが大きい
int strcmp(RollingHash<string_t> &t, int al, int bl, int ar = -1,
int br = -1) {
if (ar == -1)
ar = size_;
if (br == -1)
br = t.size_;
int n = LongestCommonPrefix(t, al, bl, ar, br);
if (al + n == ar)
return (bl + n == br) ? 0 : 1;
else if (bl + n == br)
return -1;
else
return (data[al + n] < t.data[bl + n]) ? 1 : -1;
}
// 文字列内の最長一致部分文字列を検索 O ( |S| (log|S|)^2 )
int LongestCommonSubString() {
auto func = [&](int len) -> bool {
map<Pu, int> m;
for (int i = 0; i <= size_ - len; i++) {
if ((m[get(i, i + len)] += 1) != 1)
return true;
}
return false;
};
int ok = 0, ng = size_;
while (ok + 1 < ng) {
int med = (ok + ng) / 2;
if (func(med))
ok = med;
else
ng = med;
}
return ok;
}
};
// ロリハのハッシュの初期化
template <typename T>
pair<unsigned long long, unsigned long long>
RollingHash<T>::basis = RollingHash<T>::get_basis();
using Roriha = RollingHash<string>;
struct SuffixArray {
int _size;
vector<int> sa;
string &s;
SuffixArray(string &str) : s(str), _size(str.size()) {
sa.resize(_size + 1);
vector<int> rank(_size + 1), tmp(_size + 1);
int k;
// 比較用の関数
// ダブリングを用いてiから2k文字とjから2k文字をO(1)で比較する関数
auto comp = [&](int i, int j) {
if (rank[i] != rank[j])
return rank[i] < rank[j];
int ri = i + k <= _size ? rank[i + k] : -1;
int rj = j + k <= _size ? rank[j + k] : -1;
return ri < rj;
};
// 初期化 asciiを用いて1文字の部分列を辞書順ソート
for (int i = 0; i <= _size; i++) {
sa[i] = i;
rank[i] = (i < _size ? str[i] : -1);
}
// ダブリング
for (k = 1; k <= _size; k *= 2) {
// 2k文字でソート
sort(sa.begin(), sa.end(), comp);
// 更新
tmp[sa[0]] = 0;
for (int i = 1; i <= _size; i++) {
tmp[sa[i]] = tmp[sa[i - 1]] + (comp(sa[i - 1], sa[i]) ? 1 : 0);
}
for (int i = 0; i <= _size; i++)
rank[i] = tmp[i];
}
}
// デバッグ用に実装
void output() {
for (int i = 0; i < size(); i++) {
cout << i << ": " << sa[i] << endl;
}
}
// sa.size()と表せると便利なので実装
int size() const { return _size + 1; }
// sa[]と表せると便利なのでオーバーロードしておく
int operator[](int k) const { return sa[k]; }
};
struct LCPArray {
const SuffixArray &SA;
vector<int> LCP, rank;
int max, left, right;
LCPArray(const SuffixArray &sa) : SA(sa), max(-1) {
LCP.resize(SA.size());
rank.resize(SA.size());
// 初期化 rankはsaの逆関数
for (int i = 0; i < SA.size(); i++) {
rank[SA[i]] = i;
}
LCP[0] = 0;
// 構築
for (int i = 0, h = 0; i < SA.size() - 1; i++) {
int j = SA[rank[i] - 1];
h ? h-- : h;
// ここで尺取り法に近い手法を使うことでO(N)でLCPの構築をしている
while ((i > j ? i : j) + h < SA.size() - 1 &&
SA.s[i + h] == SA.s[j + h] && ++h)
;
if (max < (LCP[rank[i] - 1] = h)) {
max = h;
left = SA[rank[i] - 1];
right = i;
if (left > right) {
int hoge = left;
left = right;
right = hoge;
}
}
}
}
// デバッグ用に実装
void output() {
cout << "max : i = " << left + 1 << ", j = " << right + 1 << ", k = " << max
<< endl;
for (int i = 0; i < SA.size(); i++) {
cout << SA.sa[i] << " " << LCP[i] << " " << endl;
}
}
};
// セグ木
template <typename T, typename F> struct ST {
int size;
vector<T> seg;
const F func;
const T UNIT;
ST(int N, F func, T UNIT) : func(func), UNIT(UNIT) {
size = 1;
while (size < N)
size <<= 1;
seg.assign(2 * size, UNIT);
}
ST(const vector<T> &v, F func, T UNIT) : func(func), UNIT(UNIT) {
// initialize
int N = (int)v.size();
size = 1;
while (size < N)
size <<= 1;
seg.assign(2 * size, UNIT);
// set
for (int i = 0; i < N; i++) {
seg[i + size] = v[i];
}
build();
}
void set(int k, T x) { seg[k + size] = x; }
void build() {
for (int k = size - 1; k > 0; k--) {
seg[k] = func(seg[2 * k], seg[2 * k + 1]);
}
}
void update(int k, T x) {
k += size;
seg[k] = x;
while (k >>= 1) {
seg[k] = func(seg[2 * k], seg[2 * k + 1]);
}
}
// 半開区間[a,b)へのクエリ
T query(int a, int b) {
T L = UNIT, R = UNIT;
for (a += size, b += size; a < b; a >>= 1, b >>= 1) {
if (a & 1)
L = func(L, seg[a++]);
if (b & 1)
R = func(seg[--b], R);
}
return func(L, R);
}
T operator[](const int &k) const { return seg[k + size]; }
};
void solve() {
ini(N);
ins(S);
SuffixArray sa(S);
LCPArray lcp(sa);
int ans = 0;
// lcp.output();
auto f = [&](int a, int b) { return min(a, b); };
ST<int, decltype(f)> st(lcp.LCP, f, inf);
rep(i, N) rep(j, N) {
if (i == j)
continue;
if (lcp.rank[i] > lcp.rank[j])
continue;
amax(ans, min(abs(i - j), st.query(lcp.rank[i], lcp.rank[j])));
}
out(ans);
}
|
[
"call.remove"
] | 729,072
| 729,074
|
u168578024
|
cpp
|
p02913
|
#include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr << " " << (hoge) << endl;
#define DBG cerr << "!" << endl;
#define BITLE(n) (1LL << ((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s, f, t) ((s).substr((f)-1, (t) - (f) + 1))
#define ALL(a) (a).begin(), (a).end()
using namespace std;
ll n;
string s;
bool hogege = true;
bool check(ll mid) {
map<string, pair<ll, ll>> MP;
for (ll i = 0; i <= s.size() - mid; i++) {
string ss = SUBS(s, i + 1, i + mid);
ll num = MP[ss].F, num2 = MP[ss].S;
if (num == 0) {
MP[ss] = mp(i + 1, i + 1);
} else {
MP[ss] = mp(min(i + 1, num), max(i + 1, num2));
}
}
for (auto a : MP) {
ll po = a.S.F, po2 = a.S.S;
if (po + mid <= po2) {
return true;
}
}
return false;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> s;
ll le = 0, ri = 222222;
while (ri - le > 1) {
ll mid = (le + ri) / 2;
if (check(mid)) {
le = mid;
} else
ri = mid;
}
cout << le << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr << " " << (hoge) << endl;
#define DBG cerr << "!" << endl;
#define BITLE(n) (1LL << ((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s, f, t) ((s).substr((f)-1, (t) - (f) + 1))
#define ALL(a) (a).begin(), (a).end()
using namespace std;
ll n;
string s;
bool hogege = true;
bool check(ll mid) {
map<string, pair<ll, ll>> MP;
for (ll i = 0; i <= s.size() - mid; i++) {
string ss = SUBS(s, i + 1, i + mid);
ll num = MP[ss].F, num2 = MP[ss].S;
if (num == 0) {
MP[ss] = mp(i + 1, i + 1);
} else {
MP[ss] = mp(min(i + 1, num), max(i + 1, num2));
}
}
for (auto a : MP) {
ll po = a.S.F, po2 = a.S.S;
if (po + mid <= po2) {
return true;
}
}
return false;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> s;
ll le = 0, ri = n / 2 + 1;
while (ri - le > 1) {
ll mid = (le + ri) / 2;
if (check(mid)) {
le = mid;
} else
ri = mid;
}
cout << le << endl;
return 0;
}
|
[
"identifier.replace.add",
"literal.replace.remove"
] | 729,092
| 729,093
|
u905715926
|
cpp
|
p02913
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)
#define repi(i, x, n) for (int i = x; i < (ll)(n); i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
// cin.tie(0);ios::sync_with_stdio(false);
string s;
vector<int> Zalgo(string &s) {
int ssize = (int)s.size();
int j = 0; //調査済み部分の先端を調べたときのi
vector<int> res(ssize, 0);
res[0] = 0;
for (int i = 1; i < ssize; i++) {
int &k = res[i]; //参照なので書き換わる
if (j + res[j] <= i) //比較結果を再利用できない場合
{
k = 0;
} else //できる場合(前調べた部分に含まれる場合)
{
k = min(res[j] + j - i, res[i - j]);
//すでに調べて分かっている部分は初期値とする
//はみ出している場合、完全に再利用できる場合(たぶん)
}
while (i + k < ssize && s[k] == s[i + k])
k++;
if (j + res[j] < i + res[i])
j = i; //新しく調べた場所がさらに先なら更新
}
// res[0] = ssize;
return res;
}
signed main() {
int n, ans = 0;
cin >> n;
cin >> s;
rep(i, n) {
string t = s.substr(i, n - i);
vector<int> v = Zalgo(t);
repi(j, i, siz(v)) { ans = max(ans, min(v[j], j)); }
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)
#define repi(i, x, n) for (int i = x; i < (ll)(n); i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
// cin.tie(0);ios::sync_with_stdio(false);
string s;
vector<int> Zalgo(string &s) {
int ssize = (int)s.size();
int j = 0; //調査済み部分の先端を調べたときのi
vector<int> res(ssize, 0);
res[0] = 0;
for (int i = 1; i < ssize; i++) {
int &k = res[i]; //参照なので書き換わる
if (j + res[j] <= i) //比較結果を再利用できない場合
{
k = 0;
} else //できる場合(前調べた部分に含まれる場合)
{
k = min(res[j] + j - i, res[i - j]);
//すでに調べて分かっている部分は初期値とする
//はみ出している場合、完全に再利用できる場合(たぶん)
}
while (i + k < ssize && s[k] == s[i + k])
k++;
if (j + res[j] < i + res[i])
j = i; //新しく調べた場所がさらに先なら更新
}
// res[0] = ssize;
return res;
}
signed main() {
int n, ans = 0;
cin >> n;
cin >> s;
rep(i, n) {
string t = s.substr(i, n - i);
vector<int> v = Zalgo(t);
rep(j, siz(v)) { ans = max(ans, min(v[j], j)); }
}
cout << ans << endl;
}
|
[
"identifier.change"
] | 729,094
| 729,095
|
u317711717
|
cpp
|
p02913
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int dp[5005][5005]; //グローバルだと0初期化される
int main(void) {
int n;
string s;
cin >> n >> s;
for (int i = n - 1; i >= 0; --i) {
for (int j = n - 1; j >= 0; --j) {
if (s[i] != s[j]) {
dp[i][j] = 0;
} else {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}
int ans = 0;
rep(i, n) {
rep(j, n) {
if (i >= j)
continue;
int now = min(dp[i][j], j - 1);
ans = max(ans, now);
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int dp[5005][5005]; //グローバルだと0初期化される
int main(void) {
int n;
string s;
cin >> n >> s;
for (int i = n - 1; i >= 0; --i) {
for (int j = n - 1; j >= 0; --j) {
if (s[i] != s[j]) {
dp[i][j] = 0;
} else {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}
int ans = 0;
rep(i, n) {
rep(j, n) {
if (i >= j)
continue;
int now = min(dp[i][j], j - i);
ans = max(ans, now);
}
}
cout << ans << endl;
return 0;
}
|
[
"identifier.replace.add",
"literal.replace.remove",
"call.arguments.change",
"expression.operation.binary.change"
] | 729,098
| 729,099
|
u905170328
|
cpp
|
p02913
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int dp[5005][5005]; //グローバルだと0初期化される
int main(void) {
int n;
string s;
cin >> n >> s;
for (int i = n - 1; i >= 0; --i) {
for (int j = n - 1; j >= 0; --j) {
if (s[i] != s[j]) {
dp[i][j] = 0;
} else {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}
int ans = 0;
rep(i, n) {
rep(j, n) {
if (i >= j)
continue;
int now = min(dp[i][j], j - 1);
ans = max(ans, now);
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int dp[5005][5005]; //グローバルだと0初期化される
int main(void) {
int n;
string s;
cin >> n >> s;
for (int i = n - 1; i >= 0; --i) {
for (int j = n - 1; j >= 0; --j) {
if (s[i] != s[j]) {
dp[i][j] = 0;
} else {
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
}
int ans = 0;
rep(i, n) {
rep(j, n) {
if (i >= j)
continue;
int now = min(dp[i][j], j - i);
ans = max(ans, now);
}
}
cout << ans << endl;
return 0;
}
|
[
"identifier.replace.add",
"literal.replace.remove",
"call.arguments.change",
"expression.operation.binary.change"
] | 729,100
| 729,099
|
u905170328
|
cpp
|
p02913
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MAXN = 5 * 1e3;
vector<vector<int>> dp(MAXN + 5, vector<int>(MAXN + 5));
int main() {
int n;
cin >> n;
string s;
cin >> s;
for (int i = n - 1; i >= 0; i--) {
for (int j = n - 1; j >= 0; j--) {
if (s[i] == s[j])
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
int res = 0;
rep(i, n) {
for (int j = i; j < n; j++) {
if (dp[i][j] < j - i)
res = max(res, dp[i][j]); // not duplicate
}
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MAXN = 5 * 1e3;
vector<vector<int>> dp(MAXN + 5, vector<int>(MAXN + 5));
int main() {
int n;
cin >> n;
string s;
cin >> s;
for (int i = n - 1; i >= 0; i--) {
for (int j = n - 1; j >= 0; j--) {
if (s[i] == s[j])
dp[i][j] = dp[i + 1][j + 1] + 1;
}
}
int res = 0;
rep(i, n) {
for (int j = i; j < n; j++) {
if (dp[i][j] <= j - i)
res = max(res, dp[i][j]); // not duplicate
}
}
cout << res << endl;
return 0;
}
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 729,101
| 729,102
|
u762183504
|
cpp
|
p02913
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
constexpr ll mod[2] = {1000000007, 998244353};
struct rolling_hash {
ll z = 1000, ex[2][100010];
vector<ll> v, w[2];
rolling_hash(string &s) {
int i, j, n = s.size();
for (i = 0; i < n; i++) {
v.push_back(s[i] - 'a' + 1);
}
w[0].assign(n + 1, 0), w[1].assign(n + 1, 0);
ex[0][0] = 1, ex[0][1] = 1;
for (i = 0; i < n; i++) {
for (j = 0; j < 2; j++) {
w[j][i + 1] = (w[j][i] * z + v[i]) % mod[j];
ex[j][i + 1] = ex[j][i] * z % mod[j];
}
}
}
inline pll get(int l, int r) { //[l,r)
ll x = (w[0][r] - ex[0][r - l] * w[0][l] % mod[0] + mod[0]) % mod[0];
ll y = (w[1][r] - ex[0][r - l] * w[1][l] % mod[1] + mod[1]) % mod[1];
return {x, y};
}
};
string s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int i, j, n, ans = 0;
cin >> n >> s;
rolling_hash rh(s);
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (s[i] != s[j])
continue;
int l = 0, r = min(j - i, n - j);
if (rh.get(i, i + r) == rh.get(j, j + r)) {
ans = max(ans, r);
break;
}
while (r - l > 1) {
int mid = (l + r) / 2;
if (rh.get(i, i + mid) == rh.get(j, j + mid))
l = mid;
else
r = mid;
}
ans = max(ans, l);
}
}
cout << ans << endl;
}
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
constexpr ll mod[2] = {1000000007, 998244353};
struct rolling_hash {
ll z = 100, ex[2][100010];
vector<ll> v, w[2];
rolling_hash(string &s) {
int i, j, n = s.size();
for (i = 0; i < n; i++) {
v.push_back(s[i] - 'a' + 1);
}
w[0].assign(n + 1, 0), w[1].assign(n + 1, 0);
ex[0][0] = 1, ex[1][0] = 1;
for (i = 0; i < n; i++) {
for (j = 0; j < 2; j++) {
w[j][i + 1] = (w[j][i] * z + v[i]) % mod[j];
ex[j][i + 1] = ex[j][i] * z % mod[j];
}
}
}
inline pll get(int l, int r) { //[l,r)
ll x = (w[0][r] - ex[0][r - l] * w[0][l] % mod[0] + mod[0]) % mod[0];
ll y = (w[1][r] - ex[1][r - l] * w[1][l] % mod[1] + mod[1]) % mod[1];
return {x, y};
}
};
string s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int i, j, n, ans = 0;
cin >> n >> s;
rolling_hash rh(s);
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (s[i] != s[j])
continue;
int l = 0, r = min(j - i, n - j);
if (rh.get(i, i + r) == rh.get(j, j + r)) {
ans = max(ans, r);
continue;
}
while (r - l > 1) {
int mid = (l + r) / 2;
if (rh.get(i, i + mid) == rh.get(j, j + mid))
l = mid;
else
r = mid;
}
ans = max(ans, l);
}
}
cout << ans << endl;
}
|
[
"literal.number.change",
"assignment.variable.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change",
"control_flow.break.remove",
"control_flow.continue.add"
] | 729,109
| 729,110
|
u621509943
|
cpp
|
p02913
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using treap =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
{1, 0}, {0, 1}, {-1, 0}, {0, -1}, // 4方向
{1, 1}, {-1, 1}, {-1, -1}, {1, -1}, // 斜め
{0, 0}, // 自身
};
template <class T> inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T, class S> vector<T> make_vec(size_t n, S x) {
return vector<T>(n, x);
}
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}
// debug
template <class T> ostream &operator<<(ostream &s, vector<T> &d) {
REP(i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " ");
return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> &d) {
REP(i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n");
return s;
}
template <class T, class S> ostream &operator<<(ostream &s, pair<T, S> &p) {
s << "{" << p.first << ", " << p.second << "}";
return s;
}
template <class T> ostream &operator<<(ostream &s, set<T> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T> ostream &operator<<(ostream &s, multiset<T> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T, class S> ostream &operator<<(ostream &s, map<T, S> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T, class S>
ostream &operator<<(ostream &s, unordered_map<T, S> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
#ifdef _MY_DEBUG
#define dump(...) \
cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ \
<< "]" << endl, \
dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
#define dump(...)
#define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head &&h, Tail &&...t) {
cerr << h << (sizeof...(Tail) == 0 ? "" : ", "),
dump_func(forward<Tail>(t)...);
}
struct Fast {
Fast() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
}
} fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END ***************
using ull = unsigned long long;
struct RollingHash {
vector<ull> hash, pows;
ull base, mod;
RollingHash(const string &S, ull base, ull mod = 1000000009)
: hash(S.size() + 1), pows(S.size() + 1, 1), mod(mod), base(base) {
for (int i = 0; i < S.size(); i++) {
pows[i + 1] = pows[i] * base % mod;
hash[i + 1] = hash[i] * base % mod + S[i];
if (hash[i + 1] >= mod)
hash[i + 1] -= mod;
}
}
// [l, r)
ull get(int l, int r) {
dump(l, r);
assert(l <= r);
ull ret = hash[r] + mod - hash[l] * pows[r - l] % mod;
if (ret >= mod)
ret -= mod;
return ret;
}
void concat(const string &T) {
int n = hash.size() - 1, m = T.size();
pows.resize(n + m + 1);
hash.resize(n + m + 1);
for (int i = 0; i < m; i++) {
pows[n + i + 1] = pows[n + i] * base % mod;
hash[n + i + 1] = hash[n + i] * base % mod + T[i];
if (hash[n + i + 1] >= mod)
hash[n + i + 1] -= mod;
}
}
};
constexpr int HASH_NUM = 4;
struct bases_t {
int use[HASH_NUM];
int &operator[](int i) { return use[i]; }
bases_t() {
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
for (int i = 0; i < HASH_NUM; i++)
use[i] = rnd() % 10000;
}
} bases;
using multihash_t = array<int, HASH_NUM>;
struct MultiRollingHash {
vector<RollingHash> rhs;
MultiRollingHash(const string &S) {
for (int i = 0; i < HASH_NUM; i++) {
rhs.push_back(RollingHash(S, bases[i]));
}
}
multihash_t get(int l, int r) {
multihash_t ret;
for (int i = 0; i < HASH_NUM; i++)
ret[i] = rhs[i].get(l, r);
return ret;
}
void concat(const string &T) {
for (int i = 0; i < HASH_NUM; i++)
rhs[i].concat(T);
}
};
signed main() {
int n;
cin >> n;
string s;
cin >> s;
MultiRollingHash rh(s);
auto check = [&](int len) -> bool {
set<multihash_t> s;
REPI(i, len, n - len + 1) {
s.insert(rh.get(i - len, i));
if (s.count(rh.get(i, i + len)))
return true;
}
return false;
};
int ok = 0, ng = (n + 1) / 2;
while (abs(ok - ng) > 1) {
int m = (ok + ng) / 2;
(check(m) ? ok : ng) = m;
}
cout << ok << endl;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using treap =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
{1, 0}, {0, 1}, {-1, 0}, {0, -1}, // 4方向
{1, 1}, {-1, 1}, {-1, -1}, {1, -1}, // 斜め
{0, 0}, // 自身
};
template <class T> inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T, class S> vector<T> make_vec(size_t n, S x) {
return vector<T>(n, x);
}
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}
// debug
template <class T> ostream &operator<<(ostream &s, vector<T> &d) {
REP(i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " ");
return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> &d) {
REP(i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n");
return s;
}
template <class T, class S> ostream &operator<<(ostream &s, pair<T, S> &p) {
s << "{" << p.first << ", " << p.second << "}";
return s;
}
template <class T> ostream &operator<<(ostream &s, set<T> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T> ostream &operator<<(ostream &s, multiset<T> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T, class S> ostream &operator<<(ostream &s, map<T, S> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T, class S>
ostream &operator<<(ostream &s, unordered_map<T, S> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
#ifdef _MY_DEBUG
#define dump(...) \
cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ \
<< "]" << endl, \
dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
#define dump(...)
#define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head &&h, Tail &&...t) {
cerr << h << (sizeof...(Tail) == 0 ? "" : ", "),
dump_func(forward<Tail>(t)...);
}
struct Fast {
Fast() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
}
} fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END ***************
using ull = unsigned long long;
struct RollingHash {
vector<ull> hash, pows;
ull base, mod;
RollingHash(const string &S, ull base, ull mod = 1000000009)
: hash(S.size() + 1), pows(S.size() + 1, 1), mod(mod), base(base) {
for (int i = 0; i < S.size(); i++) {
pows[i + 1] = pows[i] * base % mod;
hash[i + 1] = hash[i] * base % mod + S[i];
if (hash[i + 1] >= mod)
hash[i + 1] -= mod;
}
}
// [l, r)
ull get(int l, int r) {
dump(l, r);
assert(l <= r);
ull ret = hash[r] + mod - hash[l] * pows[r - l] % mod;
if (ret >= mod)
ret -= mod;
return ret;
}
void concat(const string &T) {
int n = hash.size() - 1, m = T.size();
pows.resize(n + m + 1);
hash.resize(n + m + 1);
for (int i = 0; i < m; i++) {
pows[n + i + 1] = pows[n + i] * base % mod;
hash[n + i + 1] = hash[n + i] * base % mod + T[i];
if (hash[n + i + 1] >= mod)
hash[n + i + 1] -= mod;
}
}
};
constexpr int HASH_NUM = 4;
struct bases_t {
int use[HASH_NUM];
int &operator[](int i) { return use[i]; }
bases_t() {
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
for (int i = 0; i < HASH_NUM; i++)
use[i] = rnd() % 10000;
}
} bases;
using multihash_t = array<int, HASH_NUM>;
struct MultiRollingHash {
vector<RollingHash> rhs;
MultiRollingHash(const string &S) {
for (int i = 0; i < HASH_NUM; i++) {
rhs.push_back(RollingHash(S, bases[i]));
}
}
multihash_t get(int l, int r) {
multihash_t ret;
for (int i = 0; i < HASH_NUM; i++)
ret[i] = rhs[i].get(l, r);
return ret;
}
void concat(const string &T) {
for (int i = 0; i < HASH_NUM; i++)
rhs[i].concat(T);
}
};
signed main() {
int n;
cin >> n;
string s;
cin >> s;
MultiRollingHash rh(s);
auto check = [&](int len) -> bool {
set<multihash_t> s;
REPI(i, len, n - len + 1) {
s.insert(rh.get(i - len, i));
if (s.count(rh.get(i, i + len)))
return true;
}
return false;
};
int ok = 0, ng = (n + 2) / 2;
while (abs(ok - ng) > 1) {
int m = (ok + ng) / 2;
(check(m) ? ok : ng) = m;
}
cout << ok << endl;
}
|
[
"literal.number.change",
"expression.operation.binary.change"
] | 729,132
| 729,133
|
u852113235
|
cpp
|
p02913
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using treap =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
{1, 0}, {0, 1}, {-1, 0}, {0, -1}, // 4方向
{1, 1}, {-1, 1}, {-1, -1}, {1, -1}, // 斜め
{0, 0}, // 自身
};
template <class T> inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T, class S> vector<T> make_vec(size_t n, S x) {
return vector<T>(n, x);
}
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}
// debug
template <class T> ostream &operator<<(ostream &s, vector<T> &d) {
REP(i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " ");
return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> &d) {
REP(i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n");
return s;
}
template <class T, class S> ostream &operator<<(ostream &s, pair<T, S> &p) {
s << "{" << p.first << ", " << p.second << "}";
return s;
}
template <class T> ostream &operator<<(ostream &s, set<T> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T> ostream &operator<<(ostream &s, multiset<T> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T, class S> ostream &operator<<(ostream &s, map<T, S> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T, class S>
ostream &operator<<(ostream &s, unordered_map<T, S> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
#ifdef _MY_DEBUG
#define dump(...) \
cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ \
<< "]" << endl, \
dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
#define dump(...)
#define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head &&h, Tail &&...t) {
cerr << h << (sizeof...(Tail) == 0 ? "" : ", "),
dump_func(forward<Tail>(t)...);
}
struct Fast {
Fast() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
}
} fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END ***************
using ull = unsigned long long;
struct RollingHash {
vector<ull> hash, pows;
ull base, mod;
RollingHash(const string &S, ull base, ull mod = 4000000009)
: hash(S.size() + 1), pows(S.size() + 1, 1), mod(mod), base(base) {
for (int i = 0; i < S.size(); i++) {
pows[i + 1] = pows[i] * base % mod;
hash[i + 1] = hash[i] * base % mod + S[i];
if (hash[i + 1] >= mod)
hash[i + 1] -= mod;
}
}
// [l, r)
ull get(int l, int r) {
dump(l, r);
assert(l <= r);
ull ret = hash[r] + mod - hash[l] * pows[r - l] % mod;
if (ret >= mod)
ret -= mod;
return ret;
}
void concat(const string &T) {
int n = hash.size() - 1, m = T.size();
pows.resize(n + m + 1);
hash.resize(n + m + 1);
for (int i = 0; i < m; i++) {
pows[n + i + 1] = pows[n + i] * base % mod;
hash[n + i + 1] = hash[n + i] * base % mod + T[i];
if (hash[n + i + 1] >= mod)
hash[n + i + 1] -= mod;
}
}
};
constexpr int HASH_NUM = 4;
struct bases_t {
int use[HASH_NUM];
int &operator[](int i) { return use[i]; }
bases_t() {
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
for (int i = 0; i < HASH_NUM; i++)
use[i] = rnd() % 10000;
}
} bases;
using multihash_t = array<int, HASH_NUM>;
struct MultiRollingHash {
vector<RollingHash> rhs;
MultiRollingHash(const string &S) {
for (int i = 0; i < HASH_NUM; i++) {
rhs.push_back(RollingHash(S, bases[i]));
}
}
multihash_t get(int l, int r) {
multihash_t ret;
for (int i = 0; i < HASH_NUM; i++)
ret[i] = rhs[i].get(l, r);
return ret;
}
void concat(const string &T) {
for (int i = 0; i < HASH_NUM; i++)
rhs[i].concat(T);
}
};
signed main() {
int n;
cin >> n;
string s;
cin >> s;
MultiRollingHash rh(s);
auto check = [&](int len) -> bool {
set<multihash_t> s;
REPI(i, len, n - len + 1) {
s.insert(rh.get(i - len, i));
if (s.count(rh.get(i, i + len)))
return true;
}
return false;
};
int ok = 0, ng = (n + 1) / 2;
while (abs(ok - ng) > 1) {
int m = (ok + ng) / 2;
(check(m) ? ok : ng) = m;
}
cout << ok << endl;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using treap =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
{1, 0}, {0, 1}, {-1, 0}, {0, -1}, // 4方向
{1, 1}, {-1, 1}, {-1, -1}, {1, -1}, // 斜め
{0, 0}, // 自身
};
template <class T> inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T, class S> vector<T> make_vec(size_t n, S x) {
return vector<T>(n, x);
}
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}
// debug
template <class T> ostream &operator<<(ostream &s, vector<T> &d) {
REP(i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " ");
return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> &d) {
REP(i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n");
return s;
}
template <class T, class S> ostream &operator<<(ostream &s, pair<T, S> &p) {
s << "{" << p.first << ", " << p.second << "}";
return s;
}
template <class T> ostream &operator<<(ostream &s, set<T> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T> ostream &operator<<(ostream &s, multiset<T> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T, class S> ostream &operator<<(ostream &s, map<T, S> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T, class S>
ostream &operator<<(ostream &s, unordered_map<T, S> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
#ifdef _MY_DEBUG
#define dump(...) \
cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ \
<< "]" << endl, \
dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
#define dump(...)
#define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head &&h, Tail &&...t) {
cerr << h << (sizeof...(Tail) == 0 ? "" : ", "),
dump_func(forward<Tail>(t)...);
}
struct Fast {
Fast() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
}
} fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END ***************
using ull = unsigned long long;
struct RollingHash {
vector<ull> hash, pows;
ull base, mod;
RollingHash(const string &S, ull base, ull mod = 1000000009)
: hash(S.size() + 1), pows(S.size() + 1, 1), mod(mod), base(base) {
for (int i = 0; i < S.size(); i++) {
pows[i + 1] = pows[i] * base % mod;
hash[i + 1] = hash[i] * base % mod + S[i];
if (hash[i + 1] >= mod)
hash[i + 1] -= mod;
}
}
// [l, r)
ull get(int l, int r) {
dump(l, r);
assert(l <= r);
ull ret = hash[r] + mod - hash[l] * pows[r - l] % mod;
if (ret >= mod)
ret -= mod;
return ret;
}
void concat(const string &T) {
int n = hash.size() - 1, m = T.size();
pows.resize(n + m + 1);
hash.resize(n + m + 1);
for (int i = 0; i < m; i++) {
pows[n + i + 1] = pows[n + i] * base % mod;
hash[n + i + 1] = hash[n + i] * base % mod + T[i];
if (hash[n + i + 1] >= mod)
hash[n + i + 1] -= mod;
}
}
};
constexpr int HASH_NUM = 4;
struct bases_t {
int use[HASH_NUM];
int &operator[](int i) { return use[i]; }
bases_t() {
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
for (int i = 0; i < HASH_NUM; i++)
use[i] = rnd() % 10000;
}
} bases;
using multihash_t = array<int, HASH_NUM>;
struct MultiRollingHash {
vector<RollingHash> rhs;
MultiRollingHash(const string &S) {
for (int i = 0; i < HASH_NUM; i++) {
rhs.push_back(RollingHash(S, bases[i]));
}
}
multihash_t get(int l, int r) {
multihash_t ret;
for (int i = 0; i < HASH_NUM; i++)
ret[i] = rhs[i].get(l, r);
return ret;
}
void concat(const string &T) {
for (int i = 0; i < HASH_NUM; i++)
rhs[i].concat(T);
}
};
signed main() {
int n;
cin >> n;
string s;
cin >> s;
MultiRollingHash rh(s);
auto check = [&](int len) -> bool {
set<multihash_t> s;
REPI(i, len, n - len + 1) {
s.insert(rh.get(i - len, i));
if (s.count(rh.get(i, i + len)))
return true;
}
return false;
};
int ok = 0, ng = (n + 2) / 2;
while (abs(ok - ng) > 1) {
int m = (ok + ng) / 2;
(check(m) ? ok : ng) = m;
}
cout << ok << endl;
}
|
[
"literal.number.change",
"expression.operation.binary.change"
] | 729,134
| 729,133
|
u852113235
|
cpp
|
p02913
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using treap =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
{1, 0}, {0, 1}, {-1, 0}, {0, -1}, // 4方向
{1, 1}, {-1, 1}, {-1, -1}, {1, -1}, // 斜め
{0, 0}, // 自身
};
template <class T> inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T, class S> vector<T> make_vec(size_t n, S x) {
return vector<T>(n, x);
}
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}
// debug
template <class T> ostream &operator<<(ostream &s, vector<T> &d) {
REP(i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " ");
return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> &d) {
REP(i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n");
return s;
}
template <class T, class S> ostream &operator<<(ostream &s, pair<T, S> &p) {
s << "{" << p.first << ", " << p.second << "}";
return s;
}
template <class T> ostream &operator<<(ostream &s, set<T> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T> ostream &operator<<(ostream &s, multiset<T> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T, class S> ostream &operator<<(ostream &s, map<T, S> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T, class S>
ostream &operator<<(ostream &s, unordered_map<T, S> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
#ifdef _MY_DEBUG
#define dump(...) \
cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ \
<< "]" << endl, \
dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
#define dump(...)
#define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head &&h, Tail &&...t) {
cerr << h << (sizeof...(Tail) == 0 ? "" : ", "),
dump_func(forward<Tail>(t)...);
}
struct Fast {
Fast() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
}
} fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END ***************
using ull = unsigned long long;
struct RollingHash {
vector<ull> hash, pows;
ull base, mod;
RollingHash(const string &S, ull base, ull mod = 1000000009)
: hash(S.size() + 1), pows(S.size() + 1, 1), mod(mod), base(base) {
for (int i = 0; i < S.size(); i++) {
pows[i + 1] = pows[i] * base % mod;
hash[i + 1] = hash[i] * base % mod + S[i];
if (hash[i + 1] >= mod)
hash[i + 1] -= mod;
}
}
// [l, r)
ull get(int l, int r) {
dump(l, r);
assert(l <= r);
ull ret = hash[r] + mod - hash[l] * pows[r - l] % mod;
if (ret >= mod)
ret -= mod;
return ret;
}
void concat(const string &T) {
int n = hash.size() - 1, m = T.size();
pows.resize(n + m + 1);
hash.resize(n + m + 1);
for (int i = 0; i < m; i++) {
pows[n + i + 1] = pows[n + i] * base % mod;
hash[n + i + 1] = hash[n + i] * base % mod + T[i];
if (hash[n + i + 1] >= mod)
hash[n + i + 1] -= mod;
}
}
};
constexpr int HASH_NUM = 1;
struct bases_t {
int use[HASH_NUM];
int &operator[](int i) { return use[i]; }
bases_t() {
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
for (int i = 0; i < HASH_NUM; i++)
use[i] = rnd() % 1000000;
}
} bases;
using multihash_t = array<int, HASH_NUM>;
struct MultiRollingHash {
vector<RollingHash> rhs;
MultiRollingHash(const string &S) {
for (int i = 0; i < HASH_NUM; i++) {
rhs.push_back(RollingHash(S, bases[i]));
}
}
multihash_t get(int l, int r) {
multihash_t ret;
for (int i = 0; i < HASH_NUM; i++)
ret[i] = rhs[i].get(l, r);
return ret;
}
void concat(const string &T) {
for (int i = 0; i < HASH_NUM; i++)
rhs[i].concat(T);
}
};
signed main() {
int n;
cin >> n;
string s;
cin >> s;
MultiRollingHash rh(s);
auto check = [&](int len) -> bool {
REP(i, n - len + 1) {
auto hash1 = rh.get(i, i + len);
REPI(j, i + len, n - len + 1) {
if (hash1 == rh.get(j, j + len))
return true;
}
}
return false;
};
int ok = 0, ng = (n + 1) / 2;
while (abs(ok - ng) > 1) {
int m = (ok + ng) / 2;
(check(m) ? ok : ng) = m;
}
cout << ok << endl;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using treap =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
{1, 0}, {0, 1}, {-1, 0}, {0, -1}, // 4方向
{1, 1}, {-1, 1}, {-1, -1}, {1, -1}, // 斜め
{0, 0}, // 自身
};
template <class T> inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T, class S> vector<T> make_vec(size_t n, S x) {
return vector<T>(n, x);
}
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}
// debug
template <class T> ostream &operator<<(ostream &s, vector<T> &d) {
REP(i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " ");
return s;
}
template <class T> ostream &operator<<(ostream &s, vector<vector<T>> &d) {
REP(i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n");
return s;
}
template <class T, class S> ostream &operator<<(ostream &s, pair<T, S> &p) {
s << "{" << p.first << ", " << p.second << "}";
return s;
}
template <class T> ostream &operator<<(ostream &s, set<T> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T> ostream &operator<<(ostream &s, multiset<T> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T, class S> ostream &operator<<(ostream &s, map<T, S> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
template <class T, class S>
ostream &operator<<(ostream &s, unordered_map<T, S> m) {
for (auto it = m.begin(); it != m.end(); it++) {
s << *it << (next(it) == m.end() ? "" : "\n");
}
return s;
}
#ifdef _MY_DEBUG
#define dump(...) \
cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ \
<< "]" << endl, \
dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
#define dump(...)
#define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head &&h, Tail &&...t) {
cerr << h << (sizeof...(Tail) == 0 ? "" : ", "),
dump_func(forward<Tail>(t)...);
}
struct Fast {
Fast() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
}
} fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END ***************
using ull = unsigned long long;
struct RollingHash {
vector<ull> hash, pows;
ull base, mod;
RollingHash(const string &S, ull base, ull mod = 1000000009)
: hash(S.size() + 1), pows(S.size() + 1, 1), mod(mod), base(base) {
for (int i = 0; i < S.size(); i++) {
pows[i + 1] = pows[i] * base % mod;
hash[i + 1] = hash[i] * base % mod + S[i];
if (hash[i + 1] >= mod)
hash[i + 1] -= mod;
}
}
// [l, r)
ull get(int l, int r) {
dump(l, r);
assert(l <= r);
ull ret = hash[r] + mod - hash[l] * pows[r - l] % mod;
if (ret >= mod)
ret -= mod;
return ret;
}
void concat(const string &T) {
int n = hash.size() - 1, m = T.size();
pows.resize(n + m + 1);
hash.resize(n + m + 1);
for (int i = 0; i < m; i++) {
pows[n + i + 1] = pows[n + i] * base % mod;
hash[n + i + 1] = hash[n + i] * base % mod + T[i];
if (hash[n + i + 1] >= mod)
hash[n + i + 1] -= mod;
}
}
};
constexpr int HASH_NUM = 1;
struct bases_t {
int use[HASH_NUM];
int &operator[](int i) { return use[i]; }
bases_t() {
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
for (int i = 0; i < HASH_NUM; i++)
use[i] = rnd() % 1000000;
}
} bases;
using multihash_t = array<int, HASH_NUM>;
struct MultiRollingHash {
vector<RollingHash> rhs;
MultiRollingHash(const string &S) {
for (int i = 0; i < HASH_NUM; i++) {
rhs.push_back(RollingHash(S, bases[i]));
}
}
multihash_t get(int l, int r) {
multihash_t ret;
for (int i = 0; i < HASH_NUM; i++)
ret[i] = rhs[i].get(l, r);
return ret;
}
void concat(const string &T) {
for (int i = 0; i < HASH_NUM; i++)
rhs[i].concat(T);
}
};
signed main() {
int n;
cin >> n;
string s;
cin >> s;
MultiRollingHash rh(s);
auto check = [&](int len) -> bool {
REP(i, n - len + 1) {
auto hash1 = rh.get(i, i + len);
REPI(j, i + len, n - len + 1) {
if (hash1 == rh.get(j, j + len))
return true;
}
}
return false;
};
int ok = 0, ng = n;
while (abs(ok - ng) > 1) {
int m = (ok + ng) / 2;
(check(m) ? ok : ng) = m;
}
cout << ok << endl;
}
|
[
"expression.operation.binary.remove"
] | 729,135
| 729,136
|
u852113235
|
cpp
|
p02913
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int N;
int len, ans;
string S;
cin >> N;
cin >> S;
ans = 0;
for (int i = 1; i < N; i++) {
len = 0;
for (int j = 0; j < N - i; j++) {
if (S[j] == S[j - i]) {
len++;
} else {
len = 0;
}
if (len > ans) {
ans = len;
}
if (len == i) {
len = 0;
}
}
}
cout << ans << endl;
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int N;
int len, ans;
string S;
cin >> N;
cin >> S;
ans = 0;
for (int i = 1; i < N; i++) {
len = 0;
for (int j = 0; j < N - i; j++) {
if (S[j] == S[j + i]) {
len++;
} else {
len = 0;
}
if (len > ans) {
ans = len;
}
if (len == i) {
len = 0;
}
// cout << S[j+i];
}
// cout << endl;
}
cout << ans << endl;
return 0;
}
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 729,138
| 729,139
|
u235231201
|
cpp
|
p02913
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int(i) = ((n)-1); (i) >= 0; (i)--)
#define itn int
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
struct RollingHash {
vector<int> hash, base_pow;
int base = 1009, mod = 1e+7;
RollingHash(string S = "", /*vector <int> S*/ int basetmp = -1,
int modtmp = -1) {
if (modtmp != -1)
mod = modtmp;
if (basetmp != -1)
base = basetmp;
// cout<<mod<<' '<<base<<endl;
//////
int n = S.size();
vector<int> z(n);
rep(i, n) z[i] = S[i];
hash.resize(n + 1);
base_pow.resize(n + 1);
hash[0] = 0, base_pow[0] = 1;
for (int i = 1; i < z.size(); i++) {
hash[i] = (hash[i - 1] * base + z[i - 1]) % mod;
// cout<<hash[i]<<endl;
base_pow[i] = base_pow[i - 1] * base % mod;
}
}
int between(int a, int b) {
return (mod + hash[b] - hash[a] * base_pow[b - a] % mod) % mod;
}
};
signed main(void) {
///以下 https://atcoder.jp/contests/abc141/submissions/7525999 お借りします
int N;
string S;
cin >> N >> S;
int ok = 0, ng = N / 2 + 1;
RollingHash rh1(S, 1007, 1e9 + 7), rh2(S, 2009, 1e9 + 9);
while (ng - ok > 1) {
int len = (ng + ok) / 2;
set<pair<int64_t, int64_t>> val;
vector<pair<int64_t, int64_t>> v(N);
bool success = false;
for (int i = 0; i + len <= N; i++) {
if (i >= len)
val.insert(v[i - len]);
v[i] = {rh1.between(i, i + len), rh2.between(i, i + len)};
if (val.count(v[i])) {
success = true;
break;
}
}
(success ? ok : ng) = len;
}
cout << ok << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int(i) = ((n)-1); (i) >= 0; (i)--)
#define itn int
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
struct RollingHash {
vector<int> hash, base_pow;
int base = 1009, mod = 1e+7;
RollingHash(string S = "", /*vector <int> S*/ int basetmp = -1,
int modtmp = -1) {
if (modtmp != -1)
mod = modtmp;
if (basetmp != -1)
base = basetmp;
// cout<<mod<<' '<<base<<endl;
//////
int n = S.size();
vector<int> z(n);
rep(i, n) z[i] = S[i];
hash.resize(n + 1);
base_pow.resize(n + 1);
hash[0] = 0, base_pow[0] = 1;
for (int i = 1; i <= z.size(); i++) {
hash[i] = (hash[i - 1] * base + z[i - 1]) % mod;
base_pow[i] = base_pow[i - 1] * base % mod;
}
}
/*void initialize(vector<int>& S){
hash.resize(S.size()+1);
base_pow.resize(S.size()+1);
hash[0] = 0;
base_pow[0] = 1;
for(int i=1; i<=S.size(); i++){
hash[i] = (hash[i-1] * base + S[i-1]) % mod;
base_pow[i] = base_pow[i-1] * base % mod;
}
}*/
int between(int a, int b) {
return (mod + hash[b] - hash[a] * base_pow[b - a] % mod) % mod;
}
};
signed main(void) {
///以下 https://atcoder.jp/contests/abc141/submissions/7525999 お借りします
int N;
string S;
cin >> N >> S;
int ok = 0, ng = N / 2 + 1;
RollingHash rh1(S, 1007, 1e9 + 7), rh2(S, 2009, 1e9 + 9);
while (ng - ok > 1) {
int len = (ng + ok) / 2;
set<pair<int64_t, int64_t>> val;
vector<pair<int64_t, int64_t>> v(N);
bool success = false;
for (int i = 0; i + len <= N; i++) {
if (i >= len)
val.insert(v[i - len]);
v[i] = {rh1.between(i, i + len), rh2.between(i, i + len)};
if (val.count(v[i])) {
success = true;
break;
}
}
(success ? ok : ng) = len;
}
cout << ok << endl;
return 0;
}
|
[
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 729,143
| 729,144
|
u616029737
|
cpp
|
p02913
|
#include <bits/stdc++.h>
using namespace std;
uint64_t randint() {
static int64_t seed = chrono::duration_cast<chrono::milliseconds>(
chrono::system_clock::now().time_since_epoch())
.count();
static mt19937_64 rnd(seed);
return rnd();
}
template <int64_t mod = int64_t(1e9 + 7)> struct RollingHash {
vector<int64_t> hash;
vector<int64_t> base_pow;
int64_t base;
RollingHash(string S = "", int64_t base = -1) : base(base) {
if (base < 0)
base = 1000 + randint() % 10000;
if (S.size() > 0)
initialize(S);
}
void initialize(string &S) {
int N = S.size();
vector<int> s(N);
for (int i = 0; i < N; i++)
s[i] = S[i];
initialize(s);
}
void initialize(vector<int> &S) {
int sz = S.size();
hash.resize(sz + 1);
base_pow.resize(sz + 1);
hash[0] = 0;
base_pow[0] = 1;
for (int i = 1; i <= sz; i++) {
hash[i] = (hash[i - 1] * base + S[i - 1]) % mod;
base_pow[i] = base_pow[i - 1] * base % mod;
}
}
// 0-indexed, [a, b)
int64_t between(int a, int b) {
return (mod + hash[b] - hash[a] * base_pow[b - a] % mod) % mod;
}
};
int main() {
int N;
string S;
cin >> N >> S;
int ok = 0, ng = N / 2 + 1;
RollingHash<> rh1(S);
RollingHash<int64_t(1e9 + 9)> rh2(S);
while (ng - ok > 1) {
int len = (ng + ok) / 2;
set<pair<int64_t, int64_t>> val;
vector<pair<int64_t, int64_t>> v(N);
bool success = false;
for (int i = 0; i + len <= N; i++) {
if (i >= len)
val.insert(v[i - len]);
v[i] = {rh1.between(i, i + len), rh2.between(i, i + len)};
if (val.count(v[i])) {
success = true;
break;
}
}
(success ? ok : ng) = len;
}
cout << ok << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
uint64_t randint() {
static int64_t seed = chrono::duration_cast<chrono::milliseconds>(
chrono::system_clock::now().time_since_epoch())
.count();
static mt19937_64 rnd(seed);
return rnd();
}
template <int64_t mod = int64_t(1e9 + 7)> struct RollingHash {
vector<int64_t> hash;
vector<int64_t> base_pow;
int64_t base;
RollingHash(string S = "", int64_t base_ = -1) : base(base_) {
if (base < 0)
base = 1000 + randint() % 10000;
if (S.size() > 0)
initialize(S);
}
void initialize(string &S) {
int N = S.size();
vector<int> s(N);
for (int i = 0; i < N; i++)
s[i] = S[i];
initialize(s);
}
void initialize(vector<int> &S) {
int sz = S.size();
hash.resize(sz + 1);
base_pow.resize(sz + 1);
hash[0] = 0;
base_pow[0] = 1;
for (int i = 1; i <= sz; i++) {
hash[i] = (hash[i - 1] * base + S[i - 1]) % mod;
base_pow[i] = base_pow[i - 1] * base % mod;
}
}
// 0-indexed, [a, b)
int64_t between(int a, int b) {
return (mod + hash[b] - hash[a] * base_pow[b - a] % mod) % mod;
}
};
int main() {
int N;
string S;
cin >> N >> S;
int ok = 0, ng = N / 2 + 1;
RollingHash<> rh1(S);
RollingHash<int64_t(1e9 + 9)> rh2(S);
while (ng - ok > 1) {
int len = (ng + ok) / 2;
set<pair<int64_t, int64_t>> val;
vector<pair<int64_t, int64_t>> v(N);
bool success = false;
for (int i = 0; i + len <= N; i++) {
if (i >= len)
val.insert(v[i - len]);
v[i] = {rh1.between(i, i + len), rh2.between(i, i + len)};
if (val.count(v[i])) {
success = true;
break;
}
}
(success ? ok : ng) = len;
}
cout << ok << endl;
return 0;
}
|
[
"identifier.change",
"call.arguments.change"
] | 729,151
| 729,152
|
u314396879
|
cpp
|
p02913
|
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------
int N;
string S;
int dp[5050];
void solve() {
int i, j, k, l, r, x, y;
string s;
cin >> N >> S;
int ma = 0;
for (int len = N / 2; len >= 1; len--) {
ZERO(dp);
for (x = N - len - 1; x >= 0; x--) {
if (S[x] != S[x + len])
dp[x] = 0;
else
dp[x] = min(dp[x + 1] + 1, len);
ma = max(ma, dp[x]);
}
}
cout << ma << endl;
}
int main(int argc, char **argv) {
string s;
int i;
if (argc == 1)
ios::sync_with_stdio(false), cin.tie(0);
FOR(i, argc - 1) s += argv[i + 1], s += '\n';
FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
cout.tie(0);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------
int N;
string S;
int dp[5050];
void solve() {
int i, j, k, l, r, x, y;
string s;
cin >> N >> S;
int ma = 0;
for (int len = N; len >= 1; len--) {
ZERO(dp);
for (x = N - len - 1; x >= 0; x--) {
if (S[x] != S[x + len])
dp[x] = 0;
else
dp[x] = min(dp[x + 1] + 1, len);
ma = max(ma, dp[x]);
}
}
cout << ma << endl;
}
int main(int argc, char **argv) {
string s;
int i;
if (argc == 1)
ios::sync_with_stdio(false), cin.tie(0);
FOR(i, argc - 1) s += argv[i + 1], s += '\n';
FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
cout.tie(0);
solve();
return 0;
}
|
[
"control_flow.loop.for.initializer.change",
"expression.operation.binary.remove"
] | 729,155
| 729,156
|
u452725238
|
cpp
|
p02913
|
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------
int N;
string S;
int dp[5050];
void solve() {
int i, j, k, l, r, x, y;
string s;
cin >> N >> S;
int ma = 0;
for (int len = N / 2; len >= 1; len--) {
ZERO(dp);
for (x = N - len; x >= 0; x--) {
if (S[x] != S[x + len])
dp[x] = 0;
else
dp[x] = min(dp[x + 1] + 1, len);
ma = max(ma, dp[x]);
}
}
cout << ma << endl;
}
int main(int argc, char **argv) {
string s;
int i;
if (argc == 1)
ios::sync_with_stdio(false), cin.tie(0);
FOR(i, argc - 1) s += argv[i + 1], s += '\n';
FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
cout.tie(0);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x, to) for (x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
//-------------------------------------------------------
int N;
string S;
int dp[5050];
void solve() {
int i, j, k, l, r, x, y;
string s;
cin >> N >> S;
int ma = 0;
for (int len = N; len >= 1; len--) {
ZERO(dp);
for (x = N - len - 1; x >= 0; x--) {
if (S[x] != S[x + len])
dp[x] = 0;
else
dp[x] = min(dp[x + 1] + 1, len);
ma = max(ma, dp[x]);
}
}
cout << ma << endl;
}
int main(int argc, char **argv) {
string s;
int i;
if (argc == 1)
ios::sync_with_stdio(false), cin.tie(0);
FOR(i, argc - 1) s += argv[i + 1], s += '\n';
FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin);
cout.tie(0);
solve();
return 0;
}
|
[
"control_flow.loop.for.initializer.change",
"expression.operation.binary.remove",
"assignment.change"
] | 729,157
| 729,156
|
u452725238
|
cpp
|
p02913
|
#include <bits/stdc++.h>
#define loop(n, i) for (int i = 0; i < n; i++)
#define loop1(n, i) for (int i = 1; i <= n; i++)
#define rloop(n, i) for (int i = n; i; i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
const long long mod1 = 999999937LL, mod2 = 1000000007LL, base = 9973;
int main() {
int n;
cin >> n;
string S;
cin >> S;
V<ll> hash1(n), hash2(n);
loop(n, i) {
hash1[i] = S[i];
hash2[i] = S[i];
}
int l = 0, r = n;
while (r - l > 1) {
int i = (l + r) / 2;
int found = 0;
unordered_set<ll> set1, set2;
ll pow1 = 1, pow2 = 1;
loop(i, j) {
pow1 = (pow1 * base) % mod1;
pow2 = (pow2 * base) % mod2;
}
hash1[0] = S[0] % mod1;
hash2[0] = S[0] % mod2;
loop1(n, j) {
hash1[j] = (hash1[j - 1] * base + S[j]) % mod1;
hash2[j] = (hash2[j - 1] * base + S[j]) % mod2;
if (j - i >= 0) {
hash1[j] -= (S[j - i] * pow1) % mod1;
hash1[j] = (hash1[j] + mod1) % mod1;
hash2[j] -= (S[j - i] * pow2) % mod2;
hash2[j] = (hash2[j] + mod2) % mod2;
}
}
for (int j = i; j < n; j++) {
set1.insert(hash1[j - i]);
set2.insert(hash2[j - i]);
if (set1.find(hash1[j]) != set1.end() &&
set2.find(hash2[j]) != set2.end()) {
found = 1;
}
}
if (found)
l = i;
else
r = i;
}
cout << l << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define loop(n, i) for (int i = 0; i < n; i++)
#define loop1(n, i) for (int i = 1; i <= n; i++)
#define rloop(n, i) for (int i = n; i; i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;
const long long mod1 = 999999937LL, mod2 = 1000000007LL, base = 9973;
int main() {
int n;
cin >> n;
string S;
cin >> S;
V<ll> hash1(n), hash2(n);
loop(n, i) {
hash1[i] = S[i];
hash2[i] = S[i];
}
int l = 0, r = n;
while (r - l > 1) {
int i = (l + r) / 2;
int found = 0;
unordered_set<ll> set1, set2;
ll pow1 = 1, pow2 = 1;
loop(i, j) {
pow1 = (pow1 * base) % mod1;
pow2 = (pow2 * base) % mod2;
}
hash1[0] = S[0] % mod1;
hash2[0] = S[0] % mod2;
loop1(n - 1, j) {
hash1[j] = (hash1[j - 1] * base + S[j]) % mod1;
hash2[j] = (hash2[j - 1] * base + S[j]) % mod2;
if (j - i >= 0) {
hash1[j] -= (S[j - i] * pow1) % mod1;
hash1[j] = (hash1[j] + mod1) % mod1;
hash2[j] -= (S[j - i] * pow2) % mod2;
hash2[j] = (hash2[j] + mod2) % mod2;
}
}
for (int j = i; j < n; j++) {
set1.insert(hash1[j - i]);
set2.insert(hash2[j - i]);
if (set1.find(hash1[j]) != set1.end() &&
set2.find(hash2[j]) != set2.end()) {
found = 1;
}
}
if (found)
l = i;
else
r = i;
}
cout << l << endl;
return 0;
}
|
[
"expression.operation.binary.add"
] | 729,162
| 729,163
|
u581122825
|
cpp
|
p02913
|
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//#define int ll
typedef vector<vector<pair<int, int>>> vvp;
typedef vector<pair<int, int>> vp;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<double>> vvd;
typedef vector<double> vd;
typedef vector<vector<bool>> vvb;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
#define rep(i, s, n) for (int i = (s); i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define yn(f) (f ? "yes" : "no")
#define YN(f) (f ? "YES" : "NO")
#define Yn(f) (f ? "Yes" : "No")
#define len(x) int(x.size())
#define inf (1000000007)
#define ll_inf (1000000000000000007)
#define nil -1
void puts() { cout << endl; }
template <class Head, class... Tail> void puts(Head &&head, Tail &&...tail) {
cout << head;
if (sizeof...(tail) == 0) {
cout << endl;
} else {
cout << " ";
puts(forward<Tail>(tail)...);
}
}
void puts(vector<pair<int, int>> &A) {
for (int i = 0; i < A.size(); i++) {
cout << "(" << A[i].first << "," << A[i].second << ")";
if (A.size() - 1 == i) {
cout << endl;
} else {
cout << " ";
}
}
}
void puts(vector<vector<pair<int, int>>> &A) {
for (int i = 0; i < A.size(); i++) {
puts(A[i]);
}
}
template <class T> void puts(vector<T> &A) {
for (int i = 0; i < A.size(); i++) {
cout << A[i];
if (A.size() - 1 == i) {
cout << endl;
} else {
cout << " ";
}
}
}
template <class T> void puts(vector<vector<T>> &A) {
for (int i = 0; i < A.size(); i++) {
puts(A[i]);
}
}
class disjoint_set {
public:
vi p, rank;
disjoint_set(int size) {
p.resize(size, 0);
rank.resize(size, 0);
for (int i = 0; i < size; i++)
makeSet(i);
}
void makeSet(int x) {
p[x] = x;
rank[x] = 0;
}
bool same(int x, int y) { return findSet(x) == findSet(y); }
void unite(int x, int y) { link(findSet(x), findSet(y)); }
void link(int x, int y) {
if (rank[x] < rank[y]) {
p[x] = y;
} else {
p[y] = x;
if (rank[x] == rank[y]) {
rank[x]++;
}
}
}
int findSet(int x) {
if (x != p[x]) {
p[x] = findSet(p[x]);
}
return p[x];
}
};
int gcd(int a, int b) { // log N
return (b == 0) ? a : gcd(b, a % b);
}
int lcm(int a, int b) { // log N
return (a * b) / gcd(a, b);
}
int extgcd(int a, int b, int &x, int &y) { // log N
int d = a;
if (b == 0) {
x = 1;
y = 0;
} else {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
}
return d;
}
vi get_primes(int limit) { // N log N
vb A(limit + 1, true);
for (int i = 2; i < A.size(); i++) {
if (!A[i])
continue;
for (int j = i * 2; j < A.size(); j += i)
A[j] = false;
}
vi B;
for (int i = 2; i < A.size(); i++) {
if (A[i])
B.push_back(i);
}
return B;
}
bool is_prime(int num) { // sqrt(N)
if (num < 2)
return false;
for (int i = 2; i <= sqrt(num); i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
ll merge_count(vi &A) { // N log N
int n = A.size();
if (n <= 1)
return 0;
long long count = 0;
int mid = n / 2;
vector<int> B(A.begin(), A.begin() + mid);
vector<int> C(A.begin() + mid, A.end());
count += merge_count(B);
count += merge_count(C);
B.push_back(inf);
C.push_back(inf);
int B_i = 0;
int C_i = 0;
for (int i = 0; i < n; i++) {
if (B[B_i] <= C[C_i]) {
A[i] = B[B_i++];
} else {
count += (n / 2) - B_i;
A[i] = C[C_i++];
}
}
return count;
}
vvi bit(int size) { // 2**N
vvi A;
for (int i = 0; i < (1 << size); i++) {
vi temp;
for (int j = 0; j < size; j++) {
if ((i & (1 << (size - j - 1))) > 0) {
temp.push_back(1);
} else {
temp.push_back(0);
}
}
A.push_back(temp);
}
return A;
}
vvi bit(int size, int min, int max) { //長さがsizeで、1の個数がmin以上max以下のものを全列挙して返す
//2**N
vvi A;
for (int i = 0; i < (1 << size); i++) {
vi temp;
int count = 0;
for (int j = 0; j < size; j++) {
if ((i & (1 << (size - j - 1))) > 0) {
temp.push_back(1);
count++;
} else {
temp.push_back(0);
}
}
if (min <= count && count <= max)
A.push_back(temp);
}
return A;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
vvi A(n, vi(n));
for (int i = n - 1; i >= 0; i--) {
for (int j = n - 1; j >= 0; j--) {
if (i == n - 1 || j == n - 1) {
if (s[i] == s[j]) {
A[i][j] = 1;
}
} else {
if (s[i] == s[j])
A[i][j] = A[i + 1][j + 1] + 1;
else
A[i][j] = 0;
}
}
}
ll max_ = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
max_ = min(A[i][j], abs(j - i));
}
}
puts(max_);
}
|
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//#define int ll
typedef vector<vector<pair<int, int>>> vvp;
typedef vector<pair<int, int>> vp;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<double>> vvd;
typedef vector<double> vd;
typedef vector<vector<bool>> vvb;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
#define rep(i, s, n) for (int i = (s); i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define yn(f) (f ? "yes" : "no")
#define YN(f) (f ? "YES" : "NO")
#define Yn(f) (f ? "Yes" : "No")
#define len(x) int(x.size())
#define inf (1000000007)
#define ll_inf (1000000000000000007)
#define nil -1
void puts() { cout << endl; }
template <class Head, class... Tail> void puts(Head &&head, Tail &&...tail) {
cout << head;
if (sizeof...(tail) == 0) {
cout << endl;
} else {
cout << " ";
puts(forward<Tail>(tail)...);
}
}
void puts(vector<pair<int, int>> &A) {
for (int i = 0; i < A.size(); i++) {
cout << "(" << A[i].first << "," << A[i].second << ")";
if (A.size() - 1 == i) {
cout << endl;
} else {
cout << " ";
}
}
}
void puts(vector<vector<pair<int, int>>> &A) {
for (int i = 0; i < A.size(); i++) {
puts(A[i]);
}
}
template <class T> void puts(vector<T> &A) {
for (int i = 0; i < A.size(); i++) {
cout << A[i];
if (A.size() - 1 == i) {
cout << endl;
} else {
cout << " ";
}
}
}
template <class T> void puts(vector<vector<T>> &A) {
for (int i = 0; i < A.size(); i++) {
puts(A[i]);
}
}
class disjoint_set {
public:
vi p, rank;
disjoint_set(int size) {
p.resize(size, 0);
rank.resize(size, 0);
for (int i = 0; i < size; i++)
makeSet(i);
}
void makeSet(int x) {
p[x] = x;
rank[x] = 0;
}
bool same(int x, int y) { return findSet(x) == findSet(y); }
void unite(int x, int y) { link(findSet(x), findSet(y)); }
void link(int x, int y) {
if (rank[x] < rank[y]) {
p[x] = y;
} else {
p[y] = x;
if (rank[x] == rank[y]) {
rank[x]++;
}
}
}
int findSet(int x) {
if (x != p[x]) {
p[x] = findSet(p[x]);
}
return p[x];
}
};
int gcd(int a, int b) { // log N
return (b == 0) ? a : gcd(b, a % b);
}
int lcm(int a, int b) { // log N
return (a * b) / gcd(a, b);
}
int extgcd(int a, int b, int &x, int &y) { // log N
int d = a;
if (b == 0) {
x = 1;
y = 0;
} else {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
}
return d;
}
vi get_primes(int limit) { // N log N
vb A(limit + 1, true);
for (int i = 2; i < A.size(); i++) {
if (!A[i])
continue;
for (int j = i * 2; j < A.size(); j += i)
A[j] = false;
}
vi B;
for (int i = 2; i < A.size(); i++) {
if (A[i])
B.push_back(i);
}
return B;
}
bool is_prime(int num) { // sqrt(N)
if (num < 2)
return false;
for (int i = 2; i <= sqrt(num); i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
ll merge_count(vi &A) { // N log N
int n = A.size();
if (n <= 1)
return 0;
long long count = 0;
int mid = n / 2;
vector<int> B(A.begin(), A.begin() + mid);
vector<int> C(A.begin() + mid, A.end());
count += merge_count(B);
count += merge_count(C);
B.push_back(inf);
C.push_back(inf);
int B_i = 0;
int C_i = 0;
for (int i = 0; i < n; i++) {
if (B[B_i] <= C[C_i]) {
A[i] = B[B_i++];
} else {
count += (n / 2) - B_i;
A[i] = C[C_i++];
}
}
return count;
}
vvi bit(int size) { // 2**N
vvi A;
for (int i = 0; i < (1 << size); i++) {
vi temp;
for (int j = 0; j < size; j++) {
if ((i & (1 << (size - j - 1))) > 0) {
temp.push_back(1);
} else {
temp.push_back(0);
}
}
A.push_back(temp);
}
return A;
}
vvi bit(int size, int min, int max) { //長さがsizeで、1の個数がmin以上max以下のものを全列挙して返す
//2**N
vvi A;
for (int i = 0; i < (1 << size); i++) {
vi temp;
int count = 0;
for (int j = 0; j < size; j++) {
if ((i & (1 << (size - j - 1))) > 0) {
temp.push_back(1);
count++;
} else {
temp.push_back(0);
}
}
if (min <= count && count <= max)
A.push_back(temp);
}
return A;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
vvi A(n, vi(n));
for (int i = n - 1; i >= 0; i--) {
for (int j = n - 1; j >= 0; j--) {
if (i == n - 1 || j == n - 1) {
if (s[i] == s[j]) {
A[i][j] = 1;
}
} else {
if (s[i] == s[j])
A[i][j] = A[i + 1][j + 1] + 1;
else
A[i][j] = 0;
}
}
}
int max_ = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
max_ = max(max_, min(A[i][j], abs(j - i)));
}
}
puts(max_);
}
|
[
"variable_declaration.type.change",
"call.add",
"call.arguments.change"
] | 729,164
| 729,165
|
u902151549
|
cpp
|
p02913
|
#include <stdio.h>
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define MIN(x, y) ((x) < (y) ? (x) : (y))
int n;
char S[5000];
int dp[5000][5000];
int main() {
int i, j, r;
scanf("%d", &n);
scanf("%s", S);
for (j = 1; j < n; j++)
dp[0][j] = S[0] == S[j];
for (i = 1; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (S[i] == S[j])
dp[i][j] = dp[i - 1][j - 1] + 1;
}
}
r = 0;
for (i = 1; i < n; i++) {
for (j = i + 1; j < n; j++) {
int x = MIN(j - i, dp[i][j]);
r = MAX(r, x);
}
}
printf("%d\n", r);
return 0;
}
|
#include <stdio.h>
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define MIN(x, y) ((x) < (y) ? (x) : (y))
int n;
char S[5001];
int dp[5000][5000];
int main() {
int i, j, r;
scanf("%d", &n);
scanf("%s", S);
for (j = 1; j < n; j++)
dp[0][j] = S[0] == S[j];
for (i = 1; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (S[i] == S[j])
dp[i][j] = dp[i - 1][j - 1] + 1;
}
}
r = 0;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
int x = MIN(j - i, dp[i][j]);
r = MAX(r, x);
}
}
printf("%d\n", r);
return 0;
}
|
[
"literal.number.change",
"variable_declaration.array_dimensions.change",
"assignment.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 729,168
| 729,167
|
u367021138
|
cpp
|
p02913
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define base 26
int n;
string s;
#define MAXN (int)(5e3 + 233)
unsigned long long h[MAXN];
long long power[MAXN];
unsigned long long lstans;
#define gethash(l, r) (h[r] - h[l - 1] * power[r - l + 1])
int main() {
scanf("%d", &n);
cin >> s;
power[0] = 1;
for (int i = 0; i < n; i++)
h[i + 1] = h[i] * base + s[i + 1], power[i + 1] = power[i] * base;
// for (int i=1;i<=n;i++) printf(":%lld ",h[i]);
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (i + ans <= j)
while (i + ans < j && j + ans <= n &&
gethash(i, i + ans) == gethash(j, j + ans))
ans++;
printf("%d\n", ans);
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define base 37
int n;
string s;
#define MAXN (int)(5e3 + 233)
unsigned long long h[MAXN];
unsigned long long power[MAXN];
unsigned long long lstans;
#define gethash(l, r) (h[r] - h[l - 1] * power[r - l + 1])
int main() {
scanf("%d", &n);
cin >> s;
power[0] = 1;
for (int i = 0; i < n; i++)
h[i + 1] = h[i] * base + s[i], power[i + 1] = power[i] * base;
// for (int i=1;i<=n;i++) printf(":%lld ",h[i]);
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (i + ans <= j)
while (i + ans < j && j + ans <= n &&
gethash(i, i + ans) == gethash(j, j + ans))
ans++;
printf("%d\n", ans);
return 0;
}
|
[
"preprocessor.define.value.change",
"literal.integer.change",
"variable_declaration.type.widen.change",
"expression.operation.binary.remove"
] | 729,172
| 729,170
|
u582434836
|
cpp
|
p02913
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define base 377
int n;
string s;
#define MAXN (int)(5e3 + 233)
unsigned long long h[MAXN];
long long power[MAXN];
unsigned long long lstans;
#define gethash(l, r) (h[r] - h[l - 1] * power[r - l + 1])
int main() {
scanf("%d", &n);
cin >> s;
power[0] = 1;
for (int i = 0; i < n; i++)
h[i + 1] = h[i] * base + s[i + 1], power[i + 1] = power[i] * base;
// for (int i=1;i<=n;i++) printf(":%lld ",h[i]);
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (i + ans <= j)
while (i + ans < j && j + ans <= n &&
gethash(i, i + ans) == gethash(j, j + ans))
ans++;
printf("%d\n", ans);
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define base 37
int n;
string s;
#define MAXN (int)(5e3 + 233)
unsigned long long h[MAXN];
unsigned long long power[MAXN];
unsigned long long lstans;
#define gethash(l, r) (h[r] - h[l - 1] * power[r - l + 1])
int main() {
scanf("%d", &n);
cin >> s;
power[0] = 1;
for (int i = 0; i < n; i++)
h[i + 1] = h[i] * base + s[i], power[i + 1] = power[i] * base;
// for (int i=1;i<=n;i++) printf(":%lld ",h[i]);
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (i + ans <= j)
while (i + ans < j && j + ans <= n &&
gethash(i, i + ans) == gethash(j, j + ans))
ans++;
printf("%d\n", ans);
return 0;
}
|
[
"preprocessor.define.value.change",
"literal.integer.change",
"variable_declaration.type.widen.change",
"expression.operation.binary.remove"
] | 729,173
| 729,170
|
u582434836
|
cpp
|
p02913
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define base 7
int n;
string s;
#define MAXN (int)(5e3 + 233)
unsigned long long h[MAXN];
long long power[MAXN];
unsigned long long lstans;
#define gethash(l, r) (h[r] - h[l - 1] * power[r - l + 1])
int main() {
scanf("%d", &n);
cin >> s;
power[0] = 1;
for (int i = 0; i < n; i++)
h[i + 1] = h[i] * base + s[i + 1], power[i + 1] = power[i] * base;
// for (int i=1;i<=n;i++) printf(":%lld ",h[i]);
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (i + ans <= j)
while (i + ans < j && j + ans <= n &&
gethash(i, i + ans) == gethash(j, j + ans))
ans++;
printf("%d\n", ans);
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define base 37
int n;
string s;
#define MAXN (int)(5e3 + 233)
unsigned long long h[MAXN];
unsigned long long power[MAXN];
unsigned long long lstans;
#define gethash(l, r) (h[r] - h[l - 1] * power[r - l + 1])
int main() {
scanf("%d", &n);
cin >> s;
power[0] = 1;
for (int i = 0; i < n; i++)
h[i + 1] = h[i] * base + s[i], power[i + 1] = power[i] * base;
// for (int i=1;i<=n;i++) printf(":%lld ",h[i]);
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (i + ans <= j)
while (i + ans < j && j + ans <= n &&
gethash(i, i + ans) == gethash(j, j + ans))
ans++;
printf("%d\n", ans);
return 0;
}
|
[
"preprocessor.define.value.change",
"literal.integer.change",
"variable_declaration.type.widen.change",
"expression.operation.binary.remove"
] | 729,174
| 729,170
|
u582434836
|
cpp
|
p02913
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define base 37
int n;
string s;
#define MAXN (int)(5e3 + 233)
unsigned long long h[MAXN];
long long power[MAXN];
unsigned long long lstans;
#define gethash(l, r) (h[r] - h[l - 1] * power[r - l + 1])
int main() {
scanf("%d", &n);
cin >> s;
power[0] = 1;
for (int i = 0; i < n; i++)
h[i + 1] = h[i] * base + s[i + 1], power[i + 1] = power[i] * base;
// for (int i=1;i<=n;i++) printf(":%lld ",h[i]);
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (i + ans <= j)
while (i + ans < j && j + ans <= n &&
gethash(i, i + ans) == gethash(j, j + ans))
ans++;
printf("%d\n", ans);
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define base 37
int n;
string s;
#define MAXN (int)(5e3 + 233)
unsigned long long h[MAXN];
unsigned long long power[MAXN];
unsigned long long lstans;
#define gethash(l, r) (h[r] - h[l - 1] * power[r - l + 1])
int main() {
scanf("%d", &n);
cin >> s;
power[0] = 1;
for (int i = 0; i < n; i++)
h[i + 1] = h[i] * base + s[i], power[i + 1] = power[i] * base;
// for (int i=1;i<=n;i++) printf(":%lld ",h[i]);
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (i + ans <= j)
while (i + ans < j && j + ans <= n &&
gethash(i, i + ans) == gethash(j, j + ans))
ans++;
printf("%d\n", ans);
return 0;
}
|
[
"variable_declaration.type.widen.change",
"expression.operation.binary.remove"
] | 729,175
| 729,170
|
u582434836
|
cpp
|
p02913
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define base 37
int n;
string s;
#define MAXN (int)(5e3 + 233)
int h[MAXN];
long long power[MAXN];
unsigned long long lstans;
#define gethash(l, r) (h[r] - h[l - 1] * power[r - l + 1])
int main() {
scanf("%d", &n);
cin >> s;
power[0] = 1;
for (int i = 0; i < n; i++)
h[i + 1] = h[i] * base + s[i + 1], power[i + 1] = power[i] * base;
// for (int i=1;i<=n;i++) printf(":%d ",h[i]);
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (i + ans <= j)
while (i + ans < j && j + ans <= n &&
gethash(i, i + ans) == gethash(j, j + ans))
ans++;
printf("%d\n", ans);
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define base 37
int n;
string s;
#define MAXN (int)(5e3 + 233)
unsigned long long h[MAXN];
unsigned long long power[MAXN];
unsigned long long lstans;
#define gethash(l, r) (h[r] - h[l - 1] * power[r - l + 1])
int main() {
scanf("%d", &n);
cin >> s;
power[0] = 1;
for (int i = 0; i < n; i++)
h[i + 1] = h[i] * base + s[i], power[i + 1] = power[i] * base;
// for (int i=1;i<=n;i++) printf(":%lld ",h[i]);
int ans = 0;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (i + ans <= j)
while (i + ans < j && j + ans <= n &&
gethash(i, i + ans) == gethash(j, j + ans))
ans++;
printf("%d\n", ans);
return 0;
}
|
[
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"expression.operation.binary.remove"
] | 729,176
| 729,170
|
u582434836
|
cpp
|
p02924
|
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
long long n;
void input() { scanf("%I64d", &n); }
void solve() {
--n;
printf("%I64d\n", n * (n + 1) / 2);
}
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
input();
solve();
return 0;
}
|
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
long long n;
void input() { scanf("%lld", &n); }
void solve() {
--n;
printf("%lld\n", n * (n + 1) / 2);
}
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
input();
solve();
return 0;
}
|
[
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 729,185
| 729,186
|
u741945117
|
cpp
|
p02924
|
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>
struct edge {
int to, cost;
};
using P = pair<int, int>;
using PP = pair<P, int>;
const int mod2 = 998244353;
const int mod = (int)1e9 + 7, inf = (int)1e16;
int modpow(int x, int n) {
int ans = 1;
while (n > 0) {
if (n & 1) {
ans *= x;
if (mod <= ans)
ans %= mod;
}
x *= x;
if (mod <= x)
x %= mod;
n >>= 1;
}
return ans;
}
int fact[1000000];
void f_init(int n) {
if (1000000 <= n)
return;
fact[0] = fact[1] = 1;
for (int i = 2; i <= n; ++i) {
fact[i] *= fact[i - 1];
if (mod <= fact[i])
fact[i] %= mod;
}
return;
}
int comb(int n, int r) {
if (n < r)
return 0;
int ans =
fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
if (ans < 0)
return ans + mod;
return ans;
}
int perm(int n, int r) {
if (n < r)
return 0;
if (n - r < r)
r = n - r;
int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod;
if (ans < 0)
return ans + mod;
return ans;
}
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool pri(int p) {
for (int i = 2; i * i <= p; ++i)
if (p % i == 0)
return false;
return p > 1;
}
map<int, int> factring(int n) {
map<int, int> ans;
for (int i = 2; i * i <= n; ++i) {
while (n % i == 0) {
n /= i;
++ans[i];
}
}
if (n != 1)
++ans[n];
return ans;
}
P operator+(const P &a, const P &b) {
return P(a.first + b.first, a.second + b.second);
}
P operator-(const P &a, const P &b) {
return P(a.first - b.first, a.second - b.second);
}
int n;
signed main() {
cin >> n;
cout << n / (n - 1) / 2 << endl;
}
|
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>
struct edge {
int to, cost;
};
using P = pair<int, int>;
using PP = pair<P, int>;
const int mod2 = 998244353;
const int mod = (int)1e9 + 7, inf = (int)1e16;
int modpow(int x, int n) {
int ans = 1;
while (n > 0) {
if (n & 1) {
ans *= x;
if (mod <= ans)
ans %= mod;
}
x *= x;
if (mod <= x)
x %= mod;
n >>= 1;
}
return ans;
}
int fact[1000000];
void f_init(int n) {
if (1000000 <= n)
return;
fact[0] = fact[1] = 1;
for (int i = 2; i <= n; ++i) {
fact[i] *= fact[i - 1];
if (mod <= fact[i])
fact[i] %= mod;
}
return;
}
int comb(int n, int r) {
if (n < r)
return 0;
int ans =
fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
if (ans < 0)
return ans + mod;
return ans;
}
int perm(int n, int r) {
if (n < r)
return 0;
if (n - r < r)
r = n - r;
int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod;
if (ans < 0)
return ans + mod;
return ans;
}
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool pri(int p) {
for (int i = 2; i * i <= p; ++i)
if (p % i == 0)
return false;
return p > 1;
}
map<int, int> factring(int n) {
map<int, int> ans;
for (int i = 2; i * i <= n; ++i) {
while (n % i == 0) {
n /= i;
++ans[i];
}
}
if (n != 1)
++ans[n];
return ans;
}
P operator+(const P &a, const P &b) {
return P(a.first + b.first, a.second + b.second);
}
P operator-(const P &a, const P &b) {
return P(a.first - b.first, a.second - b.second);
}
int n;
signed main() {
cin >> n;
cout << n * (n - 1) / 2 << endl;
}
|
[
"expression.operator.arithmetic.change",
"io.output.change"
] | 729,187
| 729,188
|
u054475353
|
cpp
|
p02924
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int N;
cin >> N;
cout << (N - 1) * N / 2 << std::endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll N;
cin >> N;
cout << (N - 1) * N / 2 << std::endl;
}
|
[
"variable_declaration.type.change"
] | 729,189
| 729,190
|
u580402951
|
cpp
|
p02924
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <functional>
#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;
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
cout << n * (n - 1) / 2 << "\n";
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <functional>
#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;
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n;
cin >> n;
cout << n * (n - 1) / 2LL << "\n";
return 0;
}
|
[
"variable_declaration.type.change",
"literal.number.type.widen.change"
] | 729,191
| 729,192
|
u334624175
|
cpp
|
p02924
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <vector>
using namespace std;
#define rep(s, i, n) for (int i = s; i < n; i++)
#define c(n) cout << n << endl;
#define ic(n) \
int n; \
cin >> n;
#define sc(s) \
string s; \
cin >> s;
#define mod 1000000007
#define F first
#define s second
#define int long long
int x[214514];
double y[214514];
string z[214514];
int sum[214514];
signed main() { ic(n) c((n * (n - 1) / 2) % mod) }
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <vector>
using namespace std;
#define rep(s, i, n) for (int i = s; i < n; i++)
#define c(n) cout << n << endl;
#define ic(n) \
int n; \
cin >> n;
#define sc(s) \
string s; \
cin >> s;
#define mod 1000000007
#define F first
#define s second
#define int long long
int x[214514];
double y[214514];
string z[214514];
int sum[214514];
signed main() { ic(n) c((n * (n - 1) / 2)) }
|
[
"expression.operation.binary.remove"
] | 729,193
| 729,194
|
u942393279
|
cpp
|
p02924
|
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
i64 res = (N) * (N - 1) / 2;
cout << res << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
i64 res = 1LL * N * (N - 1) / 2;
cout << res << "\n";
return 0;
}
|
[
"expression.operation.binary.change"
] | 729,197
| 729,198
|
u959960486
|
cpp
|
p02924
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
const int INF = 1000000000;
int main() {
int n;
cin >> n;
cout << n * (n - 1) / 2 << endl;
}
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
const int INF = 1000000000;
int main() {
long long n;
cin >> n;
cout << n * (n - 1) / 2 << endl;
}
|
[
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 729,201
| 729,202
|
u791146764
|
cpp
|
p02925
|
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
// using namespace atcoder;
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
const double PI = 3.14159265358979323846;
const in MOD = 1000000007;
const in INF = 1e18 + 7;
const int inf = 1e9 + 7;
using P = pair<int, int>;
vector<int> dx = {0, 1, -1, 0};
vector<int> dy = {1, 0, 0, -1};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1, 0));
rep(i, n) rep(j, n - 1) {
cin >> a[i][j];
a[i][j]--;
}
vector<int> now(n, 0);
vector<int> bat(n, false);
int ans = -1;
int cnt = 1;
while (cnt) {
cnt = 0;
bat.resize(n, false);
rep(i, n) {
if (now[i] == n - 1)
continue;
int op = a[i][now[i]];
if (bat[op] || bat[i])
continue;
if (a[op][now[op]] != i)
continue;
cnt++;
now[i]++;
now[op]++;
bat[i] = true;
bat[op] = true;
}
ans++;
}
rep(i, n) {
if (now[i] < n - 1) {
cout << -1 << endl;
return 0;
}
}
cout << ans << endl;
} /*
./problem.exe
*/
|
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
// using namespace atcoder;
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
const double PI = 3.14159265358979323846;
const in MOD = 1000000007;
const in INF = 1e18 + 7;
const int inf = 1e9 + 7;
using P = pair<int, int>;
vector<int> dx = {0, 1, -1, 0};
vector<int> dy = {1, 0, 0, -1};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1, 0));
rep(i, n) rep(j, n - 1) {
cin >> a[i][j];
a[i][j]--;
}
vector<int> now(n, 0);
vector<int> bat(n, false);
int ans = -1;
int cnt = 1;
while (cnt) {
cnt = 0;
bat.assign(n, false);
rep(i, n) {
if (now[i] == n - 1)
continue;
int op = a[i][now[i]];
if (bat[op] || bat[i])
continue;
if (a[op][now[op]] != i)
continue;
cnt++;
now[i]++;
now[op]++;
bat[i] = true;
bat[op] = true;
}
ans++;
}
rep(i, n) {
if (now[i] < n - 1) {
cout << -1 << endl;
return 0;
}
}
cout << ans << endl;
} /*
./problem.exe
*/
|
[
"call.function.change"
] | 729,205
| 729,206
|
u424602097
|
cpp
|
p02925
|
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
// using namespace atcoder;
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
const double PI = 3.14159265358979323846;
const in MOD = 1000000007;
const in INF = 1e18 + 7;
const int inf = 1e9 + 7;
using P = pair<int, int>;
vector<int> dx = {0, 1, -1, 0};
vector<int> dy = {1, 0, 0, -1};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1, 0));
rep(i, n) rep(j, n - 1) {
cin >> a[i][j];
a[i][j]--;
}
vector<int> now(n, 0);
int ans = 0;
int cnt = 1;
while (cnt) {
cnt = 0;
vector<bool> bat(n, false);
rep(i, n) {
if (now[i] == n - 1)
continue;
int op = a[i][now[i]];
if (bat[op] || bat[i])
continue;
if (a[op][now[op]] != i)
continue;
cnt++;
now[i]++;
now[op]++;
bat[i] = true;
bat[op] = true;
}
ans++;
}
rep(i, n) {
if (now[i] < n - 1) {
cout << -1 << endl;
return 0;
}
}
cout << ans << endl;
} /*
./problem.exe
*/
|
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
// using namespace atcoder;
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
const double PI = 3.14159265358979323846;
const in MOD = 1000000007;
const in INF = 1e18 + 7;
const int inf = 1e9 + 7;
using P = pair<int, int>;
vector<int> dx = {0, 1, -1, 0};
vector<int> dy = {1, 0, 0, -1};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1, 0));
rep(i, n) rep(j, n - 1) {
cin >> a[i][j];
a[i][j]--;
}
vector<int> now(n, 0);
int ans = -1;
int cnt = 1;
while (cnt) {
cnt = 0;
vector<bool> bat(n, false);
rep(i, n) {
if (now[i] == n - 1)
continue;
int op = a[i][now[i]];
if (bat[op] || bat[i])
continue;
if (a[op][now[op]] != i)
continue;
cnt++;
now[i]++;
now[op]++;
bat[i] = true;
bat[op] = true;
}
ans++;
}
rep(i, n) {
if (now[i] < n - 1) {
cout << -1 << endl;
return 0;
}
}
cout << ans << endl;
} /*
./problem.exe
*/
|
[
"literal.number.change",
"variable_declaration.value.change"
] | 729,207
| 729,208
|
u424602097
|
cpp
|
p02925
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) \
{ \
for (auto i : x) { \
cout << i << " "; \
} \
cout << endl; \
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int maxN = 1005;
const int maxV = maxN * (maxN - 1) / 2;
vector<int> to[maxV];
int id[maxN][maxN];
int vtoId(int x, int y) {
if (y < x)
swap(x, y);
return id[x][y];
}
bool visited[maxV];
bool calted[maxV];
int dp[maxV]; // max length
int dfs(int x) {
if (visited[x]) {
if (!calted[x])
return -1;
else
return dp[x];
}
dp[x] = 1;
visited[x] = true;
for (int a : to[x]) {
int y = dfs(a);
if (y == -1)
return -1;
dp[x] = max(dp[x], y + 1);
}
calted[x] = true;
return dp[x];
}
int main() {
// DAG, 閉路検出、最長パス
int N;
cin >> N;
int V = 0;
rep(j, N) rep(i, j) { id[i][j] = V++; }
vector<vector<int>> A(N, vector<int>(N - 1));
rep(i, N) {
rep(j, N - 1) {
cin >> A[i][j];
--A[i][j];
A[i][j] = vtoId(i, A[i][j]);
}
rep(j, N - 2) { to[A[i][j + 1]].push_back(A[i][j]); }
}
int ans = 0;
rep(i, N) {
int x = dfs(i);
if (x == -1) {
cout << -1 << '\n';
return 0;
}
ans = max(ans, x);
}
cout << ans << '\n';
return 0;
}
// 36
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) \
{ \
for (auto i : x) { \
cout << i << " "; \
} \
cout << endl; \
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int maxN = 1005;
const int maxV = maxN * (maxN - 1) / 2;
vector<int> to[maxV];
int id[maxN][maxN];
int vtoId(int x, int y) {
if (y < x)
swap(x, y);
return id[x][y];
}
bool visited[maxV];
bool calted[maxV];
int dp[maxV]; // max length
int dfs(int x) {
if (visited[x]) {
if (!calted[x])
return -1;
else
return dp[x];
}
dp[x] = 1;
visited[x] = true;
for (int a : to[x]) {
int y = dfs(a);
if (y == -1)
return -1;
dp[x] = max(dp[x], y + 1);
}
calted[x] = true;
return dp[x];
}
int main() {
// DAG, 閉路検出、最長パス
int N;
cin >> N;
int V = 0;
rep(j, N) rep(i, j) { id[i][j] = V++; }
vector<vector<int>> A(N, vector<int>(N - 1));
rep(i, N) {
rep(j, N - 1) {
cin >> A[i][j];
--A[i][j];
A[i][j] = vtoId(i, A[i][j]);
}
rep(j, N - 2) { to[A[i][j + 1]].push_back(A[i][j]); }
}
int ans = 0;
rep(i, V) {
int x = dfs(i);
if (x == -1) {
cout << -1 << '\n';
return 0;
}
ans = max(ans, x);
}
cout << ans << '\n';
return 0;
}
// 36
|
[] | 729,237
| 729,238
|
u600402037
|
cpp
|
p02925
|
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL << 62;
const int IINF = 1000000000;
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;
}
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
const int MAX_N = 1005;
const int MAX_V = MAX_N * (MAX_N - 1) / 2;
vector<int> to[MAX_V];
int id[MAX_N][MAX_N];
// 自分と対戦相手の行う試合の頂点番号を返す
int toId(int i, int j) {
if (i > j)
swap(i, j);
return id[i][j];
}
bool visited[MAX_V];
bool calculated[MAX_V];
// vからスタートした時の最長経路を格納
int dp[MAX_V];
int dfs(int v) {
if (visited[v]) {
// 計算済みではないのに訪問済みの場合は
// ループが検出されたとして-1とする。
if (!calculated[v])
return -1;
return dp[v];
}
visited[v] = true;
dp[v] = 1;
for (int u : to[v]) {
int res = dfs(u);
// ループ検出された場合は-1を返して終了
if (res == -1)
return -1;
dp[v] = max(dp[v], res + 1);
}
calculated[v] = true;
return dp[v];
}
int main() {
int N;
cin >> N;
// N人がN-1回試合をする。
// Aに入るのは対戦相手
vector<vector<int>> A(N, vector<int>(N - 1));
rep(i, N) {
rep(j, N - 1) {
cin >> A[i][j];
A[i][j]--;
}
}
int v = 0;
// 1つの試合を一つの頂点とみなす。
// i,jの組み合わせにすべて頂点番号を付与
rep(i, N) {
rep(j, N) {
if (i < j) {
id[i][j] = v++;
}
}
}
rep(i, N) {
rep(j, N - 1) {
// A[i][j]を対戦相手から
// 頂点番号に書き換え
A[i][j] = toId(i, A[i][j]);
}
// 頂点がN-1個あるので、N-2個辺を張る。
// 逆向きに辺を張る(逆じゃなくともいいらしい)
rep(j, N - 2) { to[A[i][j + 1]].push_back(A[i][j]); }
}
int ans = 0;
rep(i, N) {
int res = dfs(i);
if (res == -1) {
puts("-1");
return 0;
}
ans = max(ans, res);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL << 62;
const int IINF = 1000000000;
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;
}
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
const int MAX_N = 1005;
const int MAX_V = MAX_N * (MAX_N - 1) / 2;
vector<int> to[MAX_V];
int id[MAX_N][MAX_N];
// 自分と対戦相手の行う試合の頂点番号を返す
int toId(int i, int j) {
if (i > j)
swap(i, j);
return id[i][j];
}
bool visited[MAX_V];
bool calculated[MAX_V];
// vからスタートした時の最長経路を格納
int dp[MAX_V];
int dfs(int v) {
if (visited[v]) {
// 計算済みではないのに訪問済みの場合は
// ループが検出されたとして-1とする。
if (!calculated[v])
return -1;
return dp[v];
}
visited[v] = true;
dp[v] = 1;
for (int u : to[v]) {
int res = dfs(u);
// ループ検出された場合は-1を返して終了
if (res == -1)
return -1;
dp[v] = max(dp[v], res + 1);
}
calculated[v] = true;
return dp[v];
}
int main() {
int N;
cin >> N;
// N人がN-1回試合をする。
// Aに入るのは対戦相手
vector<vector<int>> A(N, vector<int>(N - 1));
rep(i, N) {
rep(j, N - 1) {
cin >> A[i][j];
A[i][j]--;
}
}
int v = 0;
// 1つの試合を一つの頂点とみなす。
// i,jの組み合わせにすべて頂点番号を付与
rep(i, N) {
rep(j, N) {
if (i < j) {
id[i][j] = v++;
}
}
}
rep(i, N) {
rep(j, N - 1) {
// A[i][j]を対戦相手から
// 頂点番号に書き換え
A[i][j] = toId(i, A[i][j]);
}
// 頂点がN-1個あるので、N-2個辺を張る。
// 逆向きに辺を張る(逆じゃなくともいいらしい)
rep(j, N - 2) { to[A[i][j + 1]].push_back(A[i][j]); }
}
int ans = 0;
rep(i, v) {
int res = dfs(i);
if (res == -1) {
puts("-1");
return 0;
}
ans = max(ans, res);
}
cout << ans << endl;
}
|
[] | 729,239
| 729,240
|
u622045059
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1ll << 60;
#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;
//#define DEBUG(x) ;
int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return false;
}
return true;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return false;
}
return true;
}
template <class T> bool chmax(T &a, initializer_list<T> l) {
return chmax(a, *max_element(l.begin(), l.end()));
}
template <class T> bool chmin(T &a, initializer_list<T> l) {
return chmin(a, *min_element(l.begin(), l.end));
}
ll N;
vector<vector<ll>> G;
const ll MAX = 1000 * 1000 + 10;
ll seen[MAX];
ll d[MAX];
ll dfs(ll n) {
if (seen[n] == 2)
return d[n];
seen[n] = 1;
for (auto &nv : G[n]) {
if (seen[nv] == 1) {
std::cout << -1 << std::endl;
exit(0);
}
chmax(d[n], dfs(nv) + 1);
}
seen[n] = 2;
return d[n];
}
int main(int argc, char **argv) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N;
G.resize(N * (N - 1) / 2 + 1);
auto f = [](ll i, ll j) -> ll {
if (i > j)
swap(i, j);
return i * (i - 1) / 2 + j + 1;
};
REP(i, N) {
ll pre = 0;
REP(j, N - 1) {
ll a;
cin >> a;
--a;
ll now = f(i, j);
G[pre].push_back(now);
pre = now;
}
}
std::cout << dfs(0) << std::endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1ll << 60;
#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;
//#define DEBUG(x) ;
int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return false;
}
return true;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return false;
}
return true;
}
template <class T> bool chmax(T &a, initializer_list<T> l) {
return chmax(a, *max_element(l.begin(), l.end()));
}
template <class T> bool chmin(T &a, initializer_list<T> l) {
return chmin(a, *min_element(l.begin(), l.end));
}
ll N;
vector<vector<ll>> G;
const ll MAX = 1000 * 1000 + 10;
ll seen[MAX];
ll d[MAX];
ll dfs(ll n) {
if (seen[n] == 2)
return d[n];
seen[n] = 1;
for (auto &nv : G[n]) {
if (seen[nv] == 1) {
std::cout << -1 << std::endl;
exit(0);
}
chmax(d[n], dfs(nv) + 1);
}
seen[n] = 2;
return d[n];
}
int main(int argc, char **argv) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N;
G.resize(N * (N - 1) / 2 + 1);
auto f = [](ll i, ll j) -> ll {
if (i < j)
swap(i, j);
return i * (i - 1) / 2 + j + 1;
};
REP(i, N) {
ll pre = 0;
REP(j, N - 1) {
ll a;
cin >> a;
--a;
ll now = f(i, a);
G[pre].push_back(now);
pre = now;
}
}
std::cout << dfs(0) << std::endl;
return 0;
}
|
[
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"identifier.change",
"call.arguments.change"
] | 729,245
| 729,246
|
u350072791
|
cpp
|
p02925
|
#include <bits/stdc++.h>
#include <cmath>
const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
// typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;
std::istream &operator>>(std::istream &in, set<int> &o) {
ll a;
in >> a;
o.insert(a);
return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
ll a;
in >> a;
o.push(a);
return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
// std::cout << std::bitset<8>(9);
// const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
#include <iostream>
#include <vector>
using namespace std;
int dfs(vector<vector<int>> &edges, vector<int> &longest, vector<bool> &visited,
vector<bool> &calculated, int to) {
if (visited[to]) {
if (!calculated[to])
return -1;
return longest[to];
}
visited[to] = true;
longest[to] = 0;
for (int next : edges[to]) {
int r = dfs(edges, longest, visited, calculated, next);
if (r == -1)
return -1;
cmax(longest[to], r + 1);
}
calculated[to] = true;
return longest[to];
}
int solve(vector<vector<int>> &edge) {
int ans = -1;
vector<int> longest(edge.size(), 0);
vector<bool> visited(edge.size(), false);
vector<bool> calculated(edge.size(), false);
rep(i, edge.size()) {
int t = dfs(edge, longest, visited, calculated, i);
if (t == -1)
return -1;
cmax(ans, t);
}
return ans;
}
int main() {
// std::ifstream f("C:\\Users\\riku\\Downloads\\b08");
int n;
cin >> n;
vector<vector<int>> match(n, vector<int>(n - 1));
rep(i, n) rep(j, n - 1) cin >> match[i][j];
rep(i, n) rep(j, n - 1) match[i][j]--;
vector<vector<int>> id_table(n, vector<int>(n, -1));
{
vector<P> m;
rep(i, n) {
rep(j, n) {
if (j <= i)
continue;
m.emplace_back(i, j);
}
}
rep(i, m.size()) {
P p = m[i];
id_table[p.first][p.second] = i;
id_table[p.second][p.first] = i;
}
}
auto to_id = [&](int i, int j) { return id_table[i][j]; };
vector<vector<int>> edge(n * (n - 1) / 2);
auto add = [&](int a, int b1, int b2) {
int m1 = to_id(a, b1);
int m2 = to_id(a, b2);
edge[m1].push_back(m2);
};
rep(i, n) {
rep(j, n - 2) { add(i, match[i][j], match[i][j + 1]); }
}
cout << solve(edge) + 1 << endl;
}
|
#include <bits/stdc++.h>
#include <cmath>
const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
// typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;
std::istream &operator>>(std::istream &in, set<int> &o) {
ll a;
in >> a;
o.insert(a);
return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
ll a;
in >> a;
o.push(a);
return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
// std::cout << std::bitset<8>(9);
// const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
#include <iostream>
#include <vector>
using namespace std;
int dfs(vector<vector<int>> &edges, vector<int> &longest, vector<bool> &visited,
vector<bool> &calculated, int to) {
if (visited[to]) {
if (!calculated[to])
return -1;
return longest[to];
}
visited[to] = true;
longest[to] = 0;
for (int next : edges[to]) {
int r = dfs(edges, longest, visited, calculated, next);
if (r == -1)
return -1;
cmax(longest[to], r + 1);
}
calculated[to] = true;
return longest[to];
}
int solve(vector<vector<int>> &edge) {
int ans = -1;
vector<int> longest(edge.size(), 0);
vector<bool> visited(edge.size(), false);
vector<bool> calculated(edge.size(), false);
rep(i, edge.size()) {
int t = dfs(edge, longest, visited, calculated, i);
if (t == -1)
return -1;
cmax(ans, t);
}
return ans + 1;
}
int main() {
// std::ifstream f("C:\\Users\\riku\\Downloads\\b08");
int n;
cin >> n;
vector<vector<int>> match(n, vector<int>(n - 1));
rep(i, n) rep(j, n - 1) cin >> match[i][j];
rep(i, n) rep(j, n - 1) match[i][j]--;
vector<vector<int>> id_table(n, vector<int>(n, -1));
{
vector<P> m;
rep(i, n) {
rep(j, n) {
if (j <= i)
continue;
m.emplace_back(i, j);
}
}
rep(i, m.size()) {
P p = m[i];
id_table[p.first][p.second] = i;
id_table[p.second][p.first] = i;
}
}
auto to_id = [&](int i, int j) { return id_table[i][j]; };
vector<vector<int>> edge(n * (n - 1) / 2);
auto add = [&](int a, int b1, int b2) {
int m1 = to_id(a, b1);
int m2 = to_id(a, b2);
edge[m1].push_back(m2);
};
rep(i, n) {
rep(j, n - 2) { add(i, match[i][j], match[i][j + 1]); }
}
cout << solve(edge) << endl;
}
|
[
"expression.operation.binary.remove"
] | 729,263
| 729,264
|
u564182781
|
cpp
|
p02925
|
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
struct Edge {
long long to;
};
using Graph = vector<vector<Edge>>;
int swap(int i, int j) {
if (i < j)
swap(i, j);
return i * (i - 1) / 2 + j + 1;
}
int abcd[2000000];
int d[2000000];
int a[1005][1005];
int dfs(const Graph &G, int n) {
if (abcd[n] == 2)
return d[n];
abcd[n] = 1;
for (auto e : G[n]) {
if (abcd[e.to] == 1) {
cout << -1 << endl;
exit(0);
}
chmax(d[n], dfs(G, e.to) + 1);
}
abcd[n] = 2;
return d[n];
}
int main() {
long long N;
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++)
cin >> a[i][j];
}
Graph G(N * (N - 1) / 2 + 1);
for (int i = 0; i < N; i++) {
int n = 0;
for (int j = 0; j < N - 1; j++) {
a[i][j]--;
int ne = swap(i, a[i][j]);
G[n].push_back({ne});
n = ne;
}
}
cout << dfs(G, 0) << endl;
return 0;
}
|
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
struct Edge {
long long to;
};
using Graph = vector<vector<Edge>>;
int swaping(int i, int j) {
if (i < j)
swap(i, j);
return i * (i - 1) / 2 + j + 1;
}
int abcd[2000000];
int d[2000000];
int a[1005][1005];
int dfs(const Graph &G, int n) {
if (abcd[n] == 2)
return d[n];
abcd[n] = 1;
for (auto e : G[n]) {
if (abcd[e.to] == 1) {
cout << -1 << endl;
exit(0);
}
chmax(d[n], dfs(G, e.to) + 1);
}
abcd[n] = 2;
return d[n];
}
int main() {
long long N;
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++)
cin >> a[i][j];
}
Graph G(N * (N - 1) / 2 + 1);
for (int i = 0; i < N; i++) {
int n = 0;
for (int j = 0; j < N - 1; j++) {
a[i][j]--;
int ne = swaping(i, a[i][j]);
G[n].push_back({ne});
n = ne;
}
}
cout << dfs(G, 0) << endl;
return 0;
}
|
[
"identifier.change",
"call.function.change"
] | 729,278
| 729,279
|
u530329977
|
cpp
|
p02925
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int MAXN = 1005;
const int MAXV = MAXN * (MAXN - 1) / 2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
int toId(int i, int j) {
if (i > j) {
swap(i, j);
}
return id[i][j];
}
bool visited[MAXV];
bool calculated[MAXV];
int dp[MAXV];
int dfs(int v) {
if (visited[v]) {
if (!calculated[v]) {
return -1;
}
return dp[v];
}
visited[v] = true;
dp[v] = 0;
for (int u : to[v]) {
int res = dfs(u);
if (res == -1) {
return -1;
}
dp[v] = max(dp[v], res + 1);
}
calculated[v] = true;
return dp[v];
}
int main() {
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1));
rep(i, n) {
rep(j, n - 1) {
cin >> a[i][j];
a[i][j]--;
}
}
int V = 0;
rep(i, n) {
rep(j, n) {
if (i < j) {
id[i][j] = V++;
}
}
}
rep(i, n) {
rep(j, n - 1) { a[i][j] = toId(i, a[i][j]); }
rep(j, n - 2) { to[a[i][j]].push_back(a[i][j + 1]); }
}
int ans = 0;
rep(i, V) {
int res = dfs(i);
if (res == -1) {
cout << -1 << endl;
return 0;
}
ans = max(ans, dfs(i));
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int MAXN = 1005;
const int MAXV = MAXN * (MAXN - 1) / 2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
int toId(int i, int j) {
if (i > j) {
swap(i, j);
}
return id[i][j];
}
bool visited[MAXV];
bool calculated[MAXV];
int dp[MAXV];
int dfs(int v) {
if (visited[v]) {
if (!calculated[v]) {
return -1;
}
return dp[v];
}
visited[v] = true;
dp[v] = 1;
for (int u : to[v]) {
int res = dfs(u);
if (res == -1) {
return -1;
}
dp[v] = max(dp[v], res + 1);
}
calculated[v] = true;
return dp[v];
}
int main() {
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1));
rep(i, n) {
rep(j, n - 1) {
cin >> a[i][j];
a[i][j]--;
}
}
int V = 0;
rep(i, n) {
rep(j, n) {
if (i < j) {
id[i][j] = V++;
}
}
}
rep(i, n) {
rep(j, n - 1) { a[i][j] = toId(i, a[i][j]); }
rep(j, n - 2) { to[a[i][j]].push_back(a[i][j + 1]); }
}
int ans = 0;
rep(i, V) {
int res = dfs(i);
if (res == -1) {
cout << -1 << endl;
return 0;
}
ans = max(ans, dfs(i));
}
cout << ans << endl;
return 0;
}
|
[
"literal.number.change",
"assignment.value.change"
] | 729,280
| 729,281
|
u828388155
|
cpp
|
p02925
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int MAXN = 1005;
const int MAXV = MAXN * (MAXN - 1) / 2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
int toId(int i, int j) {
if (i > j) {
swap(i, j);
}
return id[i][j];
}
bool visited[MAXV];
bool calculated[MAXV];
int dp[MAXV];
int dfs(int v) {
if (visited[v]) {
if (!calculated[v]) {
return -1;
}
return dp[v];
}
visited[v] = true;
dp[v] = 0;
for (int u : to[v]) {
int res = dfs(u);
if (res == -1) {
return -1;
}
dp[v] = max(dp[v], res + 1);
}
calculated[v] = true;
return dp[v];
}
int main() {
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1));
rep(i, n) {
rep(j, n - 1) {
cin >> a[i][j];
a[i][j]--;
}
}
int V = 0;
rep(i, n) {
rep(j, n) {
if (i < j) {
id[i][j] = V++;
}
}
}
rep(i, n) {
rep(j, n - 1) { a[i][j] = toId(i, a[i][j]); }
rep(j, n - 2) { to[a[i][j]].push_back(a[i][j + 1]); }
}
int ans = 0;
rep(i, n) {
int res = dfs(i);
if (res == -1) {
cout << -1 << endl;
return 0;
}
ans = max(ans, dfs(i));
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int MAXN = 1005;
const int MAXV = MAXN * (MAXN - 1) / 2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
int toId(int i, int j) {
if (i > j) {
swap(i, j);
}
return id[i][j];
}
bool visited[MAXV];
bool calculated[MAXV];
int dp[MAXV];
int dfs(int v) {
if (visited[v]) {
if (!calculated[v]) {
return -1;
}
return dp[v];
}
visited[v] = true;
dp[v] = 1;
for (int u : to[v]) {
int res = dfs(u);
if (res == -1) {
return -1;
}
dp[v] = max(dp[v], res + 1);
}
calculated[v] = true;
return dp[v];
}
int main() {
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1));
rep(i, n) {
rep(j, n - 1) {
cin >> a[i][j];
a[i][j]--;
}
}
int V = 0;
rep(i, n) {
rep(j, n) {
if (i < j) {
id[i][j] = V++;
}
}
}
rep(i, n) {
rep(j, n - 1) { a[i][j] = toId(i, a[i][j]); }
rep(j, n - 2) { to[a[i][j]].push_back(a[i][j + 1]); }
}
int ans = 0;
rep(i, V) {
int res = dfs(i);
if (res == -1) {
cout << -1 << endl;
return 0;
}
ans = max(ans, dfs(i));
}
cout << ans << endl;
return 0;
}
|
[
"literal.number.change",
"assignment.value.change"
] | 729,282
| 729,281
|
u828388155
|
cpp
|
p02925
|
#include <algorithm> // for next_permutation
#include <bits/stl_numeric.h>
#include <fstream>
#include <iostream>
#include <queue>
#include <vector>
#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;
typedef vector<vector<int>> Graph;
ll solve() {
int N;
cin >> N;
deque<int> a[1010];
//各選手の現在の日程がいつまで埋まっているか
vector<int> step(1010, 0);
int M; //試合回数
REP(i, N) {
REP(i, N - 1) {
int x;
cin >> x;
//選手の試合相手を順番につっこむ
a[i].push_back(x - 1);
}
}
//
M = N * (N - 1) / 2;
queue<int> que;
//全選手つっこむ
REP(i, N) que.push(i);
int num = 0;
while (que.size()) {
int ok = 0;
queue<int> que2;
while (que.size()) {
int i = que.front();
que.pop();
//以下の条件を定めてi == 0から貪欲で行う
//日程が超えていないか 選手が全日程試合を終えていないか
//相手選手の直近で予定している試合相手がiか
//相手選手の日程が超えていないか
if (step[i] <= num && a[i].size() && a[a[i].front()].front() == i &&
step[a[i].front()] <= num) {
//スケジュールを更新
step[i] = step[a[i].front()] = num + 1;
// que2->次の周期の試合日程を組む順 最後にqueとswapする
que2.push(i);
que2.push(a[i].front());
//試合日程の更新が成立したので取り出す
a[a[i].front()].pop_front();
a[i].pop_front();
--M;
}
}
++num;
if (M == 0)
break;
swap(que, que2);
}
int res;
if (M != 0) {
res = -1;
} else {
res = num;
}
return res;
}
int main() { cout << solve() << endl; }
|
#include <algorithm> // for next_permutation
#include <bits/stl_numeric.h>
#include <fstream>
#include <iostream>
#include <queue>
#include <vector>
#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;
typedef vector<vector<int>> Graph;
ll solve() {
int N;
cin >> N;
deque<int> a[1010];
//各選手の現在の日程がいつまで埋まっているか
vector<int> step(1010, 0);
int M; //試合回数
REP(i, N) {
REP(j, N - 1) {
int x;
cin >> x;
//選手の試合相手を順番につっこむ
a[i].push_back(x - 1);
}
}
//
M = N * (N - 1) / 2;
queue<int> que;
//全選手つっこむ
REP(i, N) que.push(i);
int num = 0;
while (que.size()) {
int ok = 0;
queue<int> que2;
while (que.size()) {
int i = que.front();
que.pop();
//以下の条件を定めてi == 0から貪欲で行う
//日程が超えていないか 選手が全日程試合を終えていないか
//相手選手の直近で予定している試合相手がiか
//相手選手の日程が超えていないか
if (step[i] <= num && a[i].size() && a[a[i].front()].front() == i &&
step[a[i].front()] <= num) {
//スケジュールを更新
step[i] = step[a[i].front()] = num + 1;
// que2->次の周期の試合日程を組む順 最後にqueとswapする
que2.push(i);
que2.push(a[i].front());
//試合日程の更新が成立したので取り出す
a[a[i].front()].pop_front();
a[i].pop_front();
--M;
}
}
++num;
if (M == 0)
break;
swap(que, que2);
}
int res;
if (M) {
res = -1;
} else {
res = num;
}
return res;
}
int main() { cout << solve() << endl; }
|
[
"identifier.change",
"call.arguments.change",
"expression.operation.binary.remove"
] | 729,289
| 729,290
|
u485731913
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
int N;
const int MAX_N = 1001;
const int MAX_GAME = MAX_N * MAX_N;
bool visited[MAX_GAME];
bool calced[MAX_GAME];
int day[MAX_GAME];
int get_day(int game, vector<vector<int>> &prev) {
if (visited[game]) {
if (!calced[game])
return -1;
return day[game];
}
visited[game] = true;
day[game] = 1;
for (int prev_game : prev[game]) {
int prev_game_day = get_day(prev_game, prev);
if (prev_game_day == -1)
return -1;
day[game] = max(day[game], prev_game_day);
}
calced[game] = true;
return day[game];
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> N;
vector<vector<int>> A(N, vector<int>(N - 1));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++) {
cin >> A[i][j];
A[i][j]--;
}
}
int index = 0;
vector<vector<int>> game_id(N, vector<int>(N));
for (int i = 0; i < N - 1; i++) {
for (int j = i + 1; j < N; j++) {
game_id[i][j] = index;
game_id[j][i] = index;
index++;
}
}
vector<vector<int>> prev(N * (N - 1) / 2, vector<int>());
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 2; j++) {
prev[game_id[i][A[i][j + 1]]].push_back(game_id[i][A[i][j]]);
}
}
int last = 0;
for (int g = 0; g < N * (N - 1) / 2; g++) {
int day = get_day(g, prev);
if (day == -1) {
cout << -1 << endl;
return 0;
}
last = max(last, day);
}
cout << last << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
int N;
const int MAX_N = 1001;
const int MAX_GAME = MAX_N * MAX_N;
bool visited[MAX_GAME];
bool calced[MAX_GAME];
int day[MAX_GAME];
int get_day(int game, vector<vector<int>> &prev) {
if (visited[game]) {
if (!calced[game])
return -1;
return day[game];
}
visited[game] = true;
day[game] = 1;
for (int prev_game : prev[game]) {
int prev_game_day = get_day(prev_game, prev);
if (prev_game_day == -1)
return -1;
day[game] = max(day[game], prev_game_day + 1);
}
calced[game] = true;
return day[game];
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> N;
vector<vector<int>> A(N, vector<int>(N - 1));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++) {
cin >> A[i][j];
A[i][j]--;
}
}
int index = 0;
vector<vector<int>> game_id(N, vector<int>(N));
for (int i = 0; i < N - 1; i++) {
for (int j = i + 1; j < N; j++) {
game_id[i][j] = index;
game_id[j][i] = index;
index++;
}
}
vector<vector<int>> prev(N * (N - 1) / 2, vector<int>());
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 2; j++) {
prev[game_id[i][A[i][j + 1]]].push_back(game_id[i][A[i][j]]);
}
}
int last = 0;
for (int g = 0; g < N * (N - 1) / 2; g++) {
int day = get_day(g, prev);
if (day == -1) {
cout << -1 << endl;
return 0;
}
last = max(last, day);
}
cout << last << endl;
return 0;
}
|
[
"assignment.change"
] | 729,291
| 729,292
|
u904833081
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxN = 1005;
const int maxV = maxN * (maxN - 1) / 2;
// トポロジカルソートされるグラフ
vector<int> to[maxV];
int id[maxN][maxN];
int toId(int i, int j) {
if (i > j)
swap(i, j);
return id[i][j];
}
bool visited[maxN]; // 関数外の変数については,
// ポインタはnull数値はゼロ値になるらしい.
bool calced[maxN];
int day[maxN];
int dfs(int v) {
if (visited[v]) {
if (!calced[v])
return -1;
return day[v];
}
visited[v] = true;
day[v] = 1;
for (int e : to[v]) {
int dayBefore = dfs(e); // 前回の回の日程を取得している.
if (dayBefore == -1) {
return -1;
}
// vに来るまでにやつ必要があった試合の日付よりも後の日付に設定する
day[v] = max(day[v], dayBefore + 1);
}
calced[v] = true;
return day[v];
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// A_{i, j + 1} は A_{i, j}が終わらないとできない ->
// Aが終わった後にBをしなければならない とき A -> Bとしたグラフを作り,
// そのグラフについてトポロジカルソートみたいなことをやる.
// トポロジカルソートすると同時に, day(B) = day(A) + 1みたいな感じにしておく
int N;
cin >> N;
// 対戦相手の情報をとりあえず入れておくやつ
vector<vector<int>> ops(N, vector<int>(N - 1));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++) {
cin >> ops[i][j];
ops[i][j]--;
}
}
// 次はidを振る
int V;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i >= j)
continue;
id[i][j] = V++;
}
}
// そして試合番号のグラフを作る
// 次のやつをグラフに入れるだけでいい.
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 2; j++) {
// 一つ後の試合番号 ひとつ前の試合番号
to[toId(i, ops[i][j + 1])].push_back(toId(i, ops[i][j]));
}
}
// 次はトポロジカルソートっぽいことをして, 何日目かを得る.
int last = 0;
for (int v = 0; v < V; v++) {
int day = dfs(v);
if (day == -1) {
cout << -1 << endl;
return 0;
}
last = max(last, day);
}
cout << last << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxN = 1005;
const int maxV = maxN * (maxN - 1) / 2;
// トポロジカルソートされるグラフ
vector<int> to[maxV];
int id[maxN][maxN];
int toId(int i, int j) {
if (i > j)
swap(i, j);
return id[i][j];
}
bool visited[maxV]; // 関数外の変数については,
// ポインタはnull数値はゼロ値になるらしい.
bool calced[maxV];
int day[maxV];
int dfs(int v) {
if (visited[v]) {
if (!calced[v])
return -1;
return day[v];
}
visited[v] = true;
day[v] = 1;
// この計算中にまた自分自信に来ることがある. そのときは絶対に完成しないので,
// -1を返す.
for (int e : to[v]) {
int dayBefore = dfs(e); // 前回の回の日程を取得している.
if (dayBefore == -1) {
return -1;
}
// vに来るまでにやつ必要があった試合の日付よりも後の日付に設定する
day[v] = max(day[v], dayBefore + 1);
}
calced[v] = true;
return day[v];
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// A_{i, j + 1} は A_{i, j}が終わらないとできない ->
// Aが終わった後にBをしなければならない とき A -> Bとしたグラフを作り,
// そのグラフについてトポロジカルソートみたいなことをやる.
// トポロジカルソートすると同時に, day(B) = day(A) + 1みたいな感じにしておく
int N;
cin >> N;
// 対戦相手の情報をとりあえず入れておくやつ
vector<vector<int>> ops(N, vector<int>(N - 1));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++) {
cin >> ops[i][j];
ops[i][j]--;
}
}
// 次はidを振る
int V = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i >= j)
continue;
id[i][j] = V++;
}
}
// そして試合番号のグラフを作る
// 次のやつをグラフに入れるだけでいい.
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 2; j++) {
// 一つ後の試合番号 ひとつ前の試合番号
to[toId(i, ops[i][j + 1])].push_back(toId(i, ops[i][j]));
}
}
// 次はトポロジカルソートっぽいことをして, 何日目かを得る.
int last = 0;
for (int v = 0; v < V; v++) {
int day = dfs(v);
if (day == -1) {
cout << -1 << endl;
return 0;
}
last = max(last, day);
}
cout << last << endl;
return 0;
}
|
[
"identifier.change",
"variable_declaration.array_dimensions.change",
"variable_declaration.value.change"
] | 729,295
| 729,294
|
u904833081
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxN = 1005;
const int maxV = maxN * (maxN - 1) / 2;
// トポロジカルソートされるグラフ
vector<int> to[maxV];
int id[maxN][maxN];
int toId(int i, int j) {
if (i > j)
swap(i, j);
return id[i][j];
}
bool visited[maxN]; // 関数外の変数については,
// ポインタはnull数値はゼロ値になるらしい.
bool calced[maxN];
int day[maxN];
int dfs(int v) {
if (visited[v]) {
if (!calced[v])
return -1;
return day[v];
}
visited[v] = true;
day[v] = 1;
for (int e : to[v]) {
int dayBefore = dfs(e); // 前回の回の日程を取得している.
if (dayBefore == -1) {
return -1;
}
// vに来るまでにやつ必要があった試合の日付よりも後の日付に設定する
day[v] = max(day[v], dayBefore + 1);
}
calced[v] = true;
return day[v];
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// A_{i, j + 1} は A_{i, j}が終わらないとできない ->
// Aが終わった後にBをしなければならない とき A -> Bとしたグラフを作り,
// そのグラフについてトポロジカルソートみたいなことをやる.
// トポロジカルソートすると同時に, day(B) = day(A) + 1みたいな感じにしておく
int N;
cin >> N;
// 対戦相手の情報をとりあえず入れておくやつ
vector<vector<int>> ops(N, vector<int>(N - 1));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++) {
cin >> ops[i][j];
ops[i][j]--;
}
}
// 次はidを振る
int V;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i >= j)
continue;
id[i][j] = V++;
}
}
// そして試合番号のグラフを作る
// 次のやつをグラフに入れるだけでいい.
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 2; j++) {
// 一つ後の試合番号 ひとつ前の試合番号
to[toId(i, ops[i][j + 1])].push_back(toId(i, ops[i][j]));
}
}
// 次はトポロジカルソートっぽいことをして, 何日目かを得る.
int last = 0;
for (int v = 0; v < V; v++) {
int day = dfs(v);
if (day == -1) {
cout << -1 << endl;
return 0;
}
last = max(last, day);
}
cout << last << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxN = 1005;
const int maxV = maxN * (maxN - 1) / 2;
// トポロジカルソートされるグラフ
vector<int> to[maxV];
int id[maxN][maxN];
int toId(int i, int j) {
if (i > j)
swap(i, j);
return id[i][j];
}
bool visited[maxV]; // 関数外の変数については,
// ポインタはnull数値はゼロ値になるらしい.
bool calced[maxV];
int day[maxV];
int dfs(int v) {
if (visited[v]) {
if (!calced[v])
return -1;
return day[v];
}
visited[v] = true;
day[v] = 1;
for (int e : to[v]) {
int dayBefore = dfs(e); // 前回の回の日程を取得している.
if (dayBefore == -1) {
return -1;
}
// vに来るまでにやつ必要があった試合の日付よりも後の日付に設定する
day[v] = max(day[v], dayBefore + 1);
}
calced[v] = true;
return day[v];
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// A_{i, j + 1} は A_{i, j}が終わらないとできない ->
// Aが終わった後にBをしなければならない とき A -> Bとしたグラフを作り,
// そのグラフについてトポロジカルソートみたいなことをやる.
// トポロジカルソートすると同時に, day(B) = day(A) + 1みたいな感じにしておく
int N;
cin >> N;
// 対戦相手の情報をとりあえず入れておくやつ
vector<vector<int>> ops(N, vector<int>(N - 1));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++) {
cin >> ops[i][j];
ops[i][j]--;
}
}
// 次はidを振る
int V = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i >= j)
continue;
id[i][j] = V++;
}
}
// そして試合番号のグラフを作る
// 次のやつをグラフに入れるだけでいい.
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 2; j++) {
// 一つ後の試合番号 ひとつ前の試合番号
to[toId(i, ops[i][j + 1])].push_back(toId(i, ops[i][j]));
}
}
// 次はトポロジカルソートっぽいことをして, 何日目かを得る.
int last = 0;
for (int v = 0; v < V; v++) {
int day = dfs(v);
if (day == -1) {
cout << -1 << endl;
return 0;
}
last = max(last, day);
}
cout << last << endl;
return 0;
}
|
[
"identifier.change",
"variable_declaration.array_dimensions.change",
"variable_declaration.value.change"
] | 729,295
| 729,296
|
u904833081
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX
int n, ans[1000];
queue<int> que[1000];
signed main() {
cin >> n;
rep(i, n) rep(j, n - 1) {
int a;
cin >> a;
que[i].push(a - 1);
}
bool f = true;
while (f) {
f = false;
rep(i, n) {
if (que[i].empty())
continue;
int dif = que[i].front();
while (i == que[dif].front()) {
ans[i] = ans[dif] = max(ans[i], ans[dif]) + 1;
que[i].pop();
que[dif].pop();
if (que[i].size())
dif = que[i].front();
f = true;
}
}
}
int trueans = 0;
rep(i, n) {
if (que[i].size()) {
cout << -1 << endl;
return 0;
}
trueans = max(trueans, ans[i]);
}
cout << trueans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX
int n, ans[1000];
queue<int> que[1000];
signed main() {
cin >> n;
rep(i, n) rep(j, n - 1) {
int a;
cin >> a;
que[i].push(a - 1);
}
bool f = true;
while (f) {
f = false;
rep(i, n) {
if (que[i].empty())
continue;
int dif = que[i].front();
while (i == que[dif].front()) {
ans[i] = ans[dif] = max(ans[i], ans[dif]) + 1;
que[i].pop();
que[dif].pop();
if (que[i].size())
dif = que[i].front();
else
break;
f = true;
}
}
}
int trueans = 0;
rep(i, n) {
if (que[i].size()) {
cout << -1 << endl;
return 0;
}
trueans = max(trueans, ans[i]);
}
cout << trueans << endl;
}
|
[
"control_flow.branch.else_if.replace.remove",
"control_flow.branch.if.replace.add"
] | 729,304
| 729,305
|
u721367699
|
cpp
|
p02925
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using VL = vector<ll>;
#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++)
const long long INF = 999999999;
int N, a[1000];
vector<pair<ll, ll>> e[1001][1001];
ll num[1001][1001], d[1001][1001], ans, cnt;
int main() {
cin >> N;
FOR(i, 1, N + 1) {
REP(j, N - 1) {
cin >> a[j];
if (j) {
e[min(i, a[j - 1])][max(i, a[j - 1])].push_back(
{min(i, a[j]), max(i, a[j])});
num[min(i, a[j])][max(i, a[j])]++;
}
}
}
queue<pair<ll, ll>> que;
cnt = 0;
FOR(i, 1, N + 1) FOR(j, 1, N + 1) if (num[i][j] == 0) {
que.push({i, j});
//頂点iからjまでのパスに含まれる頂点の数
d[i][j] = 1;
}
while (!que.empty()) {
ll x = que.front().first, y = que.front().second, nx, ny;
que.pop();
cnt++;
REP(i, e[x][y].size()) {
nx = e[x][y][i].first;
ny = e[x][y][i].second;
num[nx][ny]--;
if (num[nx][ny] == 0) {
que.push({nx, ny});
d[nx][ny] = d[x][y] + 1;
ans = max(ans, d[nx][ny]);
}
}
}
//全ての頂点が入次数0になったか?
cout << (cnt == N * (N - 1) / 2 ? ans : -1) << endl;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using VL = vector<ll>;
#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++)
const long long INF = 999999999;
int N, a[1000];
vector<pair<ll, ll>> e[1001][1001];
ll num[1001][1001], d[1001][1001], ans, cnt;
int main() {
cin >> N;
FOR(i, 1, N + 1) {
REP(j, N - 1) {
cin >> a[j];
if (j) {
e[min(i, a[j - 1])][max(i, a[j - 1])].push_back(
{min(i, a[j]), max(i, a[j])});
num[min(i, a[j])][max(i, a[j])]++;
}
}
}
queue<pair<ll, ll>> que;
cnt = 0;
FOR(i, 1, N + 1) FOR(j, i + 1, N + 1) if (num[i][j] == 0) {
que.push({i, j});
//頂点iからjまでのパスに含まれる頂点の数
d[i][j] = 1;
}
while (!que.empty()) {
ll x = que.front().first, y = que.front().second, nx, ny;
que.pop();
cnt++;
REP(i, e[x][y].size()) {
nx = e[x][y][i].first;
ny = e[x][y][i].second;
num[nx][ny]--;
if (num[nx][ny] == 0) {
que.push({nx, ny});
d[nx][ny] = d[x][y] + 1;
ans = max(ans, d[nx][ny]);
}
}
}
//全ての頂点が入次数0になったか?
cout << (cnt == N * (N - 1) / 2 ? ans : -1) << endl;
}
|
[
"expression.operation.binary.add"
] | 729,313
| 729,314
|
u832095504
|
cpp
|
p02925
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAXN = 1005;
const int MAXV = MAXN * MAXN / 2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
//とりあえず、試合のIDを返す関数を作成。
int toId(int i, int j) {
if (i > j)
swap(i, j);
return id[i][j];
}
bool visited[MAXV]; //こっちは履歴.
bool calculated[MAXV]; //ループ検出用
int dp[MAXV]; // vからスタートしたときの最大経路をここにセット.
int dfs(int v) {
if (visited[v]) {
if (!calculated[v])
return -1;
return dp[v];
}
visited[v] = true;
dp[v] = 0;
// vから始まる頂点を全て見る.
for (int u : to[v]) {
int res = dfs(u);
if (res == -1)
return -1;
dp[v] = max(dp[v], res + 1);
}
calculated[v] = true;
return dp[v];
}
int main() {
//方針1
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1));
rep(i, n) {
rep(j, n - 1) {
cin >> a[i][j];
a[i][j]--;
}
}
// id割り振り.
int V = 0;
rep(i, n) rep(j, n) {
if (i < j) {
id[i][j] = V + 1;
}
}
//頂点間の辺を張っていく。
rep(i, n) {
rep(j, n - 1) {
//頂点番号に変換.
a[i][j] = toId(i, a[i][j]);
}
rep(j, n - 2) {
to[a[i][j + 1]].push_back(a[i][j]);
//逆向きに辺を張る.
}
}
//ここまででグラフは完成.
//好きな位置からdfsをする.
int ans = 0;
rep(i, V) {
int res = dfs(i);
if (res == -1) {
puts("-1");
return 0;
}
ans = max(ans, res);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAXN = 1005;
const int MAXV = MAXN * MAXN / 2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
//とりあえず、試合のIDを返す関数を作成。
int toId(int i, int j) {
if (i > j)
swap(i, j);
return id[i][j];
}
bool visited[MAXV]; //こっちは履歴.
bool calculated[MAXV]; //ループ検出用
int dp[MAXV]; // vからスタートしたときの最大経路をここにセット.
int dfs(int v) {
if (visited[v]) {
if (!calculated[v])
return -1;
return dp[v];
}
visited[v] = true;
dp[v] = 1;
// vから始まる頂点を全て見る.
for (int u : to[v]) {
int res = dfs(u);
if (res == -1)
return -1;
dp[v] = max(dp[v], res + 1);
}
calculated[v] = true;
return dp[v];
}
int main() {
//方針1
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1));
rep(i, n) {
rep(j, n - 1) {
cin >> a[i][j];
a[i][j]--;
}
}
// id割り振り.
int V = 0;
rep(i, n) rep(j, n) {
if (i < j) {
id[i][j] = V++;
}
}
//頂点間の辺を張っていく。
rep(i, n) {
rep(j, n - 1) {
//頂点番号に変換.
a[i][j] = toId(i, a[i][j]);
}
rep(j, n - 2) {
to[a[i][j + 1]].push_back(a[i][j]);
//逆向きに辺を張る.
}
}
//ここまででグラフは完成.
//好きな位置からdfsをする.
int ans = 0;
rep(i, V) {
int res = dfs(i);
if (res == -1) {
puts("-1");
return 0;
}
ans = max(ans, res);
}
cout << ans << endl;
return 0;
}
|
[
"literal.number.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 729,315
| 729,316
|
u480887263
|
cpp
|
p02925
|
/* _
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||_ \
| | \\\ - /'| | |
| \_| `\`---'// |_/ |
\ .-\__ `-. -'__/-. /
___`. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' _> \"".
| | : `- \`. ;`. _/; .'/ / .' ; |
\ \ `-. \_\_`. _.'_/_/ -' _.' /
===========`-.`___`-.__\ \___ /__.-'_.'_.-'================
Please give me AC.
*/
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) \
rep(i, (v).size() - 1) cout << (v)[i] << ' '; \
cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) \
cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) \
cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " \
<< (z) << '\n'
#define dbg(v) \
for (size_t _ = 0; _ < v.size(); ++_) { \
cerr << #v << "[" << _ << "] : " << v[_] << '\n'; \
}
// constant
const int INF = (1 << 30) - 1;
const int64 INF64 = (1LL << 62) - 1;
// End of template.
int main() {
cout << fixed << setprecision(15);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
int a[1010][1010];
int ai[1010];
cin >> n;
rep(i, n) rep(j, n - 1) cin >> a[i][j];
rep(i, n) rep(j, n - 1) a[i][j] -= 1;
rep(i, n) ai[i] = 0;
int ans = 0;
bool updated = true;
while (updated) {
updated = false;
bool c[1010];
memset(c, false, 1010);
rep(i, n) if (!c[i] && ai[i] < n - 1) {
int t = a[i][ai[i]];
if (c[t] || ai[t] >= n - 1)
continue;
if (a[t][ai[t]] == i) {
ai[t] += 1;
ai[i] += 1;
c[t] = true;
c[i] = true;
updated = true;
}
}
ans++;
}
int completed = true;
rep(i, n) completed = completed && ai[i] == n - 1;
if (completed)
print(ans);
else
print(-1);
return 0;
}
|
/* _
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||_ \
| | \\\ - /'| | |
| \_| `\`---'// |_/ |
\ .-\__ `-. -'__/-. /
___`. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' _> \"".
| | : `- \`. ;`. _/; .'/ / .' ; |
\ \ `-. \_\_`. _.'_/_/ -' _.' /
===========`-.`___`-.__\ \___ /__.-'_.'_.-'================
Please give me AC.
*/
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) \
rep(i, (v).size() - 1) cout << (v)[i] << ' '; \
cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) \
cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) \
cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " \
<< (z) << '\n'
#define dbg(v) \
for (size_t _ = 0; _ < v.size(); ++_) { \
cerr << #v << "[" << _ << "] : " << v[_] << '\n'; \
}
// constant
const int INF = (1 << 30) - 1;
const int64 INF64 = (1LL << 62) - 1;
// End of template.
int main() {
cout << fixed << setprecision(15);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
int a[1010][1010];
int ai[1010];
cin >> n;
rep(i, n) rep(j, n - 1) cin >> a[i][j];
rep(i, n) rep(j, n - 1) a[i][j] -= 1;
rep(i, n) ai[i] = 0;
int ans = 0;
bool updated = true;
while (updated) {
updated = false;
bool c[1010];
memset(c, false, 1010);
rep(i, n) if (!c[i] && ai[i] < n - 1) {
int t = a[i][ai[i]];
if (c[t] || ai[t] >= n - 1)
continue;
if (a[t][ai[t]] == i) {
ai[t] += 1;
ai[i] += 1;
c[t] = true;
c[i] = true;
updated = true;
}
}
ans++;
}
int completed = true;
rep(i, n) completed = completed && ai[i] == n - 1;
if (completed)
print(ans - 1);
else
print(-1);
return 0;
}
|
[
"expression.operation.binary.add"
] | 729,331
| 729,332
|
u061984624
|
cpp
|
p02925
|
/* _
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||_ \
| | \\\ - /'| | |
| \_| `\`---'// |_/ |
\ .-\__ `-. -'__/-. /
___`. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' _> \"".
| | : `- \`. ;`. _/; .'/ / .' ; |
\ \ `-. \_\_`. _.'_/_/ -' _.' /
===========`-.`___`-.__\ \___ /__.-'_.'_.-'================
Please give me AC.
*/
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) \
rep(i, (v).size() - 1) cout << (v)[i] << ' '; \
cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) \
cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) \
cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " \
<< (z) << '\n'
#define dbg(v) \
for (size_t _ = 0; _ < v.size(); ++_) { \
cerr << #v << "[" << _ << "] : " << v[_] << '\n'; \
}
// constant
const int INF = (1 << 30) - 1;
const int64 INF64 = (1LL << 62) - 1;
// End of template.
int main() {
cout << fixed << setprecision(15);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
int a[1010][1010];
int ai[1010];
cin >> n;
rep(i, n) rep(j, n - 1) cin >> a[i][j];
rep(i, n) rep(j, n - 1) a[i][j] -= 1;
rep(i, n) ai[i] = 0;
int ans = 0;
bool updated = true;
while (updated) {
updated = false;
bool c[1010];
memset(c, false, 1010);
rep(i, n) if (!c[i] && ai[i] < n - 1) {
int t = a[i][ai[i]];
if (c[i] || ai[t] >= n - 1)
continue;
if (a[t][ai[t]] == i) {
ai[t] += 1;
ai[i] += 1;
c[t] = true;
c[i] = true;
updated = true;
}
}
ans++;
}
int completed = true;
rep(i, n) completed = completed && ai[i] == n - 1;
if (completed)
print(ans);
else
print(-1);
return 0;
}
|
/* _
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||_ \
| | \\\ - /'| | |
| \_| `\`---'// |_/ |
\ .-\__ `-. -'__/-. /
___`. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' _> \"".
| | : `- \`. ;`. _/; .'/ / .' ; |
\ \ `-. \_\_`. _.'_/_/ -' _.' /
===========`-.`___`-.__\ \___ /__.-'_.'_.-'================
Please give me AC.
*/
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) \
rep(i, (v).size() - 1) cout << (v)[i] << ' '; \
cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) \
cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) \
cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " \
<< (z) << '\n'
#define dbg(v) \
for (size_t _ = 0; _ < v.size(); ++_) { \
cerr << #v << "[" << _ << "] : " << v[_] << '\n'; \
}
// constant
const int INF = (1 << 30) - 1;
const int64 INF64 = (1LL << 62) - 1;
// End of template.
int main() {
cout << fixed << setprecision(15);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
int a[1010][1010];
int ai[1010];
cin >> n;
rep(i, n) rep(j, n - 1) cin >> a[i][j];
rep(i, n) rep(j, n - 1) a[i][j] -= 1;
rep(i, n) ai[i] = 0;
int ans = 0;
bool updated = true;
while (updated) {
updated = false;
bool c[1010];
memset(c, false, 1010);
rep(i, n) if (!c[i] && ai[i] < n - 1) {
int t = a[i][ai[i]];
if (c[t] || ai[t] >= n - 1)
continue;
if (a[t][ai[t]] == i) {
ai[t] += 1;
ai[i] += 1;
c[t] = true;
c[i] = true;
updated = true;
}
}
ans++;
}
int completed = true;
rep(i, n) completed = completed && ai[i] == n - 1;
if (completed)
print(ans - 1);
else
print(-1);
return 0;
}
|
[
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 729,333
| 729,332
|
u061984624
|
cpp
|
p02925
|
#include <bits/stdc++.h>
#define long long long int
using namespace std;
// @author: pashka
int main() {
ios::sync_with_stdio(false);
int n;
vector<vector<int>> a(n, vector<int>(n - 1));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - 1; j++) {
cin >> a[i][j];
a[i][j]--;
}
};
vector<int> c(n);
vector<int> q;
for (int i = 0; i < n; i++) {
int x = a[i][0];
if (a[x][0] == i) {
q.push_back(i);
}
}
int res = 0;
while (!q.empty()) {
res++;
vector<int> q2;
for (int i : q) {
c[i]++;
if (c[i] < n - 1) {
int x = a[i][c[i]];
if (a[x][c[x]] == i) {
q2.push_back(i);
q2.push_back(x);
}
}
}
q = q2;
}
for (int i = 0; i < n; i++) {
if (c[i] < n - 1) {
cout << -1;
return 0;
}
}
cout << res;
return 0;
}
|
#include <bits/stdc++.h>
#define long long long int
using namespace std;
// @author: pashka
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - 1; j++) {
cin >> a[i][j];
a[i][j]--;
}
};
vector<int> c(n);
vector<int> q;
for (int i = 0; i < n; i++) {
int x = a[i][0];
if (a[x][0] == i) {
q.push_back(i);
}
}
int res = 0;
while (!q.empty()) {
res++;
vector<int> q2;
for (int i : q) {
c[i]++;
if (c[i] < n - 1) {
int x = a[i][c[i]];
if (a[x][c[x]] == i) {
q2.push_back(i);
q2.push_back(x);
}
}
}
q = q2;
}
for (int i = 0; i < n; i++) {
if (c[i] < n - 1) {
cout << -1;
return 0;
}
}
cout << res;
return 0;
}
|
[] | 729,342
| 729,343
|
u136509923
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
const bool DEBUG = true;
const int MAX_N = 1005;
const int MAX_V = MAX_N * (MAX_N - 1) / 2;
vector<int> to[MAX_V];
int id[MAX_N][MAX_N];
int to_match_id(int i, int j) {
if (i > j)
swap(i, j);
return id[i][j];
}
bool visited[MAX_V];
bool calculated[MAX_V];
int dp[MAX_V]; // vからスタートしたときの最長経路を保存しておくテーブル
int dfs(int v) {
if (visited[v]) {
if (!calculated[v])
return -1;
return dp[v];
}
visited[v] = true;
dp[v] = 0;
// メモ化再帰
for (auto &&u : to[v]) {
int res = dfs(u);
if (res == -1)
return -1;
dp[v] = max(dp[v], res + 1);
}
calculated[v] = true;
return dp[v];
}
int main(int argc, char const *argv[]) {
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1));
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < n - 1; j++) {
cin >> a[i][j];
a[i][j]--;
}
}
int V = 0;
for (size_t i = 0; i < n; i++)
for (size_t j = 0; j < n; j++) {
if (i < j)
id[i][j] = V++;
}
for (size_t i = 0; i < n; i++) {
// a[i][j] にmatch_idが入るようにする
for (size_t j = 0; j < n - 1; j++)
a[i][j] = to_match_id(i, a[i][j]);
// 次の試合から前の試合へエッジを張る
for (size_t j = 0; j < n - 2; j++)
to[a[i][j + 1]].push_back(a[i][j]);
}
// DFSを行う
int day = 0;
for (size_t i = 0; i < V; i++) {
int res = dfs(i);
if (res == -1) {
cout << "-1" << endl;
return 0;
}
day = max(day, res);
}
cout << day << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const bool DEBUG = true;
const int MAX_N = 1005;
const int MAX_V = MAX_N * (MAX_N - 1) / 2;
vector<int> to[MAX_V];
int id[MAX_N][MAX_N];
int to_match_id(int i, int j) {
if (i > j)
swap(i, j);
return id[i][j];
}
bool visited[MAX_V];
bool calculated[MAX_V];
int dp[MAX_V]; // vからスタートしたときの最長経路を保存しておくテーブル
int dfs(int v) {
if (visited[v]) {
if (!calculated[v])
return -1;
return dp[v];
}
visited[v] = true;
dp[v] = 1;
// メモ化再帰
for (auto &&u : to[v]) {
int res = dfs(u);
if (res == -1)
return -1;
dp[v] = max(dp[v], res + 1);
}
calculated[v] = true;
return dp[v];
}
int main(int argc, char const *argv[]) {
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1));
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < n - 1; j++) {
cin >> a[i][j];
a[i][j]--;
}
}
int V = 0;
for (size_t i = 0; i < n; i++)
for (size_t j = 0; j < n; j++) {
if (i < j)
id[i][j] = V++;
}
for (size_t i = 0; i < n; i++) {
// a[i][j] にmatch_idが入るようにする
for (size_t j = 0; j < n - 1; j++)
a[i][j] = to_match_id(i, a[i][j]);
// 次の試合から前の試合へエッジを張る
for (size_t j = 0; j < n - 2; j++)
to[a[i][j + 1]].push_back(a[i][j]);
}
// DFSを行う
int day = 0;
for (size_t i = 0; i < V; i++) {
int res = dfs(i);
if (res == -1) {
cout << "-1" << endl;
return 0;
}
day = max(day, res);
}
cout << day << endl;
return 0;
}
|
[
"literal.number.change",
"assignment.value.change"
] | 729,355
| 729,356
|
u482785341
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
const bool DEBUG = true;
const int MAX_N = 1005;
const int MAX_V = MAX_N * (MAX_N - 1) / 2;
vector<int> to[MAX_V];
int id[MAX_N][MAX_N];
int to_match_id(int i, int j) {
if (i > j)
swap(i, j);
return id[i][j];
}
bool visited[MAX_V];
bool calculated[MAX_V];
int dp[MAX_V]; // vからスタートしたときの最長経路を保存しておくテーブル
int dfs(int v) {
if (visited[v]) {
if (!calculated[v])
return -1;
return dp[v];
}
visited[v] = true;
dp[v] = 0;
// メモ化再帰
for (auto &&u : to[v]) {
int res = dfs(u);
if (res == -1)
return -1;
dp[v] = max(dp[v], res + 1);
}
calculated[v] = true;
return dp[v];
}
int main(int argc, char const *argv[]) {
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1));
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < n - 1; j++) {
cin >> a[i][j];
a[i][j]--;
}
}
int v = 0;
for (size_t i = 0; i < n; i++)
for (size_t j = 0; j < n; j++) {
if (i < j)
id[i][j] = v++;
}
for (size_t i = 0; i < n; i++) {
// a[i][j] にmatch_idが入るようにする
for (size_t j = 0; j < n - 1; j++)
a[i][j] = to_match_id(i, a[i][j]);
// 次の試合から前の試合へエッジを張る
for (size_t j = 0; j < n - 2; j++)
to[a[i][j + 1]].push_back(a[i][j]);
}
// DFSを行う
int day = 0;
for (size_t i = 0; i < n; i++) {
int res = dfs(i);
if (res == -1) {
cout << "-1" << endl;
return 0;
}
day = max(day, res);
}
cout << day << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const bool DEBUG = true;
const int MAX_N = 1005;
const int MAX_V = MAX_N * (MAX_N - 1) / 2;
vector<int> to[MAX_V];
int id[MAX_N][MAX_N];
int to_match_id(int i, int j) {
if (i > j)
swap(i, j);
return id[i][j];
}
bool visited[MAX_V];
bool calculated[MAX_V];
int dp[MAX_V]; // vからスタートしたときの最長経路を保存しておくテーブル
int dfs(int v) {
if (visited[v]) {
if (!calculated[v])
return -1;
return dp[v];
}
visited[v] = true;
dp[v] = 1;
// メモ化再帰
for (auto &&u : to[v]) {
int res = dfs(u);
if (res == -1)
return -1;
dp[v] = max(dp[v], res + 1);
}
calculated[v] = true;
return dp[v];
}
int main(int argc, char const *argv[]) {
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1));
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < n - 1; j++) {
cin >> a[i][j];
a[i][j]--;
}
}
int V = 0;
for (size_t i = 0; i < n; i++)
for (size_t j = 0; j < n; j++) {
if (i < j)
id[i][j] = V++;
}
for (size_t i = 0; i < n; i++) {
// a[i][j] にmatch_idが入るようにする
for (size_t j = 0; j < n - 1; j++)
a[i][j] = to_match_id(i, a[i][j]);
// 次の試合から前の試合へエッジを張る
for (size_t j = 0; j < n - 2; j++)
to[a[i][j + 1]].push_back(a[i][j]);
}
// DFSを行う
int day = 0;
for (size_t i = 0; i < V; i++) {
int res = dfs(i);
if (res == -1) {
cout << "-1" << endl;
return 0;
}
day = max(day, res);
}
cout << day << endl;
return 0;
}
|
[
"literal.number.change",
"assignment.value.change",
"variable_declaration.name.change",
"identifier.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 729,357
| 729,356
|
u482785341
|
cpp
|
p02925
|
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;
template <typename X, typename T> auto vectors(X x, T a) {
return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
auto cont = vectors(y, z, zs...);
return vector<decltype(cont)>(x, cont);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &x : v) {
is >> x;
}
return is;
}
signed main() {
int n;
cin >> n;
vector<vector<int>> g(n * n);
vector<int> vin(n * n, -1);
rep(i, n) {
vector<int> node;
rep(_, n - 1) {
int x, y = i;
cin >> x;
x--;
if (x > y)
swap(x, y);
int v = x * n + y;
vin[v] = max(0LL, vin[v]);
node.emplace_back(v);
}
rep(j, node.size() - 1) { g[node[j]].emplace_back(node[j + 1]); }
}
rep(i, g.size()) {
for (auto to : g[i]) {
vin[to]++;
}
}
queue<int> q;
vector<int> dis(n * n);
rep(i, n * n) if (vin[i] == 0) {
q.emplace(i);
dis[i] = 1;
}
while (not q.empty()) {
int cur = q.front();
q.pop();
for (auto to : g[cur]) {
vin[to]--;
if (vin[to] == 0) {
dis[to] = dis[cur] + 1;
q.emplace(to);
}
}
}
bool f = true;
rep(i, vin.size()) {
if (vin[i] != -1 and vin[i] != 0)
f = false;
}
if (not f)
cout << *max_element(all(dis)) << endl;
else
cout << -1 << endl;
}
|
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;
template <typename X, typename T> auto vectors(X x, T a) {
return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
auto cont = vectors(y, z, zs...);
return vector<decltype(cont)>(x, cont);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &x : v) {
is >> x;
}
return is;
}
signed main() {
int n;
cin >> n;
vector<vector<int>> g(n * n);
vector<int> vin(n * n, -1);
rep(i, n) {
vector<int> node;
rep(_, n - 1) {
int x, y = i;
cin >> x;
x--;
if (x > y)
swap(x, y);
int v = x * n + y;
vin[v] = max(0LL, vin[v]);
node.emplace_back(v);
}
rep(j, node.size() - 1) { g[node[j]].emplace_back(node[j + 1]); }
}
rep(i, g.size()) {
for (auto to : g[i]) {
vin[to]++;
}
}
queue<int> q;
vector<int> dis(n * n);
rep(i, n * n) if (vin[i] == 0) {
q.emplace(i);
dis[i] = 1;
}
while (not q.empty()) {
int cur = q.front();
q.pop();
for (auto to : g[cur]) {
vin[to]--;
if (vin[to] == 0) {
dis[to] = dis[cur] + 1;
q.emplace(to);
}
}
}
bool f = true;
rep(i, vin.size()) {
if (vin[i] != -1 and vin[i] != 0)
f = false;
}
if (f)
cout << *max_element(all(dis)) << endl;
else
cout << -1 << endl;
}
|
[] | 729,366
| 729,367
|
u526532903
|
cpp
|
p02925
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MAXN = 1005;
const int MAXV = MAXN * (MAXN - 1) / 2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
int toId(int i, int j) {
if (i > j)
swap(i, j);
return id[i][j];
}
bool visited[MAXV];
bool calculated[MAXV];
int dp[MAXV];
int dfs(int v) {
if (visited[v]) {
if (!calculated[v])
return -1;
return dp[v];
}
visited[v] = true;
dp[v] = 0;
for (int u : to[v]) {
int res = dfs(u);
if (res == -1)
return -1;
dp[v] = max(dp[v], res + 1);
}
calculated[v] = true;
return dp[v];
}
int main() {
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1));
rep(i, n) {
rep(j, n - 1) {
cin >> a[i][j];
a[i][j]--;
}
}
int V = 0;
rep(i, n) rep(j, n) {
if (i < j) {
id[i][j] = V++;
}
}
rep(i, n) {
rep(j, n - 1) { a[i][j] = toId(i, a[i][j]); }
rep(j, n - 2) { to[a[i][j + 1]].push_back(a[i][j]); }
}
int ans = 0;
rep(i, n) {
int res = dfs(i);
if (res == -1) {
puts("-1");
return 0;
}
ans = max(ans, dfs(i));
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MAXN = 1005;
const int MAXV = MAXN * (MAXN - 1) / 2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
int toId(int i, int j) {
if (i > j)
swap(i, j);
return id[i][j];
}
bool visited[MAXV];
bool calculated[MAXV];
int dp[MAXV];
int dfs(int v) {
if (visited[v]) {
if (!calculated[v])
return -1;
return dp[v];
}
visited[v] = true;
dp[v] = 1;
for (int u : to[v]) {
int res = dfs(u);
if (res == -1)
return -1;
dp[v] = max(dp[v], res + 1);
}
calculated[v] = true;
return dp[v];
}
int main() {
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1));
rep(i, n) {
rep(j, n - 1) {
cin >> a[i][j];
a[i][j]--;
}
}
int V = 0;
rep(i, n) rep(j, n) {
if (i < j) {
id[i][j] = V++;
}
}
rep(i, n) {
rep(j, n - 1) { a[i][j] = toId(i, a[i][j]); }
rep(j, n - 2) { to[a[i][j + 1]].push_back(a[i][j]); }
}
int ans = 0;
rep(i, V) {
int res = dfs(i);
if (res == -1) {
puts("-1");
return 0;
}
ans = max(ans, dfs(i));
}
cout << ans << endl;
return 0;
}
|
[
"literal.number.change",
"assignment.value.change"
] | 729,380
| 729,379
|
u506858457
|
cpp
|
p02925
|
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define db(x) cout << #x << "=" << x << endl
template <class T> bool maxi(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool mini(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define y0 y3487465 // j0
#define y1 y1347829 // j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;
void Main() {
ll N;
cin >> N;
int a[N][N - 1];
rep(i, N) {
rep(j, N - 1) {
int aa;
cin >> aa;
--aa;
a[i][j] = aa;
}
}
int now[N] = {};
bool dame[N] = {};
bool update = true;
int ct = 0;
while (update) {
update = false;
ct++;
rep(i, N) {
if (dame[i]) {
dame[i] = false;
continue;
}
if (now[i] >= N - 1)
continue;
int saki = a[i][now[i]];
if (saki > i and a[saki][now[saki]] == i and !dame[saki]) {
++now[i];
++now[saki];
update = true;
dame[saki] = true;
}
}
}
rep(i, N) {
if (now[i] < N - 1) {
cout << -1 << "\n";
return;
}
}
cout << ct << "\n";
}
//-----------------------------------
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
}
//-----------------------------------
|
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define db(x) cout << #x << "=" << x << endl
template <class T> bool maxi(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool mini(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define y0 y3487465 // j0
#define y1 y1347829 // j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;
void Main() {
ll N;
cin >> N;
int a[N][N - 1];
rep(i, N) {
rep(j, N - 1) {
int aa;
cin >> aa;
--aa;
a[i][j] = aa;
}
}
int now[N] = {};
bool dame[N] = {};
bool update = true;
int ct = 0;
while (update) {
update = false;
ct++;
rep(i, N) {
if (dame[i]) {
dame[i] = false;
continue;
}
if (now[i] >= N - 1)
continue;
int saki = a[i][now[i]];
if (saki > i and a[saki][now[saki]] == i and !dame[saki]) {
++now[i];
++now[saki];
update = true;
dame[saki] = true;
}
}
}
rep(i, N) {
if (now[i] < N - 1) {
cout << -1 << "\n";
return;
}
}
cout << ct - 1 << "\n";
}
//-----------------------------------
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
}
//-----------------------------------
|
[
"expression.operation.binary.add"
] | 729,381
| 729,382
|
u556276145
|
cpp
|
p02925
|
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define db(x) cout << #x << "=" << x << endl
template <class T> bool maxi(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool mini(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define y0 y3487465 // j0
#define y1 y1347829 // j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;
void Main() {
ll N;
cin >> N;
int a[N][N - 1];
rep(i, N) {
rep(j, N - 1) {
int aa;
cin >> aa;
--aa;
a[i][j] = aa;
}
}
int now[N] = {};
bool dame[N] = {};
bool update = true;
int ct = 0;
while (update) {
update = false;
ct++;
rep(i, N) {
if (dame[i]) {
dame[i] = false;
continue;
}
if (now[i] >= N - 1)
continue;
int saki = a[i][now[i]];
if (saki > i and a[saki][now[saki]] == i and !dame[i]) {
++now[i];
++now[saki];
update = true;
dame[saki] = true;
}
}
}
rep(i, N) {
if (now[i] < N - 1) {
cout << -1 << "\n";
return;
}
}
cout << ct << "\n";
}
//-----------------------------------
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
}
//-----------------------------------
|
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define db(x) cout << #x << "=" << x << endl
template <class T> bool maxi(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool mini(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define y0 y3487465 // j0
#define y1 y1347829 // j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;
void Main() {
ll N;
cin >> N;
int a[N][N - 1];
rep(i, N) {
rep(j, N - 1) {
int aa;
cin >> aa;
--aa;
a[i][j] = aa;
}
}
int now[N] = {};
bool dame[N] = {};
bool update = true;
int ct = 0;
while (update) {
update = false;
ct++;
rep(i, N) {
if (dame[i]) {
dame[i] = false;
continue;
}
if (now[i] >= N - 1)
continue;
int saki = a[i][now[i]];
if (saki > i and a[saki][now[saki]] == i and !dame[saki]) {
++now[i];
++now[saki];
update = true;
dame[saki] = true;
}
}
}
rep(i, N) {
if (now[i] < N - 1) {
cout << -1 << "\n";
return;
}
}
cout << ct - 1 << "\n";
}
//-----------------------------------
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
}
//-----------------------------------
|
[
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 729,383
| 729,382
|
u556276145
|
cpp
|
p02925
|
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using datas = pair<ll, ll>;
using tdata = pair<ll, datas>;
using vec = vector<ll>;
using mat = vector<vec>;
using pvec = vector<datas>;
using pmat = vector<pvec>;
#define For(i, a, b) for (i = a; i < b; i++)
#define bFor(i, a, b) for (i = a; i >= b; i--)
#define rep(i, N) For(i, 0, N)
#define rep1(i, N) For(i, 1, N)
#define brep(i, N) bFor(i, N - 1, 0)
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) \
do { \
bool f = 0; \
for (auto i : v) { \
cout << (f ? " " : "") << i; \
f = 1; \
} \
cout << endl; \
} while (0)
long mmid(long a, long b, long c) {
return a < b ? (b < c ? b : max(a, c)) : (b > c ? b : min(a, c));
}
ll modinv(ll a) {
ll b = mod, u = 1, v = 0, t;
while (b) {
t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
return (u + mod) % mod;
}
ll moddevide(ll a, ll b) { return (a * modinv(b)) % mod; }
ll modncr(ll n, ll r) {
ll i, plus = 1;
rep(i, r) {
plus = (plus * (n - i)) % mod;
plus = moddevide(plus, i + 1);
}
return plus;
}
ll modncrlistp[200000], modncrlistm[200000];
ll modncrs(ll n, ll r) {
ll i, j;
if (modncrlistp[n] == 0) {
for (i = n; i >= 0; i--) {
if (modncrlistp[i])
break;
}
if (i < 0) {
modncrlistp[0] = 1;
rep1(i, n + 1) { modncrlistp[i] = (modncrlistp[i - 1] * i) % mod; }
} else {
For(j, i + 1, n + 1) { modncrlistp[j] = (modncrlistp[j - 1] * j) % mod; }
}
}
if (modncrlistm[n] == 0) {
for (i = n; i >= 0; i--) {
if (modncrlistm[i])
break;
}
if (i < 0) {
modncrlistm[0] = 1;
rep1(i, n + 1) {
modncrlistm[i] = (modncrlistm[i - 1] * modinv(i)) % mod;
}
} else {
For(j, i + 1, n + 1) modncrlistm[j] =
(modncrlistm[j - 1] * modinv(j)) % mod;
}
}
return (((modncrlistp[n] * modncrlistm[r]) % mod) * modncrlistm[n - r]) % mod;
}
ll gcd(ll a, ll b) {
if (!b)
return a;
return (a % b == 0) ? b : gcd(b, a % b);
}
ll countdigits(ll n) {
ll ans = 0;
while (n) {
n /= 10;
ans++;
}
return ans;
}
ll sumdigits(ll n) {
ll ans = 0;
while (n) {
ans += n % 10;
n /= 10;
}
return ans;
}
vec eratosthenes(ll N) {
ll i;
vec ch(N + 1, 1), p;
ch[0] = ch[1] = 0;
rep(i, N + 1) {
if (ch[i]) {
p.push_back(i);
for (ll j = 2; i * j <= N; j++) {
ch[i * j] = 0;
}
}
}
return p;
}
int main() {
ll i, j, N, M, K, a, b, cnt = 0, bf, now;
cin >> N;
M = N * (N - 1) / 2;
mat v(M);
vec inlis(M, 0), sorted;
map<datas, ll> mp;
rep1(i, N + 1) {
cin >> bf;
if (i < bf) {
if (!mp[datas(i, bf)])
mp[datas(i, bf)] = ++cnt;
a = mp[datas(i, bf)];
} else {
if (!mp[datas(bf, i)])
mp[datas(bf, i)] = ++cnt;
a = mp[datas(bf, i)];
}
a--;
rep(j, N - 2) {
cin >> now;
if (i < now) {
if (!mp[datas(i, now)])
mp[datas(i, now)] = ++cnt;
b = mp[datas(i, now)];
} else {
if (!mp[datas(now, i)])
mp[datas(now, i)] = ++cnt;
b = mp[datas(now, i)];
}
b--;
v[a].push_back(b);
inlis[b]++;
b = a;
}
}
queue<ll> que;
rep(i, M) {
if (!inlis[i])
que.push(i);
}
rep(j, M) {
N = que.size();
if (!N)
break;
while (N--) {
K = que.front();
que.pop();
sorted.push_back(K);
for (auto i : v[K]) {
inlis[i]--;
if (!inlis[i])
que.push(i);
}
}
}
if (sorted.size() != M) {
cout << -1 << endl;
} else {
cout << j << endl;
}
return 0;
}
|
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using datas = pair<ll, ll>;
using tdata = pair<ll, datas>;
using vec = vector<ll>;
using mat = vector<vec>;
using pvec = vector<datas>;
using pmat = vector<pvec>;
#define For(i, a, b) for (i = a; i < b; i++)
#define bFor(i, a, b) for (i = a; i >= b; i--)
#define rep(i, N) For(i, 0, N)
#define rep1(i, N) For(i, 1, N)
#define brep(i, N) bFor(i, N - 1, 0)
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) \
do { \
bool f = 0; \
for (auto i : v) { \
cout << (f ? " " : "") << i; \
f = 1; \
} \
cout << endl; \
} while (0)
long mmid(long a, long b, long c) {
return a < b ? (b < c ? b : max(a, c)) : (b > c ? b : min(a, c));
}
ll modinv(ll a) {
ll b = mod, u = 1, v = 0, t;
while (b) {
t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
return (u + mod) % mod;
}
ll moddevide(ll a, ll b) { return (a * modinv(b)) % mod; }
ll modncr(ll n, ll r) {
ll i, plus = 1;
rep(i, r) {
plus = (plus * (n - i)) % mod;
plus = moddevide(plus, i + 1);
}
return plus;
}
ll modncrlistp[200000], modncrlistm[200000];
ll modncrs(ll n, ll r) {
ll i, j;
if (modncrlistp[n] == 0) {
for (i = n; i >= 0; i--) {
if (modncrlistp[i])
break;
}
if (i < 0) {
modncrlistp[0] = 1;
rep1(i, n + 1) { modncrlistp[i] = (modncrlistp[i - 1] * i) % mod; }
} else {
For(j, i + 1, n + 1) { modncrlistp[j] = (modncrlistp[j - 1] * j) % mod; }
}
}
if (modncrlistm[n] == 0) {
for (i = n; i >= 0; i--) {
if (modncrlistm[i])
break;
}
if (i < 0) {
modncrlistm[0] = 1;
rep1(i, n + 1) {
modncrlistm[i] = (modncrlistm[i - 1] * modinv(i)) % mod;
}
} else {
For(j, i + 1, n + 1) modncrlistm[j] =
(modncrlistm[j - 1] * modinv(j)) % mod;
}
}
return (((modncrlistp[n] * modncrlistm[r]) % mod) * modncrlistm[n - r]) % mod;
}
ll gcd(ll a, ll b) {
if (!b)
return a;
return (a % b == 0) ? b : gcd(b, a % b);
}
ll countdigits(ll n) {
ll ans = 0;
while (n) {
n /= 10;
ans++;
}
return ans;
}
ll sumdigits(ll n) {
ll ans = 0;
while (n) {
ans += n % 10;
n /= 10;
}
return ans;
}
vec eratosthenes(ll N) {
ll i;
vec ch(N + 1, 1), p;
ch[0] = ch[1] = 0;
rep(i, N + 1) {
if (ch[i]) {
p.push_back(i);
for (ll j = 2; i * j <= N; j++) {
ch[i * j] = 0;
}
}
}
return p;
}
int main() {
ll i, j, N, M, K, a, b, cnt = 0, bf, now;
cin >> N;
M = N * (N - 1) / 2;
mat v(M);
vec inlis(M, 0), sorted;
map<datas, ll> mp;
rep1(i, N + 1) {
cin >> bf;
if (i < bf) {
if (!mp[datas(i, bf)])
mp[datas(i, bf)] = ++cnt;
a = mp[datas(i, bf)];
} else {
if (!mp[datas(bf, i)])
mp[datas(bf, i)] = ++cnt;
a = mp[datas(bf, i)];
}
a--;
rep(j, N - 2) {
cin >> now;
if (i < now) {
if (!mp[datas(i, now)])
mp[datas(i, now)] = ++cnt;
b = mp[datas(i, now)];
} else {
if (!mp[datas(now, i)])
mp[datas(now, i)] = ++cnt;
b = mp[datas(now, i)];
}
b--;
v[a].push_back(b);
inlis[b]++;
a = b;
}
}
queue<ll> que;
rep(i, M) {
if (!inlis[i])
que.push(i);
}
rep(j, M) {
N = que.size();
if (!N)
break;
while (N--) {
K = que.front();
que.pop();
sorted.push_back(K);
for (auto i : v[K]) {
inlis[i]--;
if (!inlis[i])
que.push(i);
}
}
}
if (sorted.size() != M) {
cout << -1 << endl;
} else {
cout << j << endl;
}
return 0;
}
|
[
"assignment.change"
] | 729,390
| 729,391
|
u251847465
|
cpp
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.