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 |
|---|---|---|---|---|---|---|---|
p02925
|
#include <bits/stdc++.h>
// #include <iostream> // cout, endl, cin
// #include <string> // string, to_string, stoi
// #include <vector> // vector
// #include <algorithm> // min, max, swap, sort, reverse, lower_bound,
// upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple,
// make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf
// #include <map> // map
// #include <queue> // queue, priority_queue
// #include <set> // set
// #include <stack> // stack
// #include <deque> // deque
// #include <unordered_map> // unordered_map
// #include <unordered_set> // unordered_set
// #include <bitset> // bitset
// #include <climits>
// #include <cmath>
// #include <iomanip>
// #include <functional>
// #include <numeric>
// #include <random>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define rep(i, n) FOR(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ve vector
#define vi vector<int>
#define vp vector<pair<int, int>>
#define vvi vector<vector<int>>
template <typename T> using pq = priority_queue<T, vector<T>, greater<T>>;
using ll = long long;
ll INF = LLONG_MAX / 4000 - 100;
ll mod = 1e9 + 7;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
vector<ll> prime;
class fact {
public:
int fmod = 1e9 + 7;
vector<int> fac, finv, inv;
fact(int n, int Mod = 1e9 + 7) {
fmod = Mod;
fac = vector<int>(n, 0);
finv = vector<int>(n, 0);
inv = vector<int>(n, 0);
fac[0] = 1;
for (int i = 1; i < n; i++)
fac[i] = fac[i - 1] * i % fmod;
for (int i = 0; i < n; i++)
finv[i] = fact::POW(fac[i], fmod - 2);
for (int i = 0; i < n; i++)
inv[i] = POW(i, fmod - 2);
}
ll nCr(ll n, ll r) {
if (n < r)
return 0;
return (fac[n] * finv[r] % fmod) * finv[n - r] % fmod;
}
ll POW(ll a, ll b) {
ll c = 1;
while (b > 0) {
if (b & 1) {
c = a * c % fmod;
}
a = a * a % fmod;
b >>= 1;
}
return c;
}
inline int operator[](int i) { return fac[i]; }
};
template <class T = ll> T in() {
T x;
cin >> x;
return (x);
}
void DEBUG(vector<int> a) {
for (int i = 0; i < a.size(); i++)
cout << a[i] << " ";
cout << endl;
}
void EMP(int x) { cout << "!!!" << x << "!!!" << endl; }
ll GCD(ll a, ll b) {
ll c;
while (b != 0) {
c = a % b;
a = b;
b = c;
}
return a;
}
ll LCM(ll a, ll b) { return (a / GCD(a, b)) * (b / GCD(a, b)) * GCD(a, b); }
ll POW(ll a, ll b) {
ll c = 1;
while (b > 0) {
if (b & 1) {
c = a * c % mod;
}
a = a * a % mod;
b >>= 1;
}
return c;
}
void PRI(ll n) {
bool a[n + 1LL];
for (int i = 0; i < n + 1LL; i++) {
a[i] = 1LL;
}
for (int i = 2; i < n + 1LL; i++) {
if (a[i]) {
prime.pb(i);
ll b = i;
while (b <= n) {
a[b] = 0;
b += i;
}
}
}
}
template <typename T> T chmin(T &a, T b) {
if (a > b)
a = b;
return a;
}
template <typename T> T chmax(T &a, T b) {
if (a < b)
a = b;
return b;
}
bool isSqrt(ll a) { return pow(sqrt(a), 2) == a ? 1 : 0; }
void YesNo(bool a) {
if (a)
cout << "Yes";
else
cout << "No";
cout << endl;
}
void yesno(bool a) {
if (a)
cout << "yes";
else
cout << "no";
cout << endl;
}
void YESNO(bool a) {
if (a)
cout << "YES";
else
cout << "NO";
cout << endl;
}
double dis(int x1, int x2, int y1, int y2) {
return sqrt((double)abs(x1 - x2) * (double)abs(x1 - x2) +
(double)abs(y1 - y2) * (double)abs(y1 - y2));
}
class topological {
public:
bool uniq = true, can = true;
int maxlen = 0;
int n;
queue<int> cnt;
vector<int> in;
vector<int> len;
vector<vector<int>> loute;
vector<int> res;
topological(vector<vector<int>> lt) {
loute = lt;
n = loute.size();
in = vector<int>(n);
len = vector<int>(n);
for (auto &&from : loute) {
for (auto &&to : from) {
in[to]++;
}
}
for (int i = 0; i < n; i++) {
if (!in[i]) {
cnt.push(i);
}
}
}
void run() {
while (!cnt.empty()) {
int nxt = cnt.front();
cnt.pop();
if (cnt.size())
uniq = false;
res.pb(nxt);
for (auto &&to : loute[nxt]) {
--in[to];
if (!in[to])
cnt.push(to);
len[to] = max(len[to], len[nxt] + 1);
}
}
if (res.size() != n)
can = false;
for (int i = 0; i < n; i++) {
maxlen = max(maxlen, len[i]);
}
}
};
void solve() {
int n;
cin >> n;
int ma[n][n];
int p = 0;
rep(i, n) {
FOR(j, i + 1, n) {
ma[i][j] = p;
p++;
}
}
vector<vector<int>> ed(n * (n - 1) / 2);
int A[n][n - 1];
rep(i, n) {
rep(j, n - 1) {
int a;
cin >> a;
A[i][j] = --a;
}
}
rep(i, n) {
FOR(j, 1, n - 1) {
int mae = A[i][j - 1];
int ato = A[i][j];
// cout << ma[{min(i,mae),max(i,mae)}] << " " <<
// ma[{min(i,ato),max(i,ato)}] << endl;
ed[ma[min(i, mae)][max(i, mae)]].pb(ma[min(i, ato)][max(i, ato)]);
}
}
topological topo(ed);
topo.run();
cout << (topo.can ? topo.maxlen : -1) << endl;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
solve();
}
|
#include <bits/stdc++.h>
// #include <iostream> // cout, endl, cin
// #include <string> // string, to_string, stoi
// #include <vector> // vector
// #include <algorithm> // min, max, swap, sort, reverse, lower_bound,
// upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple,
// make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf
// #include <map> // map
// #include <queue> // queue, priority_queue
// #include <set> // set
// #include <stack> // stack
// #include <deque> // deque
// #include <unordered_map> // unordered_map
// #include <unordered_set> // unordered_set
// #include <bitset> // bitset
// #include <climits>
// #include <cmath>
// #include <iomanip>
// #include <functional>
// #include <numeric>
// #include <random>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define rep(i, n) FOR(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ve vector
#define vi vector<int>
#define vp vector<pair<int, int>>
#define vvi vector<vector<int>>
template <typename T> using pq = priority_queue<T, vector<T>, greater<T>>;
using ll = long long;
ll INF = LLONG_MAX / 4000 - 100;
ll mod = 1e9 + 7;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
vector<ll> prime;
class fact {
public:
int fmod = 1e9 + 7;
vector<int> fac, finv, inv;
fact(int n, int Mod = 1e9 + 7) {
fmod = Mod;
fac = vector<int>(n, 0);
finv = vector<int>(n, 0);
inv = vector<int>(n, 0);
fac[0] = 1;
for (int i = 1; i < n; i++)
fac[i] = fac[i - 1] * i % fmod;
for (int i = 0; i < n; i++)
finv[i] = fact::POW(fac[i], fmod - 2);
for (int i = 0; i < n; i++)
inv[i] = POW(i, fmod - 2);
}
ll nCr(ll n, ll r) {
if (n < r)
return 0;
return (fac[n] * finv[r] % fmod) * finv[n - r] % fmod;
}
ll POW(ll a, ll b) {
ll c = 1;
while (b > 0) {
if (b & 1) {
c = a * c % fmod;
}
a = a * a % fmod;
b >>= 1;
}
return c;
}
inline int operator[](int i) { return fac[i]; }
};
template <class T = ll> T in() {
T x;
cin >> x;
return (x);
}
void DEBUG(vector<int> a) {
for (int i = 0; i < a.size(); i++)
cout << a[i] << " ";
cout << endl;
}
void EMP(int x) { cout << "!!!" << x << "!!!" << endl; }
ll GCD(ll a, ll b) {
ll c;
while (b != 0) {
c = a % b;
a = b;
b = c;
}
return a;
}
ll LCM(ll a, ll b) { return (a / GCD(a, b)) * (b / GCD(a, b)) * GCD(a, b); }
ll POW(ll a, ll b) {
ll c = 1;
while (b > 0) {
if (b & 1) {
c = a * c % mod;
}
a = a * a % mod;
b >>= 1;
}
return c;
}
void PRI(ll n) {
bool a[n + 1LL];
for (int i = 0; i < n + 1LL; i++) {
a[i] = 1LL;
}
for (int i = 2; i < n + 1LL; i++) {
if (a[i]) {
prime.pb(i);
ll b = i;
while (b <= n) {
a[b] = 0;
b += i;
}
}
}
}
template <typename T> T chmin(T &a, T b) {
if (a > b)
a = b;
return a;
}
template <typename T> T chmax(T &a, T b) {
if (a < b)
a = b;
return b;
}
bool isSqrt(ll a) { return pow(sqrt(a), 2) == a ? 1 : 0; }
void YesNo(bool a) {
if (a)
cout << "Yes";
else
cout << "No";
cout << endl;
}
void yesno(bool a) {
if (a)
cout << "yes";
else
cout << "no";
cout << endl;
}
void YESNO(bool a) {
if (a)
cout << "YES";
else
cout << "NO";
cout << endl;
}
double dis(int x1, int x2, int y1, int y2) {
return sqrt((double)abs(x1 - x2) * (double)abs(x1 - x2) +
(double)abs(y1 - y2) * (double)abs(y1 - y2));
}
class topological {
public:
bool uniq = true, can = true;
int maxlen = 0;
int n;
queue<int> cnt;
vector<int> in;
vector<int> len;
vector<vector<int>> loute;
vector<int> res;
topological(vector<vector<int>> lt) {
loute = lt;
n = loute.size();
in = vector<int>(n);
len = vector<int>(n);
for (auto &&from : loute) {
for (auto &&to : from) {
in[to]++;
}
}
for (int i = 0; i < n; i++) {
if (!in[i]) {
cnt.push(i);
}
}
}
void run() {
while (!cnt.empty()) {
int nxt = cnt.front();
cnt.pop();
if (cnt.size())
uniq = false;
res.pb(nxt);
for (auto &&to : loute[nxt]) {
--in[to];
if (!in[to])
cnt.push(to);
len[to] = max(len[to], len[nxt] + 1);
}
}
if (res.size() != n)
can = false;
for (int i = 0; i < n; i++) {
maxlen = max(maxlen, len[i]);
}
}
};
void solve() {
int n;
cin >> n;
int ma[n][n];
int p = 0;
rep(i, n) {
FOR(j, i + 1, n) {
ma[i][j] = p;
p++;
}
}
vector<vector<int>> ed(n * (n - 1) / 2);
int A[n][n - 1];
rep(i, n) {
rep(j, n - 1) {
int a;
cin >> a;
A[i][j] = --a;
}
}
rep(i, n) {
FOR(j, 1, n - 1) {
int mae = A[i][j - 1];
int ato = A[i][j];
// cout << ma[{min(i,mae),max(i,mae)}] << " " <<
// ma[{min(i,ato),max(i,ato)}] << endl;
ed[ma[min(i, mae)][max(i, mae)]].pb(ma[min(i, ato)][max(i, ato)]);
}
}
topological topo(ed);
topo.run();
cout << (topo.can ? topo.maxlen + 1 : -1) << endl;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
solve();
}
|
[
"expression.operation.binary.add"
] | 729,392
| 729,393
|
u764234894
|
cpp
|
p02925
|
#include <iostream>
#include <queue>
using namespace std;
int main() {
int a[1000][1000];
int n;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - 1; j++) {
cin >> a[i][j];
a[i][j]--;
}
}
int ind[1000];
for (int i = 0; i < n; i++) {
ind[i] = 0;
}
int count = 1;
int ans = 0;
queue<int> ho;
for (int i = 0; i < n; i++) {
ho.push(i);
}
while (count > 0) {
count = 0;
int temp[1000];
for (int i = 0; i < n; i++) {
temp[i] = 0;
}
int u = ho.size();
for (int j = 0; j < u; j++) {
int i = ho.front();
ho.pop();
if (ind[i] < n - 1) {
if (ind[a[i][ind[i]]] < n - 1) {
if (a[a[i][ind[i]]][ind[a[i][ind[i]]]] == i and temp[i] == 0) {
temp[i]++;
temp[a[i][ind[i]]]++;
count++;
ho.push(i);
ho.push(ind[i]);
}
}
}
}
if (count > 0) {
ans++;
}
for (int i = 0; i < n; i++) {
ind[i] += temp[i];
}
}
for (int i = 0; i < n; i++) {
if (ind[i] != n - 1) {
cout << -1 << endl;
return 0;
}
}
cout << ans << endl;
return 0;
}
|
#include <iostream>
#include <queue>
using namespace std;
int main() {
int a[1000][1000];
int n;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - 1; j++) {
cin >> a[i][j];
a[i][j]--;
}
}
int ind[1000];
for (int i = 0; i < n; i++) {
ind[i] = 0;
}
int count = 1;
int ans = 0;
queue<int> ho;
for (int i = 0; i < n; i++) {
ho.push(i);
}
while (count > 0) {
count = 0;
int temp[1000];
for (int i = 0; i < n; i++) {
temp[i] = 0;
}
int u = ho.size();
for (int j = 0; j < u; j++) {
int i = ho.front();
ho.pop();
if (ind[i] < n - 1) {
if (ind[a[i][ind[i]]] < n - 1) {
if (a[a[i][ind[i]]][ind[a[i][ind[i]]]] == i and temp[i] == 0) {
temp[i]++;
temp[a[i][ind[i]]]++;
count++;
ho.push(i);
ho.push(a[i][ind[i]]);
}
}
}
}
if (count > 0) {
ans++;
}
for (int i = 0; i < n; i++) {
ind[i] += temp[i];
}
}
for (int i = 0; i < n; i++) {
if (ind[i] != n - 1) {
cout << -1 << endl;
return 0;
}
}
cout << ans << endl;
return 0;
}
|
[
"call.arguments.add",
"call.arguments.change"
] | 729,396
| 729,397
|
u023751250
|
cpp
|
p02925
|
#include <bitset>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>
typedef long long ll;
using std::vector;
template <typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template <typename T, typename... Args>
void ndarray(vector<T> &vec, int len, Args... args) {
vec.resize(len);
for (auto &v : vec)
ndarray(v, args...);
}
//////////////////////////////////////
enum Status {
Not = 0,
Now,
End,
};
int dfs(int now, int par, vector<vector<int>> &ki, vector<Status> &status,
vector<vector<int>> &res, int depth) {
// std::cout << "searching now: " << now << std::endl;
status[now] = Status::Now;
int maxdepth = depth;
for (auto chi : ki[now]) {
//繋がったノードを取り出す
if (chi == par) {
//親に戻る
return -1;
}
if (status[chi] == Status::Now) {
//ループ検出
return -1;
} else if (status[chi] == Status::End) {
//探索済み:再度探索する理由はない
maxdepth = std::max(maxdepth, depth - res[chi][0] + res[chi][1]);
} else {
int tmp = dfs(chi, now, ki, status, res, depth + 1);
if (tmp == -1) {
return -1;
}
maxdepth = std::max(maxdepth, tmp);
}
}
status[now] = Status::End;
res[now] = {depth, maxdepth};
return maxdepth;
}
//////////////////////////////////////
int main() {
// std::ifstream in("0_normal_2");
// std::cin.rdbuf(in.rdbuf());
int N;
std::cin >> N;
int size = (N * (N - 1)) / 2 + 1;
vector<vector<int>> ki;
vector<Status> status;
vector<vector<int>> res;
ki.resize(size);
status.resize(size);
ndarray(res, size, 2);
//試合に番号をつける:i < j, i vs j = i*(n-1) - (i*(i+1))/2 + j
//試合xの翌日の試合をxの子とする
//この木の最大深さが答え、ループが存在すれば不可能
for (int i = 0; i < N; i++) {
int game2 = -1;
for (int j = 0; j < N - 1; j++) {
int a, game;
std::cin >> a;
a -= 1;
if (i < a) {
game = i * (N - 1) - (i * (i + 1)) / 2 + a;
} else {
game = a * (N - 1) - (a * (a + 1)) / 2 + i;
}
if (game2 != -1) {
ki[game2].push_back(game);
}
game2 = game;
}
}
for (int g = 1; g <= (N * (N - 1)) / 2; g++) {
ki[0].push_back(g);
}
int ans = dfs(0, 0, ki, status, res, 0);
std::cout << ans << std::endl;
return 0;
}
|
#include <bitset>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>
typedef long long ll;
using std::vector;
template <typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template <typename T, typename... Args>
void ndarray(vector<T> &vec, int len, Args... args) {
vec.resize(len);
for (auto &v : vec)
ndarray(v, args...);
}
//////////////////////////////////////
enum Status {
Not = 0,
Now,
End,
};
int dfs(int now, int par, vector<vector<int>> &ki, vector<Status> &status,
vector<vector<int>> &res, int depth) {
// std::cout << "searching now: " << now << std::endl;
status[now] = Status::Now;
int maxdepth = depth;
for (auto chi : ki[now]) {
//繋がったノードを取り出す
if (chi == par) {
//親に戻る
return -1;
}
if (status[chi] == Status::Now) {
//ループ検出
return -1;
} else if (status[chi] == Status::End) {
//探索済み:再度探索する理由はない
maxdepth = std::max(maxdepth, depth - res[chi][0] + res[chi][1] + 1);
} else {
int tmp = dfs(chi, now, ki, status, res, depth + 1);
if (tmp == -1) {
return -1;
}
maxdepth = std::max(maxdepth, tmp);
}
}
status[now] = Status::End;
res[now] = {depth, maxdepth};
return maxdepth;
}
//////////////////////////////////////
int main() {
// std::ifstream in("0_normal_2");
// std::cin.rdbuf(in.rdbuf());
int N;
std::cin >> N;
int size = (N * (N - 1)) / 2 + 1;
vector<vector<int>> ki;
vector<Status> status;
vector<vector<int>> res;
ki.resize(size);
status.resize(size);
ndarray(res, size, 2);
//試合に番号をつける:i < j, i vs j = i*(n-1) - (i*(i+1))/2 + j
//試合xの翌日の試合をxの子とする
//この木の最大深さが答え、ループが存在すれば不可能
for (int i = 0; i < N; i++) {
int game2 = -1;
for (int j = 0; j < N - 1; j++) {
int a, game;
std::cin >> a;
a -= 1;
if (i < a) {
game = i * (N - 1) - (i * (i + 1)) / 2 + a;
} else {
game = a * (N - 1) - (a * (a + 1)) / 2 + i;
}
if (game2 != -1) {
ki[game2].push_back(game);
}
game2 = game;
}
}
for (int g = 1; g <= (N * (N - 1)) / 2; g++) {
ki[0].push_back(g);
}
int ans = dfs(0, 0, ki, status, res, 0);
std::cout << ans << std::endl;
return 0;
}
|
[
"assignment.change"
] | 729,398
| 729,399
|
u888094685
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9 + 7, INF = 1e18;
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;
}
signed main() {
int N;
cin >> N;
vector<vector<int>> a(N, vector<int>(N - 1));
set<pair<int, int>> flg;
vector<int> to(N, -1);
REP(i, N) REP(j, N - 1) {
cin >> a[i][j];
a[i][j]--;
if (j == 0) {
to[i] = a[i][j];
}
}
vector<int> now(N, 0);
REP(i, N) {
if (to[to[i]] = i) {
flg.insert({min(i, to[i]), max(i, to[i])});
}
}
vector<int> day(N, 0);
while (!flg.empty()) {
auto p = *flg.begin();
flg.erase(flg.begin());
int ma = max(day[p.first], day[p.second]);
day[p.first] = day[p.second] = ma + 1;
now[p.first]++;
now[p.second]++;
if (now[p.first] < N - 1)
to[p.first] = a[p.first][now[p.first]];
if (now[p.second] < N - 1)
to[p.second] = a[p.second][now[p.second]];
if (now[p.first] < N - 1 && to[to[p.first]] == p.first)
flg.insert({min(p.first, to[p.first]), max(p.first, to[p.first])});
if (now[p.second] < N - 1 && to[to[p.second]] == p.second)
flg.insert({min(p.second, to[p.second]), max(p.second, to[p.second])});
}
int ok = 1;
REP(i, N) if (now[i] != N - 1) ok = 0;
int ma = 0;
REP(i, N) CHMAX(ma, day[i]);
if (ok)
cout << ma << endl;
else
cout << -1 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9 + 7, INF = 1e18;
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;
}
signed main() {
int N;
cin >> N;
vector<vector<int>> a(N, vector<int>(N - 1));
set<pair<int, int>> flg;
vector<int> to(N, -1);
REP(i, N) REP(j, N - 1) {
cin >> a[i][j];
a[i][j]--;
if (j == 0) {
to[i] = a[i][j];
}
}
vector<int> now(N, 0);
REP(i, N) {
if (to[to[i]] == i) {
flg.insert({min(i, to[i]), max(i, to[i])});
}
}
vector<int> day(N, 0);
while (!flg.empty()) {
auto p = *flg.begin();
flg.erase(flg.begin());
int ma = max(day[p.first], day[p.second]);
day[p.first] = day[p.second] = ma + 1;
now[p.first]++;
now[p.second]++;
if (now[p.first] < N - 1)
to[p.first] = a[p.first][now[p.first]];
if (now[p.second] < N - 1)
to[p.second] = a[p.second][now[p.second]];
if (now[p.first] < N - 1 && to[to[p.first]] == p.first)
flg.insert({min(p.first, to[p.first]), max(p.first, to[p.first])});
if (now[p.second] < N - 1 && to[to[p.second]] == p.second)
flg.insert({min(p.second, to[p.second]), max(p.second, to[p.second])});
}
int ok = 1;
REP(i, N) if (now[i] != N - 1) ok = 0;
int ma = 0;
REP(i, N) CHMAX(ma, day[i]);
if (ok)
cout << ma << endl;
else
cout << -1 << endl;
}
|
[
"expression.operation.compare.replace.add",
"assignment.replace.remove",
"misc.typo"
] | 729,415
| 729,416
|
u693027786
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
#define N 1003
int Q[N * N], HEAD[N * N], Ne[N * N], E[N * N], V[N];
int To[N * N], b, n, Num[N][N], A[N], cnt, t, h, q;
void ADD(int s, int e) { Ne[++b] = HEAD[s], HEAD[s] = b, E[b] = e, To[e]++; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
Num[i][j] = Num[j][i] = i * n + j;
for (int i = 1; i <= n; i++) {
for (int j = 1; j < n; j++) {
scanf("%d", &A[j]);
if (j ^ 1)
ADD(Num[i][A[j - 1]], Num[i][A[j]]);
}
}
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++) {
cnt++;
if (To[Num[i][j]] == 0)
Q[++t] = Num[i][j], V[Num[i][j]] = 0;
}
while (h < t) {
q = Q[++h];
for (int z = HEAD[q]; z; z = Ne[z]) {
To[E[z]]--;
if (!To[E[z]])
V[E[z]] = V[q] + 1, Q[++t] = E[z];
}
}
if (t != cnt)
puts("-1");
else
printf("%d\n", V[Q[t]]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define N 1003
int Q[N * N], HEAD[N * N], Ne[N * N], E[N * N], V[N * N];
int To[N * N], b, n, Num[N][N], A[N], cnt, t, h, q;
void ADD(int s, int e) { Ne[++b] = HEAD[s], HEAD[s] = b, E[b] = e, To[e]++; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
Num[i][j] = Num[j][i] = i * n + j;
for (int i = 1; i <= n; i++) {
for (int j = 1; j < n; j++) {
scanf("%d", &A[j]);
if (j ^ 1)
ADD(Num[i][A[j - 1]], Num[i][A[j]]);
}
}
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++) {
cnt++;
if (To[Num[i][j]] == 0)
Q[++t] = Num[i][j], V[Num[i][j]] = 1;
}
while (h < t) {
q = Q[++h];
for (int z = HEAD[q]; z; z = Ne[z]) {
To[E[z]]--;
if (!To[E[z]])
V[E[z]] = V[q] + 1, Q[++t] = E[z];
}
}
if (t != cnt)
puts("-1");
else
printf("%d\n", V[Q[t]]);
return 0;
}
|
[
"literal.number.change",
"assignment.value.change"
] | 729,426
| 729,425
|
u399268660
|
cpp
|
p02925
|
#include <iostream>
#include <queue>
using namespace std;
queue<int> q[1000];
int n, a, i, j;
int d[1000];
int c = 0, t = 0, now, l;
bool f;
int main() {
scanf("%d", &n);
for (i = 0; i < n; i++) {
for (j = 0; j < n - 1; j++) {
scanf("%d", &a);
q[i].push(a - 1);
}
d[i] = -1;
}
l = n * (n - 1) / 2;
while (true) {
f = false;
for (i = 0; i < n - 1; i++) {
if (!q[i].empty()) {
now = q[i].front();
if (!q[now].empty() && q[now].front() == i) {
if (d[i] != c && d[now] != c)
continue;
q[i].pop(), q[now].pop();
d[i] = c, d[now] = c;
f = true;
t++;
}
}
}
c++;
if (!f) {
cout << "-1" << endl;
return 0;
}
if (t == l) {
cout << c << endl;
return 0;
}
}
}
|
#include <iostream>
#include <queue>
using namespace std;
queue<int> q[1000];
int n, a, i, j;
int d[1000];
int c = 0, t = 0, now, l;
bool f;
int main() {
scanf("%d", &n);
for (i = 0; i < n; i++) {
for (j = 0; j < n - 1; j++) {
scanf("%d", &a);
q[i].push(a - 1);
}
d[i] = -1;
}
l = n * (n - 1) / 2;
while (true) {
f = false;
for (i = 0; i < n - 1; i++) {
if (!q[i].empty()) {
now = q[i].front();
if (!q[now].empty() && q[now].front() == i) {
if (d[i] == c || d[now] == c)
continue;
q[i].pop(), q[now].pop();
d[i] = c, d[now] = c;
f = true;
t++;
}
}
}
c++;
if (!f) {
cout << "-1" << endl;
return 0;
}
if (t == l) {
cout << c << endl;
return 0;
}
}
}
|
[
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 729,436
| 729,437
|
u069877747
|
cpp
|
p02925
|
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[]) {
clock_t starttime = clock();
int n;
cin >> n;
vector<vector<int>> v(n, vector<int>(n - 1));
vector<int> ind(n, 0);
vector<bool> isok(n, true);
int ans = 0;
int cnt = 0;
bool f = true;
rep(i, n) {
rep(j, n - 1) {
scanf("%d", &v[i][j]);
v[i][j]--;
}
}
while (cnt < n * (n - 1) / 2 && f) {
if (double(clock() - starttime) / CLOCKS_PER_SEC < 1.9) {
printf("%d\n", n * (n - 1) / 2);
return 0;
}
f = false;
vector<bool> usedturn(n, false);
vector<vector<bool>> used(n, vector<bool>(n - 1, false));
rep(i, n) {
int cur = i;
if (ind[cur] == n - 1) {
continue;
}
int next = v[cur][ind[cur]];
if (usedturn[cur] == true || usedturn[next] == true) {
continue;
}
if (ind[next] == n - 1) {
continue;
}
if (v[next][ind[next]] != cur) {
continue;
}
// cerr << "turn " << ans << " " << cur + 1 << "," << next + 1 << " " <<
// cnt << endl;
usedturn[next] = true;
usedturn[cur] = true;
used[next][next] = true;
used[cur][next] = true;
ind[cur]++;
ind[next]++;
cnt += 1;
f = true;
}
ans++;
}
if (f == false) {
printf("-1\n");
return 0;
}
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[]) {
clock_t starttime = clock();
int n;
cin >> n;
vector<vector<int>> v(n, vector<int>(n - 1));
vector<int> ind(n, 0);
vector<bool> isok(n, true);
int ans = 0;
int cnt = 0;
bool f = true;
rep(i, n) {
rep(j, n - 1) {
scanf("%d", &v[i][j]);
v[i][j]--;
}
}
while (cnt < n * (n - 1) / 2 && f) {
if (double(clock() - starttime) / CLOCKS_PER_SEC > 1.9) {
printf("%d\n", n * (n - 1) / 2);
return 0;
}
f = false;
vector<bool> usedturn(n, false);
vector<vector<bool>> used(n, vector<bool>(n - 1, false));
rep(i, n) {
int cur = i;
if (ind[cur] == n - 1) {
continue;
}
int next = v[cur][ind[cur]];
if (usedturn[cur] == true || usedturn[next] == true) {
continue;
}
if (ind[next] == n - 1) {
continue;
}
if (v[next][ind[next]] != cur) {
continue;
}
// cerr << "turn " << ans << " " << cur + 1 << "," << next + 1 << " " <<
// cnt << endl;
usedturn[next] = true;
usedturn[cur] = true;
used[next][next] = true;
used[cur][next] = true;
ind[cur]++;
ind[next]++;
cnt += 1;
f = true;
}
ans++;
}
if (f == false) {
printf("-1\n");
return 0;
}
printf("%d\n", ans);
return 0;
}
|
[
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 729,442
| 729,443
|
u174404613
|
cpp
|
p02925
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define LL long long
using namespace std;
struct graph {
int to, next;
} gr[1000005];
int n, num, cnt, tot, ans, head[1000005], a[1005][1005], c[1005][1005],
in[1000005], t[1000005], day[1000005];
void border(int u, int v) {
cnt++;
gr[cnt].to = v;
gr[cnt].next = head[u];
head[u] = cnt;
return;
}
void topsort() {
for (int i = 1; i <= tot; i++) {
int u = t[i];
for (int j = head[u]; j; j = gr[j].next) {
int v = gr[j].to;
day[v] = day[i] + 1;
in[v]--;
if (!in[v])
t[++tot] = v;
}
}
for (int i = 1; i <= num; i++)
ans = max(ans, day[i]);
return;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j < n; j++) {
scanf("%d", &a[i][j]);
if (!c[i][j] && !c[j][i])
c[i][j] = c[j][i] = ++num;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 2; j < n; j++) {
border(c[i][a[i][j - 1]], c[i][a[i][j]]);
in[c[i][a[i][j]]]++;
}
}
for (int i = 1; i <= num; i++)
if (!in[i]) {
t[++tot] = i;
day[i] = 1;
}
topsort();
if (ans == 1)
puts("-1");
else
printf("%d\n", ans);
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define LL long long
using namespace std;
struct graph {
int to, next;
} gr[1000005];
int n, num, cnt, tot, ans, head[1000005], a[1005][1005], c[1005][1005],
in[1000005], t[1000005], day[1000005];
void border(int u, int v) {
cnt++;
gr[cnt].to = v;
gr[cnt].next = head[u];
head[u] = cnt;
return;
}
void topsort() {
for (int i = 1; i <= tot; i++) {
int u = t[i];
for (int j = head[u]; j; j = gr[j].next) {
int v = gr[j].to;
day[v] = day[u] + 1;
in[v]--;
if (!in[v])
t[++tot] = v;
}
}
for (int i = 1; i <= num; i++)
ans = max(ans, day[i]);
return;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j < n; j++) {
scanf("%d", &a[i][j]);
if (!c[i][j] && !c[j][i])
c[i][j] = c[j][i] = ++num;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 2; j < n; j++) {
border(c[i][a[i][j - 1]], c[i][a[i][j]]);
in[c[i][a[i][j]]]++;
}
}
for (int i = 1; i <= num; i++)
if (!in[i]) {
t[++tot] = i;
day[i] = 1;
}
topsort();
if (tot != num)
puts("-1");
else
printf("%d\n", ans);
return 0;
}
|
[
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change"
] | 729,449
| 729,450
|
u296197760
|
cpp
|
p02925
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
// const ll mod = 998244353 ;
const ll mod = 1000000007;
const ll inf = 1e18;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define REP_REV(i, n) for (ll i = n - 1; i >= 0; --i)
#define REP_FROM_REV(i, j, n) for (ll i = n - 1; i >= j; --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ll(x.size())
template <typename T> inline T chmax(T &a, const T b) {
return a = (a < b) ? b : a;
}
template <typename T> inline T chmin(T &a, const T b) {
return a = (a > b) ? b : a;
}
ll power(ll base, ll exponent) {
if (exponent % 2) {
return power(base, exponent - 1) * base % mod;
} else if (exponent) {
ll root_ans = power(base, exponent / 2);
return root_ans * root_ans % mod;
} else {
return 1;
}
}
ll inverse(ll x) { return power(x, mod - 2); }
ll gcd(ll a, ll b) {
if (a < b)
gcd(b, a);
ll r;
while (r = a % b) {
a = b;
b = r;
}
return b;
}
template <typename T> ll sum(T begin, T end) {
return accumulate(begin, end, 0ll);
}
struct combination {
vector<ll> fact, inv;
combination(int sz) : fact(sz + 1), inv(sz + 1) {
fact[0] = 1;
for (int i = 1; i <= sz; i++) {
fact[i] = fact[i - 1] * i % mod;
}
inv[sz] = power(fact[sz], mod - 2);
for (int i = sz - 1; i >= 0; i--) {
inv[i] = inv[i + 1] * (i + 1) % mod;
}
}
ll C(int p, int q) const {
if (q < 0 || p < q)
return 0;
return (fact[p] * inv[q] % mod * inv[p - q] % mod);
}
};
using Pair = pair<ll, ll>;
template <ll Modulus> struct ModInt {
ll a;
constexpr ModInt(const ll x = 0) noexcept : a((x % mod + mod) % mod) {}
constexpr ll &value() noexcept { return a; }
constexpr const ll &value() const noexcept { return a; }
constexpr ModInt operator+(const ModInt x) const noexcept {
return ModInt(*this) += x;
}
constexpr ModInt operator-(const ModInt x) const noexcept {
return ModInt(*this) -= x;
}
constexpr ModInt operator*(const ModInt x) const noexcept {
return ModInt(*this) *= x;
}
constexpr ModInt operator/(const ModInt x) const noexcept {
return ModInt(*this) /= x;
}
constexpr ModInt &operator+=(const ModInt x) noexcept {
a += x.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
constexpr ModInt &operator-=(const ModInt x) noexcept {
if (a < x.a) {
a += Modulus;
}
a -= x.a;
return *this;
}
constexpr ModInt &operator*=(const ModInt x) noexcept {
a = a * x.a % Modulus;
return *this;
}
constexpr ModInt &operator/=(ModInt x) noexcept {
ll exp = Modulus - 2;
while (exp) {
if (exp % 2) {
*this *= x;
}
x *= x;
exp /= 2;
}
return *this;
}
constexpr ModInt operator-() noexcept { return ModInt(-a); }
friend ostream &operator<<(ostream &os, const ModInt &m) {
os << m.a;
return os;
}
};
using mint = ModInt<mod>;
vector<vector<int>> g;
vector<int> dp;
vector<int> visited;
vector<int> calculated;
int dfs(int cur) {
if (calculated[cur])
return dp[cur];
if (visited[cur] && calculated[cur] == 0)
return -1;
visited[cur] = 1;
dp[cur] = 1;
for (int p : g[cur]) {
int v = dfs(p);
if (v == -1)
return -1;
dp[cur] = max(dp[cur], v + 1);
}
calculated[cur] = 1;
return dp[cur];
}
signed main() {
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
ll n;
cin >> n;
g.resize(n * (n - 1));
dp.resize(n * (n - 1));
visited.resize(n * (n - 1));
calculated.resize(n * (n - 1));
auto toId = [&](int a, int b) {
if (a > b)
swap(a, b);
return a * n + b;
};
REP(i, n) {
int a;
cin >> a;
a--;
int prev = toId(i, a);
REP(j, n - 2) {
int b;
cin >> b;
b--;
int cur = toId(i, b);
g[prev].push_back(cur);
prev = cur;
}
}
auto ans = 0;
REP(i, n) {
int v = dfs(i);
if (v < 0) {
ans = -1;
break;
}
ans = max(ans, v);
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
// const ll mod = 998244353 ;
const ll mod = 1000000007;
const ll inf = 1e18;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define REP_REV(i, n) for (ll i = n - 1; i >= 0; --i)
#define REP_FROM_REV(i, j, n) for (ll i = n - 1; i >= j; --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ll(x.size())
template <typename T> inline T chmax(T &a, const T b) {
return a = (a < b) ? b : a;
}
template <typename T> inline T chmin(T &a, const T b) {
return a = (a > b) ? b : a;
}
ll power(ll base, ll exponent) {
if (exponent % 2) {
return power(base, exponent - 1) * base % mod;
} else if (exponent) {
ll root_ans = power(base, exponent / 2);
return root_ans * root_ans % mod;
} else {
return 1;
}
}
ll inverse(ll x) { return power(x, mod - 2); }
ll gcd(ll a, ll b) {
if (a < b)
gcd(b, a);
ll r;
while (r = a % b) {
a = b;
b = r;
}
return b;
}
template <typename T> ll sum(T begin, T end) {
return accumulate(begin, end, 0ll);
}
struct combination {
vector<ll> fact, inv;
combination(int sz) : fact(sz + 1), inv(sz + 1) {
fact[0] = 1;
for (int i = 1; i <= sz; i++) {
fact[i] = fact[i - 1] * i % mod;
}
inv[sz] = power(fact[sz], mod - 2);
for (int i = sz - 1; i >= 0; i--) {
inv[i] = inv[i + 1] * (i + 1) % mod;
}
}
ll C(int p, int q) const {
if (q < 0 || p < q)
return 0;
return (fact[p] * inv[q] % mod * inv[p - q] % mod);
}
};
using Pair = pair<ll, ll>;
template <ll Modulus> struct ModInt {
ll a;
constexpr ModInt(const ll x = 0) noexcept : a((x % mod + mod) % mod) {}
constexpr ll &value() noexcept { return a; }
constexpr const ll &value() const noexcept { return a; }
constexpr ModInt operator+(const ModInt x) const noexcept {
return ModInt(*this) += x;
}
constexpr ModInt operator-(const ModInt x) const noexcept {
return ModInt(*this) -= x;
}
constexpr ModInt operator*(const ModInt x) const noexcept {
return ModInt(*this) *= x;
}
constexpr ModInt operator/(const ModInt x) const noexcept {
return ModInt(*this) /= x;
}
constexpr ModInt &operator+=(const ModInt x) noexcept {
a += x.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
constexpr ModInt &operator-=(const ModInt x) noexcept {
if (a < x.a) {
a += Modulus;
}
a -= x.a;
return *this;
}
constexpr ModInt &operator*=(const ModInt x) noexcept {
a = a * x.a % Modulus;
return *this;
}
constexpr ModInt &operator/=(ModInt x) noexcept {
ll exp = Modulus - 2;
while (exp) {
if (exp % 2) {
*this *= x;
}
x *= x;
exp /= 2;
}
return *this;
}
constexpr ModInt operator-() noexcept { return ModInt(-a); }
friend ostream &operator<<(ostream &os, const ModInt &m) {
os << m.a;
return os;
}
};
using mint = ModInt<mod>;
vector<vector<int>> g;
vector<int> dp;
vector<int> visited;
vector<int> calculated;
int dfs(int cur) {
if (calculated[cur])
return dp[cur];
if (visited[cur] && calculated[cur] == 0)
return -1;
visited[cur] = 1;
dp[cur] = 1;
for (int p : g[cur]) {
int v = dfs(p);
if (v == -1)
return -1;
dp[cur] = max(dp[cur], v + 1);
}
calculated[cur] = 1;
return dp[cur];
}
signed main() {
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
ll n;
cin >> n;
g.resize(n * (n - 1));
dp.resize(n * (n - 1));
visited.resize(n * (n - 1));
calculated.resize(n * (n - 1));
auto toId = [&](int a, int b) {
if (a > b)
swap(a, b);
return a * n + b;
};
REP(i, n) {
int a;
cin >> a;
a--;
int prev = toId(i, a);
REP(j, n - 2) {
int b;
cin >> b;
b--;
int cur = toId(i, b);
g[prev].push_back(cur);
prev = cur;
}
}
auto ans = 0;
REP(i, n * (n - 1)) {
int v = dfs(i);
if (v < 0) {
ans = -1;
break;
}
ans = max(ans, v);
}
cout << ans << endl;
return 0;
}
|
[
"expression.operation.binary.add"
] | 729,497
| 729,498
|
u702582248
|
cpp
|
p02925
|
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
#define SIZE 1005
int N;
int table[SIZE][SIZE];
int loc[SIZE];
bool check(int node_id) {
if (loc[node_id] == N - 1)
return false;
int next = table[node_id][loc[node_id]];
if (loc[next] == N - 1)
return false;
return table[next][loc[next]] == node_id;
}
int main() {
scanf("%d", &N);
for (int i = 0; i < N; i++) {
for (int k = 0; k < N - 1; k++) {
scanf("%d", &table[i][k]);
table[i][k]--;
}
}
for (int i = 0; i < N; i++) {
loc[i] = 0;
}
int CURRENT = 0, NEXT = 1;
vector<pair<int, int>> V[2];
for (int i = 0; i < N; i++) {
if (check(i)) {
int next = table[i][loc[i]];
V[CURRENT].push_back(make_pair(min(i, next), max(i, next)));
}
}
int ans = -1;
for (int day = 1; day < 5; day++) {
if (V[CURRENT].size() == 0)
break;
ans = day;
sort(V[CURRENT].begin(), V[CURRENT].end());
V[CURRENT].erase(unique(V[CURRENT].begin(), V[CURRENT].end()),
V[CURRENT].end());
for (int i = 0; i < V[CURRENT].size(); i++) {
int a = V[CURRENT][i].first;
int b = V[CURRENT][i].second;
loc[a]++;
loc[b]++;
if (check(a)) {
int next = table[a][loc[a]];
V[NEXT].push_back(make_pair(min(a, next), max(a, next)));
}
if (check(b)) {
int next = table[b][loc[b]];
V[NEXT].push_back(make_pair(min(b, next), max(b, next)));
}
}
V[CURRENT].clear();
swap(CURRENT, NEXT);
}
for (int i = 0; i < N; i++) {
if (loc[i] != N - 1) {
printf("-1\n");
return 0;
}
}
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
#define SIZE 1005
int N;
int table[SIZE][SIZE];
int loc[SIZE];
bool check(int node_id) {
if (loc[node_id] == N - 1)
return false;
int next = table[node_id][loc[node_id]];
if (loc[next] == N - 1)
return false;
return table[next][loc[next]] == node_id;
}
int main() {
scanf("%d", &N);
for (int i = 0; i < N; i++) {
for (int k = 0; k < N - 1; k++) {
scanf("%d", &table[i][k]);
table[i][k]--;
}
}
for (int i = 0; i < N; i++) {
loc[i] = 0;
}
int CURRENT = 0, NEXT = 1;
vector<pair<int, int>> V[2];
for (int i = 0; i < N; i++) {
if (check(i)) {
int next = table[i][loc[i]];
V[CURRENT].push_back(make_pair(min(i, next), max(i, next)));
}
}
int ans = -1;
for (int day = 1;; day++) {
if (V[CURRENT].size() == 0)
break;
ans = day;
sort(V[CURRENT].begin(), V[CURRENT].end());
V[CURRENT].erase(unique(V[CURRENT].begin(), V[CURRENT].end()),
V[CURRENT].end());
for (int i = 0; i < V[CURRENT].size(); i++) {
int a = V[CURRENT][i].first;
int b = V[CURRENT][i].second;
loc[a]++;
loc[b]++;
if (check(a)) {
int next = table[a][loc[a]];
V[NEXT].push_back(make_pair(min(a, next), max(a, next)));
}
if (check(b)) {
int next = table[b][loc[b]];
V[NEXT].push_back(make_pair(min(b, next), max(b, next)));
}
}
V[CURRENT].clear();
swap(CURRENT, NEXT);
}
for (int i = 0; i < N; i++) {
if (loc[i] != N - 1) {
printf("-1\n");
return 0;
}
}
printf("%d\n", ans);
return 0;
}
|
[
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 729,504
| 729,505
|
u000022466
|
cpp
|
p02925
|
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef long double ld;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define F first
#define S second
const int mx = 100010;
const ll mod = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<vector<int>> d(n, vector<int>(n - 1, 0));
vector<int> cnt(n * n, 0);
vector<int> v[n * n];
rep(i, n) rep(j, n - 1) {
cin >> d[i][j];
d[i][j]--;
if (j != 0) {
int a = i, b = d[i][j - 1];
if (a > b)
swap(a, b);
int c = i, e = d[i][j];
if (c > e)
swap(c, e);
v[a * n + b].emplace_back(c * n + e);
cnt[c * n + e]++;
}
}
int ans = 0;
int vs = 0;
int pre = -1;
queue<int> q;
rep(i, n) rep(j, i) {
if (cnt[j * n + i] == 0) {
q.push(j * n + i);
}
}
while (pre != vs) {
ans++;
pre = vs;
queue<int> nq;
while (!q.empty()) {
int p = q.front();
q.pop();
for (auto it : v[p]) {
cnt[it]--;
if (cnt[it] == 0) {
nq.push(it);
vs++;
}
}
}
swap(q, nq);
}
if (vs != n * (n - 1) / 2) {
cout << -1 << endl;
return 0;
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef long double ld;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define F first
#define S second
const int mx = 100010;
const ll mod = 1e9 + 7;
int main() {
int n;
cin >> n;
vector<vector<int>> d(n, vector<int>(n - 1, 0));
vector<int> cnt(n * n, 0);
vector<int> v[n * n];
rep(i, n) rep(j, n - 1) {
cin >> d[i][j];
d[i][j]--;
if (j != 0) {
int a = i, b = d[i][j - 1];
if (a > b)
swap(a, b);
int c = i, e = d[i][j];
if (c > e)
swap(c, e);
v[a * n + b].emplace_back(c * n + e);
cnt[c * n + e]++;
}
}
int ans = 0;
int vs = 0;
int pre = -1;
queue<int> q;
rep(i, n) rep(j, i) {
if (cnt[j * n + i] == 0) {
q.push(j * n + i);
vs++;
}
}
while (pre != vs) {
ans++;
pre = vs;
queue<int> nq;
while (!q.empty()) {
int p = q.front();
q.pop();
for (auto it : v[p]) {
cnt[it]--;
if (cnt[it] == 0) {
nq.push(it);
vs++;
}
}
}
swap(q, nq);
}
if (vs != n * (n - 1) / 2) {
cout << -1 << endl;
return 0;
}
cout << ans << endl;
return 0;
}
|
[
"expression.unary.arithmetic.add"
] | 729,512
| 729,513
|
u980909653
|
cpp
|
p02925
|
#include <bits/stdc++.h>
#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)
using namespace std;
using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;
ll dfs(vector<set<ll>> &g, vector<bool> &seen, vector<ll> &depth, ll point) {
seen[point] = true;
ll ans = 1;
for (auto next : g[point]) {
if (depth[next] != 0) {
ans = max(ans, depth[next] + 1);
}
if (seen[next] && depth[next] == 0) {
ans = mod;
break;
}
ans = max(ans, dfs(g, seen, depth, next) + 1);
}
depth[point] = ans;
return ans;
}
int main() {
source:
ll n;
cin >> n;
ll a[n][n - 1];
ll memo[n][n - 1];
rep(i, n) {
rep(j, n - 1) {
cin >> a[i][j];
a[i][j]--;
ll small = min(i, a[i][j]);
ll big = max(i, a[i][j]);
ll index = (big - 1) * big / 2 + small;
memo[i][j] = index;
}
}
vector<set<ll>> g(n * (n - 1) / 2);
rep(i, n) {
rep(j, n - 2) { g[memo[i][j]].insert(memo[i][j + 1]); }
}
vector<bool> seen(n * (n - 1) / 2), finished(n * (n - 1) / 2);
vector<ll> depth(n * (n - 1) / 2, 0);
ll ans = 0;
rep(i, n * (n - 1) / 2) {
/* cout << depth[i] << " "; */
if (seen[i]) {
continue;
}
ll temp = dfs(g, seen, depth, i);
ans = max(ans, temp);
}
/* cout << endl; */
if (ans >= mod) {
ans = -1;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)
using namespace std;
using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;
ll dfs(vector<set<ll>> &g, vector<bool> &seen, vector<ll> &depth, ll point) {
seen[point] = true;
ll ans = 1;
for (auto next : g[point]) {
if (depth[next] != 0) {
ans = max(ans, depth[next] + 1);
continue;
}
if (seen[next] && depth[next] == 0) {
ans = mod;
break;
}
ans = max(ans, dfs(g, seen, depth, next) + 1);
}
depth[point] = ans;
return ans;
}
int main() {
source:
ll n;
cin >> n;
ll a[n][n - 1];
ll memo[n][n - 1];
rep(i, n) {
rep(j, n - 1) {
cin >> a[i][j];
a[i][j]--;
ll small = min(i, a[i][j]);
ll big = max(i, a[i][j]);
ll index = (big - 1) * big / 2 + small;
memo[i][j] = index;
}
}
vector<set<ll>> g(n * (n - 1) / 2);
rep(i, n) {
rep(j, n - 2) { g[memo[i][j]].insert(memo[i][j + 1]); }
}
vector<bool> seen(n * (n - 1) / 2), finished(n * (n - 1) / 2);
vector<ll> depth(n * (n - 1) / 2, 0);
ll ans = 0;
rep(i, n * (n - 1) / 2) {
if (seen[i]) {
continue;
}
ll temp = dfs(g, seen, depth, i);
ans = max(ans, temp);
}
if (ans >= mod) {
ans = -1;
}
cout << ans << endl;
return 0;
}
|
[] | 729,519
| 729,520
|
u030992242
|
cpp
|
p02925
|
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
bool seen[2000000]{};
bool finished[2000000]{};
int d[2000000]{};
int dfs(const Graph &G, int now) {
if (seen[now] == true)
return d[now];
seen[now] = true;
for (auto e : G[now]) {
if (seen[e] && !finished[e]) {
cout << -1 << endl;
exit(0);
}
if (seen[e])
d[now] = max(d[now], d[e]);
else
d[now] = max(d[now], dfs(G, e) + 1);
}
finished[now] = true;
return d[now];
}
int encode(int i, int j) {
if (i < j)
swap(i, j);
return i * (i - 1) / 2 + j + 1;
}
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N;
cin >> N;
Graph G(N * (N - 1) / 2 + 1);
rep(i, N) {
int now = 0;
rep(j, N - 1) {
int k;
cin >> k;
--k;
int next = encode(i, k);
G[now].push_back(next);
now = next;
}
}
cout << dfs(G, 0) << endl;
}
|
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
bool seen[2000000]{};
bool finished[2000000]{};
int d[2000000]{};
int dfs(const Graph &G, int now) {
if (seen[now] == true)
return d[now];
seen[now] = true;
for (auto e : G[now]) {
if (seen[e] && !finished[e]) {
cout << -1 << endl;
exit(0);
}
if (seen[e])
d[now] = max(d[now], d[e] + 1);
else
d[now] = max(d[now], dfs(G, e) + 1);
}
finished[now] = true;
return d[now];
}
int encode(int i, int j) {
if (i < j)
swap(i, j);
return i * (i - 1) / 2 + j + 1;
}
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N;
cin >> N;
Graph G(N * (N - 1) / 2 + 1);
rep(i, N) {
int now = 0;
rep(j, N - 1) {
int k;
cin >> k;
--k;
int next = encode(i, k);
G[now].push_back(next);
now = next;
}
}
cout << dfs(G, 0) << endl;
}
|
[
"assignment.change"
] | 729,521
| 729,522
|
u415916075
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
#define tii tuple<int, int, int>
#define Priq priority_queue<int, vi, greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll << 60)
signed main() {
int N;
cin >> N;
vector<vector<vector<pii>>> A(N, vector<vector<pii>>(N));
vii C(N, vi(N));
rep(i, 0, N) {
vi B(N - 1);
rep(j, 0, N - 1) cin >> B[j];
rep(j, 1, N - 1) {
int P = i, Q = B[j] - 1, R = B[j - 1] - 1, S = i;
if (P > Q)
swap(P, Q);
if (S > R)
swap(S, R);
A[S][R].pb(mp(P, Q));
C[P][Q]++;
}
}
stack<pii> Q;
rep(i, 0, N) {
rep(j, i + 1, N) {
if (C[i][j] == 0)
Q.push(mp(i, j));
}
}
vector<pii> D;
while (Q.size() > 0) {
int X = Q.top().first, Y = Q.top().second;
Q.pop();
D.pb(mp(X, Y));
rep(i, 0, A[X][Y].size()) {
int P = A[X][Y][i].first, R = A[X][Y][i].second;
C[P][R]--;
if (C[P][R] == 0)
Q.push(mp(P, R));
}
}
if (D.size() == N * (N - 1) / 2) {
vii dp(N, vi(N, 1));
rep(i, 0, D.size()) {
int X = D[i].first, Y = D[i].second;
rep(j, 0, A[X][Y].size()) {
int P = A[X][Y][i].first, R = A[X][Y][i].second;
dp[P][R] = max(dp[P][R], dp[X][Y] + 1);
}
}
int ans = 0;
rep(i, 0, N) { rep(j, 0, N) ans = max(ans, dp[i][j]); }
cout << ans << endl;
} else
cout << -1 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
#define tii tuple<int, int, int>
#define Priq priority_queue<int, vi, greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll << 60)
signed main() {
int N;
cin >> N;
vector<vector<vector<pii>>> A(N, vector<vector<pii>>(N));
vii C(N, vi(N));
rep(i, 0, N) {
vi B(N - 1);
rep(j, 0, N - 1) cin >> B[j];
rep(j, 1, N - 1) {
int P = i, Q = B[j] - 1, R = B[j - 1] - 1, S = i;
if (P > Q)
swap(P, Q);
if (S > R)
swap(S, R);
A[S][R].pb(mp(P, Q));
C[P][Q]++;
}
}
stack<pii> Q;
rep(i, 0, N) {
rep(j, i + 1, N) {
if (C[i][j] == 0)
Q.push(mp(i, j));
}
}
vector<pii> D;
while (Q.size() > 0) {
int X = Q.top().first, Y = Q.top().second;
Q.pop();
D.pb(mp(X, Y));
rep(i, 0, A[X][Y].size()) {
int P = A[X][Y][i].first, R = A[X][Y][i].second;
C[P][R]--;
if (C[P][R] == 0)
Q.push(mp(P, R));
}
}
if (D.size() == N * (N - 1) / 2) {
vii dp(N, vi(N, 1));
rep(i, 0, D.size()) {
int X = D[i].first, Y = D[i].second;
rep(j, 0, A[X][Y].size()) {
int P = A[X][Y][j].first, R = A[X][Y][j].second;
dp[P][R] = max(dp[P][R], dp[X][Y] + 1);
}
}
int ans = 0;
rep(i, 0, N) { rep(j, 0, N) ans = max(ans, dp[i][j]); }
cout << ans << endl;
} else
cout << -1 << endl;
}
|
[
"identifier.change",
"variable_access.subscript.index.change"
] | 729,546
| 729,547
|
u347057617
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef int64_t Int;
typedef pair<int, int> P;
int N;
vector<deque<int>> A(N);
vector<P> match;
// kさんが試合をできればmatchに代入する
void check(int i) {
if (A[i].size() == 0)
return;
int j = A[i].front();
if (A[j].front() == i) {
if (i > j)
swap(i, j);
match.push_back(P(i, j));
}
}
int main() {
cin >> N;
rep(i, N) rep(j, N - 1) {
int a;
cin >> a;
a--;
A[i].push_back(a);
}
rep(i, N) check(i);
int ans = 0;
while (!match.empty()) {
ans++;
sort(match.begin(), match.end());
match.erase(unique(match.begin(), match.end()), match.end());
vector<P> prev_match;
swap(prev_match, match);
for (P p : prev_match) {
int i = p.first, j = p.second;
A[i].pop_front();
A[j].pop_front();
}
for (P p : prev_match) {
int i = p.first, j = p.second;
check(i);
check(j);
}
}
rep(i, N) {
if (A[i].size() != 0) {
cout << -1 << endl;
return 0;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef int64_t Int;
typedef pair<int, int> P;
int N;
vector<deque<int>> A(1010);
vector<P> match;
// kさんが試合をできればmatchに代入する
void check(int i) {
if (A[i].size() == 0)
return;
int j = A[i].front();
if (A[j].front() == i) {
if (i > j)
swap(i, j);
match.push_back(P(i, j));
}
}
int main() {
cin >> N;
rep(i, N) rep(j, N - 1) {
int a;
cin >> a;
a--;
A[i].push_back(a);
}
rep(i, N) check(i);
int ans = 0;
while (!match.empty()) {
ans++;
sort(match.begin(), match.end());
match.erase(unique(match.begin(), match.end()), match.end());
vector<P> prev_match;
swap(prev_match, match);
for (P p : prev_match) {
int i = p.first, j = p.second;
A[i].pop_front();
A[j].pop_front();
}
for (P p : prev_match) {
int i = p.first, j = p.second;
check(i);
check(j);
}
}
rep(i, N) {
if (A[i].size() != 0) {
cout << -1 << endl;
return 0;
}
}
cout << ans << endl;
}
|
[] | 729,556
| 729,557
|
u285358283
|
cpp
|
p02925
|
#include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> piiii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef queue<char> qc;
typedef queue<string> qs;
typedef vector<char> vc;
typedef vector<string> vs;
typedef map<char, int> mpci;
typedef map<int, int> mpii;
typedef map<string, int> mpsi;
typedef set<int> sei;
typedef set<char> sec;
typedef set<string> ses;
typedef stack<ll> si;
typedef stack<char> sc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<pll> vpll;
typedef vector<pdd> vdd;
typedef unsigned int uint;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vii> vvii;
/*=====================================================================*/
#define pb push_back
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define all(s) (s).begin(), (s).end()
#define fi first
#define se second
#define be begin
#define en end
#define m_p make_pair
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define forn(i, p, n) for (int i = p; i <= n; i++)
#define ford(i, p, n) for (int i = n; i >= p; i--)
#define foreach(i, c) \
for (__typeof(c.begin()) i = (c.begin()); i != (c).end(); ++i)
#define zero(a) memset(a, 0, sizeof(a))
#define number(a, num) memeset(a, num, sizeof(a))
/*=====================================================================*/
inline void read(int &x) {
short negative = 1;
x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
negative = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
x *= negative;
}
inline void write(long long x) {
static long long sta[35];
long long top = 0;
do {
sta[top++] = x % 10, x /= 10;
} while (x);
while (top)
putchar(sta[--top] + 48);
puts("");
}
void finish(string s) {
cout << s << endl;
exit(0);
}
/*======================================================================*/
bool prime(int n) {
if (n == 0 || n == 1)
return false;
for (int i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
const ll power(int n, int k) {
ll t = 1;
rep(i, k) t *= n;
return t;
}
const string turn2(int n) {
string s = "";
while (n != 0) {
s += (char)(n % 2 + '0');
n /= 2;
}
reverse(s.begin(), s.end());
return s;
}
string turn(int n, int k) {
string s = "";
while (n) {
s += (char)(n % k + '0');
n /= k;
}
reverse(s.begin(), s.end());
return s;
}
const string turn16(int n) {
string s = "";
while (n != 0) {
if (n % 16 > 9)
s += (char)('A' + n % 16 - 10);
else
s += (char)('0' + n % 16);
n /= 16;
}
reverse(s.begin(), s.end());
return s;
}
const ll quickpower(int n, int k) {
if (k == 1)
return n;
if (k % 2 == 1)
return n * quickpower(n, k / 2) * quickpower(n, k / 2);
else
return quickpower(n, k / 2) * (quickpower(n, k / 2));
}
/*
void merge(int a[],int left,int mid,int right)
{
int n1=mid-left;
int n2=right-mid;
for(int i=0;i<n1;i++)
{
l[i]=a[i+left];
}
for(int i=0;i<n2;i++)
{
r[i]=a[mid+i];
}
r[n2]=l[n1]=INF;
int i=0;
int j=0;
for(int k=left;k<right;k++)
{
if(l[i]<=r[j])
{
a[k]=l[i++];
}
else
{
a[k]=r[j++];
}
}
}
void mergesort(int a[],int left,int right)
{
if(left+1<right)
{
int mid=(left+right)/2;
mergesort(a,left,mid);
mergesort(a,mid,right);
merge(a,left,mid,right);
}
}
int binsearch(int x,int v[],int n)
{
int low=0,high=n-1;
int mid;
while(low<=high)
{
mid=(low+high)/2;
if(x<v[mid])
high=mid-1;
else
if(x>v[mid])
low=mid+1;
else
return mid+1;
}
return -1;
}
int partition(int a[],int left,int right)
{
int p=a[left];
int i=left;
int j=right+1;
for(;;)
{
while(a[++i]<p)
if(i>=right)
break;
while(a[j--]>p)
if(j<=left)
break;
if(i>=j)
break;
else
swap(a[i],a[j]);
}
if(j>=left)
return j;
swap(a[left],a[j]);
return j;
}
void quicksort(int a[],int left,int right)
{
int q;
while(right>left)
{
q=partition(a,left,right);
if(n-q+1==k)
{
cout<<a[q];
exit(0);
}
quicksort(a,left,q-1);
quicksort(a,q+1,right);
}
}
void dfs(int n)
{
if(use[n])
return;
use[n]=true;
cout<<n<<endl;
for(int i=0;i<v[n].size();i++)
dfs(v[n][i]);
}*/
/*======================================================================*/
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
queue<int> last, now;
int a[1010][1010];
int t[1010];
int dist[1010];
/*======================================================================*/
int main() {
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/
/*====================================================================*/
int n;
cin >> n;
forn(i, 1, n) {
forn(j, 1, n - 1) { cin >> a[i][j]; }
}
forn(i, 1, n) { last.push(i); }
int cnt = (n - 1) * n / 2;
rep(i, n * (n - 1) / 2) {
while (!last.empty()) {
int x = last.front();
last.pop();
t[x]++;
int y = a[x][t[x]];
// cout<<x<<" "<<y<<endl;
if (dist[y] == x) {
cnt--;
now.push(x);
now.push(y);
dist[x] = dist[y] = 0;
} else {
dist[x] = y;
}
}
// cout<<cnt<<endl;
swap(last, now);
// cout<<cnt<<endl;
if (cnt < 0) {
cout << i + 1 << endl;
return 0;
}
}
finish("-1");
return 0;
}
|
#include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> piiii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef queue<char> qc;
typedef queue<string> qs;
typedef vector<char> vc;
typedef vector<string> vs;
typedef map<char, int> mpci;
typedef map<int, int> mpii;
typedef map<string, int> mpsi;
typedef set<int> sei;
typedef set<char> sec;
typedef set<string> ses;
typedef stack<ll> si;
typedef stack<char> sc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<pll> vpll;
typedef vector<pdd> vdd;
typedef unsigned int uint;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vii> vvii;
/*=====================================================================*/
#define pb push_back
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define all(s) (s).begin(), (s).end()
#define fi first
#define se second
#define be begin
#define en end
#define m_p make_pair
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define forn(i, p, n) for (int i = p; i <= n; i++)
#define ford(i, p, n) for (int i = n; i >= p; i--)
#define foreach(i, c) \
for (__typeof(c.begin()) i = (c.begin()); i != (c).end(); ++i)
#define zero(a) memset(a, 0, sizeof(a))
#define number(a, num) memeset(a, num, sizeof(a))
/*=====================================================================*/
inline void read(int &x) {
short negative = 1;
x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
negative = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
x *= negative;
}
inline void write(long long x) {
static long long sta[35];
long long top = 0;
do {
sta[top++] = x % 10, x /= 10;
} while (x);
while (top)
putchar(sta[--top] + 48);
puts("");
}
void finish(string s) {
cout << s << endl;
exit(0);
}
/*======================================================================*/
bool prime(int n) {
if (n == 0 || n == 1)
return false;
for (int i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
const ll power(int n, int k) {
ll t = 1;
rep(i, k) t *= n;
return t;
}
const string turn2(int n) {
string s = "";
while (n != 0) {
s += (char)(n % 2 + '0');
n /= 2;
}
reverse(s.begin(), s.end());
return s;
}
string turn(int n, int k) {
string s = "";
while (n) {
s += (char)(n % k + '0');
n /= k;
}
reverse(s.begin(), s.end());
return s;
}
const string turn16(int n) {
string s = "";
while (n != 0) {
if (n % 16 > 9)
s += (char)('A' + n % 16 - 10);
else
s += (char)('0' + n % 16);
n /= 16;
}
reverse(s.begin(), s.end());
return s;
}
const ll quickpower(int n, int k) {
if (k == 1)
return n;
if (k % 2 == 1)
return n * quickpower(n, k / 2) * quickpower(n, k / 2);
else
return quickpower(n, k / 2) * (quickpower(n, k / 2));
}
/*
void merge(int a[],int left,int mid,int right)
{
int n1=mid-left;
int n2=right-mid;
for(int i=0;i<n1;i++)
{
l[i]=a[i+left];
}
for(int i=0;i<n2;i++)
{
r[i]=a[mid+i];
}
r[n2]=l[n1]=INF;
int i=0;
int j=0;
for(int k=left;k<right;k++)
{
if(l[i]<=r[j])
{
a[k]=l[i++];
}
else
{
a[k]=r[j++];
}
}
}
void mergesort(int a[],int left,int right)
{
if(left+1<right)
{
int mid=(left+right)/2;
mergesort(a,left,mid);
mergesort(a,mid,right);
merge(a,left,mid,right);
}
}
int binsearch(int x,int v[],int n)
{
int low=0,high=n-1;
int mid;
while(low<=high)
{
mid=(low+high)/2;
if(x<v[mid])
high=mid-1;
else
if(x>v[mid])
low=mid+1;
else
return mid+1;
}
return -1;
}
int partition(int a[],int left,int right)
{
int p=a[left];
int i=left;
int j=right+1;
for(;;)
{
while(a[++i]<p)
if(i>=right)
break;
while(a[j--]>p)
if(j<=left)
break;
if(i>=j)
break;
else
swap(a[i],a[j]);
}
if(j>=left)
return j;
swap(a[left],a[j]);
return j;
}
void quicksort(int a[],int left,int right)
{
int q;
while(right>left)
{
q=partition(a,left,right);
if(n-q+1==k)
{
cout<<a[q];
exit(0);
}
quicksort(a,left,q-1);
quicksort(a,q+1,right);
}
}
void dfs(int n)
{
if(use[n])
return;
use[n]=true;
cout<<n<<endl;
for(int i=0;i<v[n].size();i++)
dfs(v[n][i]);
}*/
/*======================================================================*/
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
queue<int> last, now;
int a[1010][1010];
int t[1010];
int dist[1010];
/*======================================================================*/
int main() {
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/
/*====================================================================*/
int n;
cin >> n;
forn(i, 1, n) {
forn(j, 1, n - 1) { cin >> a[i][j]; }
}
forn(i, 1, n) { last.push(i); }
int cnt = (n - 1) * n / 2;
rep(i, n * (n - 1) / 2) {
while (!last.empty()) {
int x = last.front();
last.pop();
t[x]++;
int y = a[x][t[x]];
// cout<<x<<" "<<y<<endl;
if (dist[y] == x) {
cnt--;
now.push(x);
now.push(y);
dist[x] = dist[y] = 0;
} else {
dist[x] = y;
}
}
// cout<<cnt<<endl;
swap(last, now);
// cout<<cnt<<endl;
if (cnt <= 0) {
cout << i + 1 << endl;
return 0;
}
}
finish("-1");
return 0;
}
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 729,560
| 729,561
|
u265392294
|
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]; // max length of path from v
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], dfs(u) + 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;
//各試合にidを振る
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]); // idに書き換え
}
rep(j, n - 2) {
to[a[i][j + 1]].push_back(a[i][j]); //逆向きに辺を張る
}
}
int ans = 0;
//好きな頂点からdfs
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;
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]; // max length of path from v
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;
//各試合にidを振る
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]); // idに書き換え
}
rep(j, n - 2) {
to[a[i][j + 1]].push_back(a[i][j]); //逆向きに辺を張る
}
}
int ans = 0;
//好きな頂点からdfs
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",
"call.arguments.change",
"expression.operation.binary.change"
] | 729,564
| 729,565
|
u108540384
|
cpp
|
p02925
|
#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__)
#define rand rng
using namespace std;
void solve();
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
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, N) \
do { \
cerr << #v << " = "; \
array_out(v, N); \
cout << endl; \
} while (0)
int main() { solve_dbg(); }
#else
#define trc(...)
#define trca(...)
int main() { solve(); }
#endif
using P = pair<int, int>;
constexpr int MOD = 998244853;
mt19937_64 rng(58);
template <typename T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
/////////
// トポロジカルソート 任意のグラフに使用可能(たぶん) O(E+V)
// DAGであるときはtrueを、閉路が存在するときfalseを返す
template <typename T> bool TopologicalSort(vector<int> &v, T &g) {
int N = g.size();
vector<int> marked(N, 0), temp(N, 0);
v.clear();
v.reserve(N);
// 訪問して帰りがけ順にvに追加
auto visit = [&](auto f, int i) -> bool {
if (temp[i] == 1)
return false;
if (marked[i] == 0) {
temp[i] = 1;
for (auto &e : g[i]) {
if (f(f, e) == false)
return false;
}
marked[i] = 1;
v.push_back(i);
temp[i] = 0;
}
return true;
};
for (int i = 0; i < N; i++) {
if (marked[i] == 0) {
if (visit(visit, i) == false)
return false;
}
}
reverse(v.begin(), v.end());
return true;
}
vvi g;
void solve() {
ini(N);
vvi a(N, vi(N - 1));
rep(i, N) in(a[i]);
rep(i, N) rep(j, N - 1) a[i][j]--;
rep(i, N) rep(j, N - 1) { a[i][j] = min(i, a[i][j]) * N + max(i, a[i][j]); }
rep(i, N) trc(a[i]);
g.resize(N * N);
rep(i, N) rep(j, N - 2) { g[a[i][j]].pb(a[i][j + 1]); }
trc("HOGE");
vi topo;
if (TopologicalSort(topo, g) == false)
die(-1);
{
vi topo2;
topo2.reserve(N * (N - 1) / 2);
each(x, topo) {
if (x / N < x % N)
topo2.pb(x);
}
topo.swap(topo2);
}
trc(topo);
vi inv(N * N, -1);
rep(i, sz(topo)) inv[topo[i]] = i;
trc(inv);
vi ans(sz(topo), 1);
int cnt = 0;
rep(i, N * N) {
if (g[i].empty())
continue;
each(x, g[i]) {
amax(ans[inv[x]], ans[inv[i]] + 1);
amax(cnt, ans[inv[x]]);
}
}
trc(ans);
out(cnt);
}
|
#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__)
#define rand rng
using namespace std;
void solve();
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
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, N) \
do { \
cerr << #v << " = "; \
array_out(v, N); \
cout << endl; \
} while (0)
int main() { solve_dbg(); }
#else
#define trc(...)
#define trca(...)
int main() { solve(); }
#endif
using P = pair<int, int>;
constexpr int MOD = 998244853;
mt19937_64 rng(58);
template <typename T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
/////////
// トポロジカルソート 任意のグラフに使用可能(たぶん) O(E+V)
// DAGであるときはtrueを、閉路が存在するときfalseを返す
template <typename T> bool TopologicalSort(vector<int> &v, T &g) {
int N = g.size();
vector<int> marked(N, 0), temp(N, 0);
v.clear();
v.reserve(N);
// 訪問して帰りがけ順にvに追加
auto visit = [&](auto f, int i) -> bool {
if (temp[i] == 1)
return false;
if (marked[i] == 0) {
temp[i] = 1;
for (auto &e : g[i]) {
if (f(f, e) == false)
return false;
}
marked[i] = 1;
v.push_back(i);
temp[i] = 0;
}
return true;
};
for (int i = 0; i < N; i++) {
if (marked[i] == 0) {
if (visit(visit, i) == false)
return false;
}
}
reverse(v.begin(), v.end());
return true;
}
vvi g;
void solve() {
ini(N);
vvi a(N, vi(N - 1));
rep(i, N) in(a[i]);
rep(i, N) rep(j, N - 1) a[i][j]--;
rep(i, N) rep(j, N - 1) { a[i][j] = min(i, a[i][j]) * N + max(i, a[i][j]); }
rep(i, N) trc(a[i]);
g.resize(N * N);
rep(i, N) rep(j, N - 2) { g[a[i][j]].pb(a[i][j + 1]); }
trc("HOGE");
vi topo;
if (TopologicalSort(topo, g) == false)
die(-1);
{
vi topo2;
topo2.reserve(N * (N - 1) / 2);
each(x, topo) {
if (x / N < x % N)
topo2.pb(x);
}
topo.swap(topo2);
}
trc(topo);
vi inv(N * N, -1);
rep(i, sz(topo)) inv[topo[i]] = i;
trc(inv);
vi ans(sz(topo), 1);
int cnt = 0;
each(i, topo) {
if (g[i].empty())
continue;
each(x, g[i]) {
amax(ans[inv[x]], ans[inv[i]] + 1);
amax(cnt, ans[inv[x]]);
}
}
trc(ans);
out(cnt);
}
|
[
"identifier.change"
] | 729,568
| 729,569
|
u168578024
|
cpp
|
p02925
|
#include <bits/stdc++.h>
#define loop(n) \
for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); \
ngtkana_is_genius++)
#define rep(i, begin, end) for (int i = int(begin); i < int(end); i++)
#define lint long long
auto cmn = [](auto &a, auto b) {
if (a > b) {
a = b;
return true;
}
return false;
};
auto cmx = [](auto &a, auto b) {
if (a < b) {
a = b;
return true;
}
return false;
};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) {
std::cerr << " " << head;
debug_impl(tail...);
}
#define debug(...) \
std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:"; \
debug_impl(__VA_ARGS__); \
std::cerr << std::noboolalpha;
class topological_sort {
int n;
std::vector<std::vector<int>> graph;
std::vector<int> ckd;
std::vector<int> sorted;
bool dfs(int crr) {
if (ckd.at(crr) == 1)
return true;
if (ckd.at(crr) == 2)
return false;
bool ret = false;
ckd.at(crr) = 1;
for (int nxt : graph.at(crr)) {
ret |= dfs(nxt);
}
ckd.at(crr) = 2;
sorted.push_back(crr);
return ret;
}
public:
topological_sort(int n) : n(n), graph(n), ckd(n, 0), sorted{} {}
void insert(int i, int j) { graph.at(i).emplace_back(j); }
bool build() {
for (auto i = 0; i < n; i++) {
if (ckd.at(i) == 0 && dfs(i))
return true;
}
std::reverse(sorted.begin(), sorted.end());
return false;
}
auto result() const { return sorted; }
};
template <typename T> auto make_vector_impl(size_t sz, T t) {
return std::vector<T>(sz, t);
}
template <size_t N, typename T, typename U,
std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz, U u) {
return make_vector_impl(sz, T(u));
}
template <size_t N, typename T,
std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz) {
return std::vector<T>(sz);
}
template <size_t N, typename T, typename... Args,
std::enable_if_t<N != 1, std::nullptr_t> = nullptr>
auto make_vector(size_t a, Args... args) {
return make_vector_impl(a, make_vector<N - 1, T>(args...));
}
template <typename T, typename Size_t> auto &at(T &t, Size_t i) {
return t.at(i);
}
template <typename T, typename Size_t, typename... Args>
auto &at(T &t, Size_t i, Args... args) {
return at(t.at(i), args...);
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &pair) {
return os << "(" << pair.first << "," << pair.second << ")";
}
template <typename T, typename U>
std::istream &operator>>(std::iostream &is, std::pair<T, U> &pair) {
return is >> pair.first >> pair.second;
}
template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
for (auto &x : v)
is >> x;
return is;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
auto n = v.size();
os << "{";
for (size_t i = 0; i < n; i++)
os << (i > 0 ? "," : "") << v[i];
return os << "}";
}
int main() {
std::cin.tie(0);
std::cin.sync_with_stdio(false);
int n;
std::cin >> n;
auto N = n * (n - 1) / 2;
std::vector<std::pair<int, int>> table(N);
auto encode = [&](int i, int j) {
if (i < j)
std::swap(i, j);
return i * (i - 1) / 2 + j;
};
auto decode = [&](int x) { return table.at(x); };
auto list = make_vector<2, int>(n, n - 1, -1);
rep(i, 0, n) {
rep(j, 0, n) {
if (i == j)
continue;
auto code = encode(i, j);
if (i > j)
table.at(code) = {i, j};
int x;
std::cin >> x;
x--;
at(list, i, j - (i < j)) = encode(i, x);
}
}
auto rev = make_vector<2, int>(N, 0);
auto tps = topological_sort(N);
for (auto const &v : list) {
rep(j, 0, n - 2) {
tps.insert(v.at(j), v.at(j + 1));
rev.at(v.at(j + 1)).push_back(v.at(j));
}
}
auto err = [&] {
std::cout << -1 << std::endl;
exit(0);
};
if (tps.build())
err();
auto sorted = tps.result();
// debug(sorted);
std::vector<int> dp(N, 0);
for (auto x : sorted) {
for (auto prv : rev.at(x)) {
cmx(dp.at(x), dp.at(prv) + 1);
}
}
auto ret = *max_element(dp.begin(), dp.end());
std::cout << ret << std::endl;
return 0;
}
|
#include <bits/stdc++.h>
#define loop(n) \
for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); \
ngtkana_is_genius++)
#define rep(i, begin, end) for (int i = int(begin); i < int(end); i++)
#define lint long long
auto cmn = [](auto &a, auto b) {
if (a > b) {
a = b;
return true;
}
return false;
};
auto cmx = [](auto &a, auto b) {
if (a < b) {
a = b;
return true;
}
return false;
};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) {
std::cerr << " " << head;
debug_impl(tail...);
}
#define debug(...) \
std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:"; \
debug_impl(__VA_ARGS__); \
std::cerr << std::noboolalpha;
class topological_sort {
int n;
std::vector<std::vector<int>> graph;
std::vector<int> ckd;
std::vector<int> sorted;
bool dfs(int crr) {
if (ckd.at(crr) == 1)
return true;
if (ckd.at(crr) == 2)
return false;
bool ret = false;
ckd.at(crr) = 1;
for (int nxt : graph.at(crr)) {
ret |= dfs(nxt);
}
ckd.at(crr) = 2;
sorted.push_back(crr);
return ret;
}
public:
topological_sort(int n) : n(n), graph(n), ckd(n, 0), sorted{} {}
void insert(int i, int j) { graph.at(i).emplace_back(j); }
bool build() {
for (auto i = 0; i < n; i++) {
if (ckd.at(i) == 0 && dfs(i))
return true;
}
std::reverse(sorted.begin(), sorted.end());
return false;
}
auto result() const { return sorted; }
};
template <typename T> auto make_vector_impl(size_t sz, T t) {
return std::vector<T>(sz, t);
}
template <size_t N, typename T, typename U,
std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz, U u) {
return make_vector_impl(sz, T(u));
}
template <size_t N, typename T,
std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz) {
return std::vector<T>(sz);
}
template <size_t N, typename T, typename... Args,
std::enable_if_t<N != 1, std::nullptr_t> = nullptr>
auto make_vector(size_t a, Args... args) {
return make_vector_impl(a, make_vector<N - 1, T>(args...));
}
template <typename T, typename Size_t> auto &at(T &t, Size_t i) {
return t.at(i);
}
template <typename T, typename Size_t, typename... Args>
auto &at(T &t, Size_t i, Args... args) {
return at(t.at(i), args...);
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &pair) {
return os << "(" << pair.first << "," << pair.second << ")";
}
template <typename T, typename U>
std::istream &operator>>(std::iostream &is, std::pair<T, U> &pair) {
return is >> pair.first >> pair.second;
}
template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
for (auto &x : v)
is >> x;
return is;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
auto n = v.size();
os << "{";
for (size_t i = 0; i < n; i++)
os << (i > 0 ? "," : "") << v[i];
return os << "}";
}
int main() {
std::cin.tie(0);
std::cin.sync_with_stdio(false);
int n;
std::cin >> n;
auto N = n * (n - 1) / 2;
std::vector<std::pair<int, int>> table(N);
auto encode = [&](int i, int j) {
if (i < j)
std::swap(i, j);
return i * (i - 1) / 2 + j;
};
auto decode = [&](int x) { return table.at(x); };
auto list = make_vector<2, int>(n, n - 1, -1);
rep(i, 0, n) {
rep(j, 0, n) {
if (i == j)
continue;
auto code = encode(i, j);
if (i > j)
table.at(code) = {i, j};
int x;
std::cin >> x;
x--;
at(list, i, j - (i < j)) = encode(i, x);
}
}
auto rev = make_vector<2, int>(N, 0);
auto tps = topological_sort(N);
for (auto const &v : list) {
rep(j, 0, n - 2) {
tps.insert(v.at(j), v.at(j + 1));
rev.at(v.at(j + 1)).push_back(v.at(j));
}
}
auto err = [&] {
std::cout << -1 << std::endl;
exit(0);
};
if (tps.build())
err();
auto sorted = tps.result();
// debug(sorted);
std::vector<int> dp(N, 0);
for (auto x : sorted) {
for (auto prv : rev.at(x)) {
cmx(dp.at(x), dp.at(prv) + 1);
}
}
auto ret = *max_element(dp.begin(), dp.end()) + 1;
std::cout << ret << std::endl;
return 0;
}
|
[
"assignment.change"
] | 729,570
| 729,571
|
u846041485
|
cpp
|
p02925
|
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define dump(x) cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
int get_match_id(int a, int b, int n) {
if (a > b) {
swap(a, b);
}
int base = 0;
if (a > 1) {
base = (n + (n - a + 2)) * (a - 1) / 2;
}
return base + b;
}
int dp[1000001];
int check_depth(map<int, vector<int>> &edges, int src, int n, set<int> &hist) {
int max_depth = 0;
if (dp[src] != 0)
return dp[src];
for (int next : edges[src]) {
// dump(next)
if (hist.find(next) != hist.end())
return 1 << 30;
hist.insert(next);
max_depth = max(max_depth, check_depth(edges, next, n, hist) + 1);
hist.erase(next);
}
// dump(max_depth)
dp[src] = max_depth;
return max_depth;
}
int main() {
std::ios::sync_with_stdio(false);
map<int, vector<int>> edges;
int n, tmp;
cin >> n;
vector<vector<int>> matches(n);
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < (n - 1); ++j) {
cin >> tmp;
matches[i - 1].push_back(get_match_id(i, tmp, n));
}
}
for (int i = 0; i < n; ++i) {
int sz = matches[i].size();
for (int j = 0; j < sz - 1; ++j) {
edges[matches[i][j]].push_back(matches[i][j + 1]);
}
}
int max_depth = 0;
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
int start_node = get_match_id(i, j, n);
set<int> hist;
hist.insert(start_node);
int depth = check_depth(edges, start_node, n, hist);
if (depth == (1 << 30)) {
cout << -1 << endl;
return 0;
}
max_depth = max(max_depth, depth);
}
}
cout << max_depth + 1 << endl;
}
|
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define dump(x) cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
int get_match_id(int a, int b, int n) {
if (a > b) {
swap(a, b);
}
int base = 0;
if (a > 1) {
base = (n + (n - a + 2)) * (a - 1) / 2;
}
return base + b;
}
int dp[1000001];
int check_depth(map<int, vector<int>> &edges, int src, int n, set<int> &hist) {
int max_depth = 0;
if (dp[src] != 0)
return dp[src];
for (int next : edges[src]) {
// dump(next)
if (hist.find(next) != hist.end())
return 1 << 30;
hist.insert(next);
max_depth = max(max_depth, check_depth(edges, next, n, hist) + 1);
hist.erase(next);
}
// dump(max_depth)
dp[src] = max_depth;
return max_depth;
}
int main() {
std::ios::sync_with_stdio(false);
map<int, vector<int>> edges;
int n, tmp;
cin >> n;
vector<vector<int>> matches(n);
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < (n - 1); ++j) {
cin >> tmp;
matches[i - 1].push_back(get_match_id(i, tmp, n));
}
}
for (int i = 0; i < n; ++i) {
int sz = matches[i].size();
for (int j = 0; j < sz - 1; ++j) {
edges[matches[i][j]].push_back(matches[i][j + 1]);
}
}
int max_depth = 0;
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
int start_node = get_match_id(i, j, n);
set<int> hist;
hist.insert(start_node);
int depth = check_depth(edges, start_node, n, hist);
if (depth >= (1 << 30)) {
cout << -1 << endl;
return 0;
}
max_depth = max(max_depth, depth);
}
}
cout << max_depth + 1 << endl;
}
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 729,576
| 729,577
|
u340303097
|
cpp
|
p02925
|
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define dump(x) cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
int get_match_id(int a, int b, int n) {
if (a > b) {
swap(a, b);
}
int base = 0;
if (a > 1) {
base = (n + (n - a + 2)) * (a - 1) / 2;
}
return base + b;
}
int dp[1000001];
int check_depth(map<int, vector<int>> &edges, int src, int n, set<int> &hist) {
int max_depth = 0;
if (dp[src] != 0)
return dp[src];
for (int next : edges[src]) {
// dump(next)
if (hist.find(next) != hist.end())
return 1 << 30;
hist.insert(next);
max_depth = max(max_depth, check_depth(edges, next, n, hist) + 1);
hist.erase(next);
}
// dump(max_depth)
dp[src] = max_depth;
return max_depth;
}
int main() {
std::ios::sync_with_stdio(false);
map<int, vector<int>> edges;
int n, tmp;
cin >> n;
vector<vector<int>> matches(n);
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < (n - 1); ++j) {
cin >> tmp;
matches[i - 1].push_back(get_match_id(i, tmp, n));
}
}
for (int i = 0; i < n; ++i) {
int sz = matches[i].size();
for (int j = 0; j < sz - 1; ++j) {
edges[matches[i][j]].push_back(matches[i][j + 1]);
}
}
int max_depth = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
int start_node = get_match_id(i, j, n);
set<int> hist;
hist.insert(start_node);
int depth = check_depth(edges, start_node, n, hist);
if (depth == (1 << 30)) {
cout << -1 << endl;
return 0;
}
max_depth = max(max_depth, depth);
}
}
cout << max_depth + 1 << endl;
}
|
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define dump(x) cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
int get_match_id(int a, int b, int n) {
if (a > b) {
swap(a, b);
}
int base = 0;
if (a > 1) {
base = (n + (n - a + 2)) * (a - 1) / 2;
}
return base + b;
}
int dp[1000001];
int check_depth(map<int, vector<int>> &edges, int src, int n, set<int> &hist) {
int max_depth = 0;
if (dp[src] != 0)
return dp[src];
for (int next : edges[src]) {
// dump(next)
if (hist.find(next) != hist.end())
return 1 << 30;
hist.insert(next);
max_depth = max(max_depth, check_depth(edges, next, n, hist) + 1);
hist.erase(next);
}
// dump(max_depth)
dp[src] = max_depth;
return max_depth;
}
int main() {
std::ios::sync_with_stdio(false);
map<int, vector<int>> edges;
int n, tmp;
cin >> n;
vector<vector<int>> matches(n);
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < (n - 1); ++j) {
cin >> tmp;
matches[i - 1].push_back(get_match_id(i, tmp, n));
}
}
for (int i = 0; i < n; ++i) {
int sz = matches[i].size();
for (int j = 0; j < sz - 1; ++j) {
edges[matches[i][j]].push_back(matches[i][j + 1]);
}
}
int max_depth = 0;
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
int start_node = get_match_id(i, j, n);
set<int> hist;
hist.insert(start_node);
int depth = check_depth(edges, start_node, n, hist);
if (depth >= (1 << 30)) {
cout << -1 << endl;
return 0;
}
max_depth = max(max_depth, depth);
}
}
cout << max_depth + 1 << endl;
}
|
[
"control_flow.loop.for.initializer.change",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 729,578
| 729,577
|
u340303097
|
cpp
|
p02925
|
#include <algorithm>
#include <cmath>
#include <cstdarg>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define REP3(i, st, en) for (ll(i) = (st); (i) < (en); (i)++)
using P = pair<ll, ll>;
const int MOD = 1e9 + 7;
const ll INF = 1e+14;
const double PI = 3.14159265349;
// Extended Print Func
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &input) {
os << "[ ";
REP(i, input.size()) {
os << input[i];
if (i < input.size() - 1) {
os << " ";
}
}
os << " ]";
return os;
}
void print() { std::cout << "\n"; }
template <class T, class... A> void print(const T &first, const A &...rest) {
std::cout << first << " ";
print(rest...);
}
template <class... A> void print(const A &...rest) { print(rest...); }
ll A[1001][1001];
ll done[1001];
ll ne[1001];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
memset(done, 0, sizeof(done));
ll N;
cin >> N;
REP(i, N) {
REP(j, N - 1) {
cin >> A[i][j];
A[i][j]--;
ne[i] = 0;
}
}
ll day = 0;
for (;;) {
bool is_match = false;
day++;
REP(i, N) {
if (done[i] == day)
continue;
ll opp = A[i][ne[i]];
if (done[opp] == day)
continue;
if (ne[i] < N && ne[opp] < N && i == A[opp][ne[opp]]) {
is_match = true;
ne[i]++;
ne[opp]++;
done[i] = day;
done[opp] = day;
}
}
if (!is_match) {
day--;
break;
}
}
REP(i, N) {
if (ne[i] != N - 1) {
cout << -1 << "\n";
return 0;
}
}
std::cout << day << "\n";
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdarg>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define REP3(i, st, en) for (ll(i) = (st); (i) < (en); (i)++)
using P = pair<ll, ll>;
const int MOD = 1e9 + 7;
const ll INF = 1e+14;
const double PI = 3.14159265349;
// Extended Print Func
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &input) {
os << "[ ";
REP(i, input.size()) {
os << input[i];
if (i < input.size() - 1) {
os << " ";
}
}
os << " ]";
return os;
}
void print() { std::cout << "\n"; }
template <class T, class... A> void print(const T &first, const A &...rest) {
std::cout << first << " ";
print(rest...);
}
template <class... A> void print(const A &...rest) { print(rest...); }
ll A[1001][1001];
ll done[1001];
ll ne[1001];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
memset(done, 0, sizeof(done));
ll N;
cin >> N;
REP(i, N) {
REP(j, N - 1) {
cin >> A[i][j];
A[i][j]--;
ne[i] = 0;
}
}
ll day = 0;
for (;;) {
bool is_match = false;
day++;
REP(i, N) {
if (done[i] == day)
continue;
ll opp = A[i][ne[i]];
if (done[opp] == day)
continue;
if (ne[i] < N - 1 && ne[opp] < N - 1 && i == A[opp][ne[opp]]) {
is_match = true;
ne[i]++;
ne[opp]++;
done[i] = day;
done[opp] = day;
}
}
if (!is_match) {
day--;
break;
}
}
REP(i, N) {
if (ne[i] != N - 1) {
cout << -1 << "\n";
return 0;
}
}
std::cout << day << "\n";
return 0;
}
|
[
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 729,581
| 729,582
|
u176567747
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
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;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int get_id(int n, int m, int N) {
int fir, sec;
fir = min(n, m);
sec = max(n, m);
int ans = 0;
for (int i = 0; i < fir; i++) {
ans += (N - 1) - i;
}
ans += sec - fir - 1;
return ans;
};
bool visit(const vector<vector<int>> &G, int v, vector<int> &order,
vector<int> &color) {
color[v] = 1;
for (int u : G[v]) {
if (color[u] == 2)
continue;
if (color[u] == 1)
return false;
if (!visit(G, u, order, color))
return false;
}
order.push_back(v);
color[v] = 2;
return true;
}
bool TpSort(const vector<vector<int>> &G, vector<int> &order) {
int n = G.size();
vector<int> color(n);
for (int u = 0; u < n; u++)
if (!color[u] && !visit(G, u, order, color))
return false;
reverse(order.begin(), order.end());
return true;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<vector<int>> A(N);
int tmp;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++) {
cin >> tmp;
tmp--;
A[i].push_back(tmp);
}
}
vector<vector<int>> G(N * (N - 1) / 2);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 2; j++) {
G[get_id(i, A[i][j], N)].push_back(get_id(i, A[i][j + 1], N));
}
}
vector<int> order;
if (!TpSort(G, order)) {
cout << -1 << endl;
}
vector<int> dp(N * (N - 1) / 2);
for (const int el : order) {
for (const int child : G[el]) {
dp[child] = max(dp[child], dp[el] + 1);
}
}
cout << *max_element(dp.begin(), dp.end()) + 1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
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;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int get_id(int n, int m, int N) {
int fir, sec;
fir = min(n, m);
sec = max(n, m);
int ans = 0;
for (int i = 0; i < fir; i++) {
ans += (N - 1) - i;
}
ans += sec - fir - 1;
return ans;
};
bool visit(const vector<vector<int>> &G, int v, vector<int> &order,
vector<int> &color) {
color[v] = 1;
for (int u : G[v]) {
if (color[u] == 2)
continue;
if (color[u] == 1)
return false;
if (!visit(G, u, order, color))
return false;
}
order.push_back(v);
color[v] = 2;
return true;
}
bool TpSort(const vector<vector<int>> &G, vector<int> &order) {
int n = G.size();
vector<int> color(n);
for (int u = 0; u < n; u++)
if (!color[u] && !visit(G, u, order, color))
return false;
reverse(order.begin(), order.end());
return true;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<vector<int>> A(N);
int tmp;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++) {
cin >> tmp;
tmp--;
A[i].push_back(tmp);
}
}
vector<vector<int>> G(N * (N - 1) / 2);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 2; j++) {
G[get_id(i, A[i][j], N)].push_back(get_id(i, A[i][j + 1], N));
}
}
vector<int> order;
if (!TpSort(G, order)) {
cout << -1 << endl;
} else {
vector<int> dp(N * (N - 1) / 2);
for (const int el : order) {
for (const int child : G[el]) {
dp[child] = max(dp[child], dp[el] + 1);
}
}
cout << *max_element(dp.begin(), dp.end()) + 1 << endl;
}
return 0;
}
|
[
"control_flow.branch.else.add"
] | 729,586
| 729,587
|
u187878098
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
queue<int> a[1001];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j < n; j++) {
int x;
cin >> x;
a[i].push(x);
}
}
int sc = n * (n - 1) / 2;
// cout<<sc<<endl;
int cnt = 0;
while (sc > 0) {
// cout<<sc<<endl;
vector<int> temp;
for (int i = 1; i <= n; i++) {
// int t=a[i].front();
if (a[a[i].front()].front() == i && i < a[i].front()) {
// cout<<i<<" "<<a[i][0]<<endl;
temp.push_back(i);
temp.push_back(a[i].front());
break;
}
}
if (temp.size() == 0) {
cout << -1;
return 0;
}
// cout<<"fdf"<<endl;
cnt++;
for (int i = 0; i < temp.size(); i++) {
a[temp[i]].pop();
}
sc -= (temp.size() / 2);
}
cout << cnt << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
queue<int> a[1001];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j < n; j++) {
int x;
cin >> x;
a[i].push(x);
}
}
int sc = n * (n - 1) / 2;
// cout<<sc<<endl;
int cnt = 0;
while (sc > 0) {
// cout<<sc<<endl;
vector<int> temp;
for (int i = 1; i <= n; i++) {
// int t=a[i].front();
if (a[a[i].front()].front() == i && i < a[i].front()) {
// cout<<i<<" "<<a[i][0]<<endl;
temp.push_back(i);
temp.push_back(a[i].front());
continue;
}
}
if (temp.size() == 0) {
cout << -1;
return 0;
}
// cout<<"fdf"<<endl;
cnt++;
for (int i = 0; i < temp.size(); i++) {
a[temp[i]].pop();
}
sc -= (temp.size() / 2);
}
cout << cnt << endl;
}
|
[
"control_flow.break.remove",
"control_flow.continue.add"
] | 729,595
| 729,596
|
u201455094
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
//#define endl "\n"
#define ciosup \
cin.tie(0); \
ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
#define vll vector<ll>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;
template <typename T> void vecin(vector<T> &v, int n = 0) {
if (n == 0)
n = v.size();
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
}
template <typename T> void vecout(vector<T> &v, int n = 0) {
if (n == 0)
n = v.size();
for (int i = 0; i < n - 1; ++i) {
cout << v[i] << " ";
}
cout << v[n - 1] << endl;
}
void print(string s) { cout << s << endl; }
int main() {
ciosup;
int n;
cin >> n;
vector<vint> a(n, vint(n - 1));
queue<pint> que;
REP(i, n) {
vecin(a[i]);
REP(j, n - 1) { a[i][j]--; }
}
REP(i, n) {
if (a[i][0] > i && a[a[i][0]][0] == i) {
que.emplace(make_pair(i, a[i][0]));
}
}
vint now(n, 0);
vector<bool> used(n, false);
ll ans = 0;
while (que.size()) {
pint cd = que.front();
if (used[cd.FI] || used[cd.SE]) {
++ans;
REP(i, n) { used[i] = false; }
continue;
}
que.pop();
++now[cd.FI];
++now[cd.SE];
used[cd.FI] = used[cd.SE] = true;
if (now[cd.FI] < n - 1) {
int k = a[cd.FI][now[cd.FI]];
if (now[k] < n - 1 && a[k][now[k]] == cd.FI)
que.emplace(make_pair(cd.FI, k));
}
if (now[cd.SE] < n - 1) {
int k = a[cd.SE][now[cd.SE]];
if (now[k] < n - 1 && a[k][now[k]] == cd.SE)
que.emplace(make_pair(cd.SE, k));
}
}
bool flag = false;
REP(i, n) {
if (now[i] != n - 1) {
flag = true;
break;
}
}
if (flag)
ans = -1;
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
//#define endl "\n"
#define ciosup \
cin.tie(0); \
ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
#define vll vector<ll>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;
template <typename T> void vecin(vector<T> &v, int n = 0) {
if (n == 0)
n = v.size();
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
}
template <typename T> void vecout(vector<T> &v, int n = 0) {
if (n == 0)
n = v.size();
for (int i = 0; i < n - 1; ++i) {
cout << v[i] << " ";
}
cout << v[n - 1] << endl;
}
void print(string s) { cout << s << endl; }
int main() {
ciosup;
int n;
cin >> n;
vector<vint> a(n, vint(n - 1));
queue<pint> que;
REP(i, n) {
vecin(a[i]);
REP(j, n - 1) { a[i][j]--; }
}
REP(i, n) {
if (a[i][0] > i && a[a[i][0]][0] == i) {
que.emplace(make_pair(i, a[i][0]));
}
}
vint now(n, 0);
vector<bool> used(n, false);
ll ans = 1;
while (que.size()) {
pint cd = que.front();
if (used[cd.FI] || used[cd.SE]) {
++ans;
REP(i, n) { used[i] = false; }
continue;
}
que.pop();
++now[cd.FI];
++now[cd.SE];
used[cd.FI] = used[cd.SE] = true;
if (now[cd.FI] < n - 1) {
int k = a[cd.FI][now[cd.FI]];
if (now[k] < n - 1 && a[k][now[k]] == cd.FI)
que.emplace(make_pair(cd.FI, k));
}
if (now[cd.SE] < n - 1) {
int k = a[cd.SE][now[cd.SE]];
if (now[k] < n - 1 && a[k][now[k]] == cd.SE)
que.emplace(make_pair(cd.SE, k));
}
}
bool flag = false;
REP(i, n) {
if (now[i] != n - 1) {
flag = true;
break;
}
}
if (flag)
ans = -1;
cout << ans << endl;
}
|
[
"literal.number.change",
"variable_declaration.value.change"
] | 729,600
| 729,601
|
u337054478
|
cpp
|
p02925
|
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int a[1001][1001] = {};
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - 1; j++) {
cin >> a[i][j];
a[i][j]--;
}
}
int current[1001] = {};
int res = 1;
while (true) {
int done = 0;
bool doneEachPlayer[1001] = {false};
for (int j = 0; j < n; j++) {
if (doneEachPlayer[j] == true)
continue;
if (current[j] == n - 1)
continue;
int opponent_of_j = a[j][current[j]];
if (doneEachPlayer[opponent_of_j] == true)
continue;
if (a[opponent_of_j][current[opponent_of_j]] == j) {
current[j]++;
current[opponent_of_j]++;
doneEachPlayer[j] = true;
doneEachPlayer[opponent_of_j] = true;
done = 1;
}
}
int break_flag = 1;
for (int j = 0; j < n; j++) {
if (current[j] != n - 1) {
break_flag = 0;
break;
}
}
res++;
if (break_flag == 1)
break;
if (done == 0) {
cout << -1 << endl;
return 0;
}
}
cout << res << endl;
return 0;
}
|
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int a[1001][1001] = {};
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - 1; j++) {
cin >> a[i][j];
a[i][j]--;
}
}
int current[1001] = {};
int res = 0;
while (true) {
int done = 0;
bool doneEachPlayer[1001] = {};
for (int j = 0; j < n; j++) {
if (doneEachPlayer[j] == true)
continue;
if (current[j] == n - 1)
continue;
int opponent_of_j = a[j][current[j]];
if (doneEachPlayer[opponent_of_j] == true)
continue;
if (a[opponent_of_j][current[opponent_of_j]] == j) {
current[j]++;
current[opponent_of_j]++;
doneEachPlayer[j] = true;
doneEachPlayer[opponent_of_j] = true;
done = 1;
}
}
int break_flag = 1;
for (int j = 0; j < n; j++) {
if (current[j] != n - 1) {
break_flag = 0;
break;
}
}
res++;
if (break_flag == 1)
break;
if (done == 0) {
cout << -1 << endl;
return 0;
}
}
cout << res << endl;
return 0;
}
|
[
"literal.number.change",
"variable_declaration.value.change"
] | 729,602
| 729,603
|
u108648546
|
cpp
|
p02925
|
#include <bits/stdc++.h>
template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
InputIterator last) {
return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
for (auto &i : v) {
stream >> i;
}
return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
stream >> p.first >> p.second;
return stream;
}
int main() {
int64_t n;
std::cin >> n;
std::vector<std::vector<int64_t>> a(n, std::vector<int64_t>(n - 1));
std::cin >> a;
for (auto &i : a) {
for (auto &j : i) {
j--;
}
}
std::vector<int64_t> index(n, 0);
std::vector<bool> flag(n, false);
int64_t day = 0;
while (true) {
std::fill(flag.begin(), flag.end(), false);
bool f = false;
for (int64_t i = 0; i < n; i++) {
if (flag[i] || index[i] != n - 1) {
continue;
}
const auto j = a[i][index[i]];
if (a[j][index[j]] == i && !flag[j]) {
f = true;
index[i]++;
index[j]++;
flag[i] = true;
flag[j] = true;
}
}
if (!f) {
break;
}
day++;
}
bool f = true;
for (const auto i : index) {
if (i != n - 1) {
f = false;
break;
}
}
if (f) {
std::cout << day << std::endl;
} else {
std::cout << -1 << std::endl;
}
return 0;
}
|
#include <bits/stdc++.h>
template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
InputIterator last) {
return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
for (auto &i : v) {
stream >> i;
}
return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
stream >> p.first >> p.second;
return stream;
}
int main() {
int64_t n;
std::cin >> n;
std::vector<std::vector<int64_t>> a(n, std::vector<int64_t>(n - 1));
std::cin >> a;
for (auto &i : a) {
for (auto &j : i) {
j--;
}
}
std::vector<int64_t> index(n, 0);
std::vector<bool> flag(n, false);
int64_t day = 0;
while (true) {
std::fill(flag.begin(), flag.end(), false);
bool f = false;
for (int64_t i = 0; i < n; i++) {
if (flag[i] || index[i] == n - 1) {
continue;
}
const auto j = a[i][index[i]];
if (a[j][index[j]] == i && !flag[j]) {
f = true;
index[i]++;
index[j]++;
flag[i] = true;
flag[j] = true;
}
}
if (!f) {
break;
}
day++;
}
bool f = true;
for (const auto i : index) {
if (i != n - 1) {
f = false;
break;
}
}
if (f) {
std::cout << day << std::endl;
} else {
std::cout << -1 << std::endl;
}
return 0;
}
|
[
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 729,608
| 729,609
|
u438319362
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T> void print(T x) { std::cout << x << '\n'; }
// typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long
int n;
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 caluculated[MAXV];
int dp[MAXV]; // max length og path from v
int dfs(int v) {
if (visited[v]) {
if (!caluculated[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);
}
caluculated[v] = true;
return dp[v];
}
signed main() {
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]].pb(a[i][j]); }
}
int ans = 0;
rep(i, n) {
int res = dfs(i);
if (res == -1) {
cout << -1 << endl;
return 0;
}
ans = max(ans, res);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T> void print(T x) { std::cout << x << '\n'; }
// typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long
int n;
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 caluculated[MAXV];
int dp[MAXV]; // max length og path from v
int dfs(int v) {
if (visited[v]) {
if (!caluculated[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);
}
caluculated[v] = true;
return dp[v];
}
signed main() {
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]].pb(a[i][j]); }
}
int ans = 0;
rep(i, V) {
int res = dfs(i);
if (res == -1) {
cout << -1 << endl;
return 0;
}
ans = max(ans, res);
}
cout << ans + 1 << endl;
return 0;
}
|
[
"expression.operation.binary.add"
] | 729,620
| 729,621
|
u888717396
|
cpp
|
p02925
|
/**
* Created by hiramekun at 15:11 on 2019-09-02.
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<ll, ll>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
template <class T> ostream &operator<<(ostream &out, const vector<T> &list) {
ll n = list.size();
rep(i, n) out << list[i] << ' ';
return out;
}
template <class T> istream &operator>>(istream &in, vector<T> &list) {
ll n = list.size();
rep(i, n) in >> list[i];
return in;
}
template <class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
ll n = list.size();
rep(i, n) out << list[i] << '\n';
return out;
}
/* ------------- ANSWER ------------- */
/* ---------------------------------- */
void solve() {
ll n;
cin >> n;
vector<queue<ll>> v(n);
rep(i, n) {
rep(j, n - 1) {
ll a;
cin >> a;
v[i].push(--a);
}
}
queue<ll> next;
ll res = n * (n - 1);
ll ans = 0;
bool plus = false;
vector<bool> seen(n);
rep(i, n) {
if (v[i].empty())
continue;
ll j = v[i].front();
if (v[j].empty())
continue;
if (!seen[j] && !seen[i] && v[j].front() == i) {
seen[i] = seen[j] = true;
v[i].pop(), v[j].pop();
next.push(i), next.push(j);
res -= 2;
plus = true;
}
}
if (plus)
ans++;
else {
cout << -1 << '\n';
return;
}
while (res > 0) {
bool plus = false;
vector<bool> seen(n);
queue<ll> tmp;
while (!next.empty()) {
ll now = next.front();
next.pop();
if (v[now].empty())
break;
ll j = v[now].front();
if (v[j].empty())
break;
if (!seen[j] && !seen[now] && v[j].front() == now) {
seen[j] = seen[now] = true;
v[j].pop(), v[now].pop();
tmp.push(j), tmp.push(now);
res -= 2;
plus = true;
}
}
if (!plus) {
cout << -1 << '\n';
return;
}
ans++;
next = tmp;
}
cout << ans << '\n';
}
int main() {
#ifdef MY_DEBUG
while (true) {
#endif
solve();
#ifdef MY_DEBUG
}
#endif
return 0;
}
|
/**
* Created by hiramekun at 15:11 on 2019-09-02.
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<ll, ll>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
template <class T> ostream &operator<<(ostream &out, const vector<T> &list) {
ll n = list.size();
rep(i, n) out << list[i] << ' ';
return out;
}
template <class T> istream &operator>>(istream &in, vector<T> &list) {
ll n = list.size();
rep(i, n) in >> list[i];
return in;
}
template <class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
ll n = list.size();
rep(i, n) out << list[i] << '\n';
return out;
}
/* ------------- ANSWER ------------- */
/* ---------------------------------- */
void solve() {
ll n;
cin >> n;
vector<queue<ll>> v(n);
rep(i, n) {
rep(j, n - 1) {
ll a;
cin >> a;
v[i].push(--a);
}
}
queue<ll> next;
ll res = n * (n - 1);
ll ans = 0;
bool plus = false;
vector<bool> seen(n);
rep(i, n) {
if (v[i].empty())
continue;
ll j = v[i].front();
if (v[j].empty())
continue;
if (!seen[j] && !seen[i] && v[j].front() == i) {
seen[i] = seen[j] = true;
v[i].pop(), v[j].pop();
next.push(i), next.push(j);
res -= 2;
plus = true;
}
}
if (plus)
ans++;
else {
cout << -1 << '\n';
return;
}
while (res > 0) {
bool plus = false;
vector<bool> seen(n);
queue<ll> tmp;
while (!next.empty()) {
ll now = next.front();
next.pop();
if (v[now].empty())
continue;
ll j = v[now].front();
if (v[j].empty())
continue;
if (!seen[j] && !seen[now] && v[j].front() == now) {
seen[j] = seen[now] = true;
v[j].pop(), v[now].pop();
tmp.push(j), tmp.push(now);
res -= 2;
plus = true;
}
}
if (!plus) {
cout << -1 << '\n';
return;
}
ans++;
next = tmp;
}
cout << ans << '\n';
}
int main() {
#ifdef MY_DEBUG
while (true) {
#endif
solve();
#ifdef MY_DEBUG
}
#endif
return 0;
}
|
[
"control_flow.break.remove",
"control_flow.continue.add"
] | 729,622
| 729,623
|
u136378781
|
cpp
|
p02925
|
//#pragma GCC optimize ("-O3")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <type_traits>
#include <typeinfo>
#include <unordered_map>
#include <vector>
#ifdef _MSC_VER
#include <intrin.h>
#define popcnt __popcnt64
//# define __builtin_popcount __popcnt
#else
#define popcnt __builtin_popcountll
#endif
//#include "boost/variant.hpp"
using namespace std;
typedef long long ll;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;
#define rep(i, N, M) for (ll i = N, i##_len = (M); i < i##_len; ++i)
#define rep_skip(i, N, M, ...) \
for (ll i = N, i##_len = (M); i < i##_len; i += (skip))
#define rrep(i, N, M) for (ll i = (M)-1, i##_len = (N - 1); i > i##_len; --i)
#define pb push_back
#define fir first
#define sec second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define perm(c) \
sort(all(c)); \
for (bool c##perm = 1; c##perm; \
c##perm = next_permutation( \
all(c))) // perm(c){write(c)} writes all permutation of c
typedef pair<double, double> pd;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
template <typename T>
using pq_greater = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using vpt = vector<complex<T>>;
template <int n> struct tll_impl {
using type = decltype(tuple_cat(tuple<ll>(),
declval<typename tll_impl<n - 1>::type>()));
};
template <> struct tll_impl<1> { using type = tuple<ll>; };
template <int n> using tll = typename tll_impl<n>::type;
template <class T> constexpr ll SZ(T &v) { return static_cast<ll>(v.size()); };
template <int n, typename T> struct vec_t_impl {
using type = vector<typename vec_t_impl<n - 1, T>::type>;
};
template <typename T> struct vec_t_impl<1, T> { using type = vector<T>; };
template <int n, typename T> using vec_t = typename vec_t_impl<n, T>::type;
// check
static_assert(is_same<vec_t<3, ll>, vector<vector<vector<ll>>>>::value, "");
// decompose vector into basetype and dimension.
template <typename T> struct vec_dec {
static constexpr int dim = 0;
using type = T;
};
template <typename T> struct vec_dec<vector<T>> {
static constexpr int dim = vec_dec<T>::dim + 1;
using type = typename vec_dec<T>::type;
};
static_assert(is_same<typename vec_dec<vec_t<3, ll>>::type, ll>::value, "");
static_assert(vec_dec<vec_t<3, ll>>::dim == 3, "");
template <typename T = ll> vector<T> makev(size_t a) { return vector<T>(a); }
template <typename T = ll, typename... Ts> auto makev(size_t a, Ts... ts) {
return vector<decltype(makev<T>(ts...))>(a, makev<T>(ts...));
} // ex: auto dp = makev<ll>(4,5) => vector<vector<ll>> dp(4,vector<ll>(5));
template <typename T>
struct is_vector : std::false_type {}; // check if T is vector
template <typename T> struct is_vector<vector<T>> : std::true_type {};
static_assert(is_vector<vector<ll>>::value == true &&
is_vector<ll>::value == false,
"");
// check if T is vector
template <typename T> struct is_pair : std::false_type {};
template <typename T, typename S>
struct is_pair<pair<T, S>> : std::true_type {};
static_assert(is_pair<pll>::value == true && is_pair<ll>::value == false, "");
template <typename T, typename V,
typename enable_if<!is_vector<T>::value, nullptr_t>::type = nullptr>
void fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V,
typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr>
void fill_v(T &t, const V &v) {
for (auto &&x : t)
fill_v(x, v);
} // ex: fill_v(dp, INF);
namespace std {
template <class T> bool operator<(const complex<T> &a, const complex<T> &b) {
return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
}
}; // namespace std
template <typename T, typename S>
istream &operator>>(istream &istr, pair<T, S> &x) {
return istr >> x.first >> x.second;
}
template <typename T> istream &operator>>(istream &istr, vector<T> &x) {
rep(i, 0, x.size()) istr >> x[i];
return istr;
}
template <typename T> istream &operator>>(istream &istr, complex<T> &x) {
T r, i;
istr >> r >> i;
x.real(r);
x.imag(i);
return istr;
}
template <typename T, typename Delim_t = string,
typename enable_if<!is_vector<T>::value, nullptr_t>::type = nullptr>
void write(T &x, Delim_t delim = " ") {
cout << x << delim;
}
template <typename T, typename Delim_t = string,
typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr>
void write(T &x, Delim_t delim = " ") {
rep(i, 0, x.size()) write(x[i], (i == (x.size() - 1) ? "" : delim));
cout << '\n';
}
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
vll seq(ll i, ll j) {
vll res(j - i);
rep(k, i, j) res[k] = i + k;
return res;
}
constexpr ll POW_0(ll x, ll y) {
if (y == 0)
return 1;
if (y == 1)
return x;
if (y == 2)
return x * x;
if (y % 2 == 0)
return POW_0(POW_0(x, y / 2), 2LL);
return ((POW_0(POW_0(x, y / 2), 2LL)) * (x));
}
constexpr ll POW(ll x, ll y, ll mod = 0) {
if (mod == 0)
return POW_0(x, y);
if (y == 0)
return 1;
if (y == 1)
return x % mod;
if (y == 2)
return x * x % mod;
if (y % 2 == 0)
return POW(POW(x, y / 2, mod), 2LL, mod) % mod;
return ((POW(POW(x, y / 2, mod), 2LL, mod)) * (x % mod)) % mod;
}
template <typename Inputs, typename Functor,
typename T = typename Inputs::value_type>
void sort_by(Inputs &inputs, Functor f) {
std::sort(std::begin(inputs), std::end(inputs),
[&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); });
}
template <typename Inputs, typename Functor,
typename T = typename Inputs::value_type>
void stable_sort_by(Inputs &inputs, Functor f) {
std::stable_sort(
std::begin(inputs), std::end(inputs),
[&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); });
}
template <typename Inputs> void sort_uniq(Inputs &inputs) {
sort(all(inputs));
inputs.erase(unique(all(inputs)), inputs.end());
}
vector<string> split(const string &s, char delim) {
vector<string> elems;
stringstream ss(s);
string item;
while (getline(ss, item, delim)) {
if (!item.empty()) {
elems.push_back(item);
}
}
return elems;
}
template <class T> map<T, ll> inv_map(vector<T> &x) {
map<T, ll> res;
rep(i, 0, x.size()) { res[x[i]] = i; }
return res;
}
template <class T, class val_t = typename T::value_type,
enable_if_t<!is_same<T, set<val_t>>::value> * = nullptr>
constexpr bool exist(const T &container, val_t val) {
return find(all(container), val) != container.end();
}
template <class T, class val_t = typename T::value_type,
enable_if_t<is_same<T, set<val_t>>::value> * = nullptr>
constexpr bool exist(const T &container, val_t val) {
return container.find(val) != container.end();
}
struct UnionFind {
vector<ll> data;
vll querySize_;
set<ll> roots;
UnionFind(ll size) : data(size, -1), querySize_(size, 0) {
rep(i, 0, size) roots.insert(i);
}
ll unite(ll x, ll y) {
// return: root
x = get_root(x);
y = get_root(y);
if (x != y) {
if (data[y] < data[x])
swap(x, y);
data[x] += data[y];
data[y] = x;
querySize_[x] += querySize_[y] + 1;
roots.erase(y);
return x;
} else {
querySize_[x]++;
return x;
}
}
bool is_same(ll x, ll y) {
// check whether x and y are connected
return get_root(x) == get_root(y);
}
ll get_root(ll x) {
// get root
return data[x] < 0 ? x : data[x] = get_root(data[x]);
}
ll size(ll x) { return -data[get_root(x)]; }
ll query_size(ll x) { return querySize_[get_root(x)]; }
const set<ll> &get_roots() { return roots; }
void initialize() {
for (auto &i : data) {
i = -1;
}
}
};
template <class cost_t> struct Edge_Base {
ll from;
ll to;
cost_t cost;
Edge_Base reverse() const { return Edge_Base{to, from, cost}; }
Edge_Base(ll from, ll to, cost_t cost = 1) : from(from), to(to), cost(cost){};
Edge_Base(pll e) : from(e.first), to(e.second), cost(1) {}
Edge_Base() : from(0), to(0), cost(0){};
bool operator<(const Edge_Base &e) const { return cost < e.cost; }
bool operator>(const Edge_Base &e) const { return cost > e.cost; }
bool operator==(const Edge_Base &e) const {
return cost == e.cost && from == e.from && to == e.to;
}
};
using Edge = Edge_Base<ll>;
template <class EdgeType, class EdgeContainerType> struct Edge_Itr_Base {
constexpr Edge_Itr_Base() : index(), edges(nullptr) {}
constexpr Edge_Itr_Base(ll index, EdgeContainerType &edges_)
: index(index), edges(&edges_) {}
constexpr Edge_Itr_Base &operator++() {
++index;
return *this;
}
constexpr bool operator==(const Edge_Itr_Base &rhs) const {
return index == rhs.index;
}
constexpr bool operator!=(const Edge_Itr_Base &rhs) const {
return index != rhs.index;
}
constexpr EdgeType *operator->() const { return &(*edges)[index]; }
constexpr EdgeType &operator*() const { return (*edges)[index]; }
constexpr Edge_Itr_Base &operator+=(ll n) {
index += n;
return *this;
}
ll index;
EdgeContainerType *edges;
};
auto nullAction = [](const auto &) {};
template <class cost_t> struct Graph_Base {
using Edge = Edge_Base<cost_t>;
using Edge_Itr = Edge_Itr_Base<Edge_Base<cost_t>, vector<Edge_Base<cost_t>>>;
using Edge_CItr =
Edge_Itr_Base<const Edge_Base<cost_t>, const vector<Edge_Base<cost_t>>>;
ll nodeSize;
vector<Edge> edges;
vector<vector<Edge_Itr>> out_edges;
vector<vector<Edge_Itr>> in_edges;
enum Dir { dir, undir };
Graph_Base(ll nodeSize, const vector<Edge> &edges_ = vector<Edge>(),
Dir dirct = dir)
: nodeSize(nodeSize), out_edges(nodeSize), in_edges(nodeSize) {
if (dirct == undir) {
for (const Edge &e : edges_)
push_undir(e);
} else {
for (const Edge &e : edges_)
push(e);
}
}
Graph_Base(ll nodeSize, vector<pll> edges_, Dir dirct = dir)
: nodeSize(nodeSize), out_edges(nodeSize), in_edges(nodeSize) {
if (dirct == undir) {
for (const pll &e : edges_)
push_undir(Edge(e));
} else {
for (const pll &e : edges_)
push(Edge(e));
}
}
Graph_Base(vvll ajacency_matrix, ll default_value)
: nodeSize(ajacency_matrix.size()), out_edges(nodeSize),
in_edges(nodeSize) {
ll n = ajacency_matrix.size();
rep(i, 0, n) rep(j, 0, n) {
if (ajacency_matrix[i][j] != default_value)
push(Edge(i, j, ajacency_matrix[i][j]));
}
}
Edge &operator[](ll ind) { return this->edges[ind]; }
const Edge &operator[](ll ind) const { return this->edges[ind]; }
vector<Edge_Itr> &out(ll ind) { return this->out_edges[ind]; }
const vector<Edge_Itr> &out(ll ind) const { return this->out_edges[ind]; }
vector<Edge_Itr> &in(ll ind) { return this->in_edges[ind]; }
const vector<Edge_Itr> &in(ll ind) const { return this->in_edges[ind]; }
Edge_Itr begin() { return Edge_Itr(0, edges); }
Edge_Itr end() { return Edge_Itr(edges.size(), edges); }
Edge_CItr begin() const { return Edge_CItr(0, edges); }
Edge_CItr end() const { return Edge_CItr(edges.size(), edges); }
ll size() const { return nodeSize; }
ll sizeEdges() const { return edges.size(); }
void push(const Edge &edge) {
assert(max(edge.from, edge.to) < nodeSize);
edges.emplace_back(edge);
out_edges[edge.from].emplace_back(Edge_Itr(edges.size() - 1, edges));
in_edges[edge.to].emplace_back(Edge_Itr(edges.size() - 1, edges));
}
void push(const Edge &edge, Graph_Base::Dir dir) {
if (dir == Dir::undir)
push_undir(edge);
else
push(edge);
}
void push_undir(const Edge &edge) {
push(edge);
push(edge.reverse());
}
void push(vector<Edge> edges) {
for (const Edge &e : edges) {
push(e);
}
}
vvll adjacency_matrix() const {
vvll d(size(), vll(size()));
for (auto &e : edges) {
d[e.from][e.to] = e.cost;
}
return d;
}
vll get_topologically_sorted_nodes() const {
// graph needs to be represented by adjacent list.
// complexity: O( node size + edge size)
ll nodeSize = this->size();
// find root
vll roots;
vll inDegree(nodeSize);
rep(i, 0, nodeSize) {
for (auto &sibling : this->out(i)) {
inDegree[sibling->to]++;
}
}
rep(i, 0, nodeSize) {
if (inDegree[i] == 0) {
roots.push_back(i);
}
}
stack<ll> parents;
for (ll i : roots)
parents.push(i);
vll sortedNodes;
while (!parents.empty()) {
ll parent = parents.top();
parents.pop();
sortedNodes.push_back(parent);
for (auto &sibling : this->out(parent)) {
inDegree[sibling->to]--;
if (inDegree[sibling->to] == 0) {
parents.push(sibling->to);
}
}
}
return sortedNodes;
}
// not safe for Edge_Itr
// void topological_sort() {
// vll sorted = get_topologically_sorted_nodes();
// vll new_ind(sorted.size());
// vector<Edge> new_edges;
// rep(i, 0, sorted.size()) {
// new_ind[sorted[i]] = i;
// }
// for (Edge& e : edges) {
// new_edges.emplace_back(Edge{ new_ind[e.from], new_ind[e.to],e.cost
//});
// }
// *this = Graph_Base(this->size(), new_edges);
//}
cost_t diameter() const {
// require : graph is tree
// calculate the diameter ( longest path length ) in O(N)
vector<cost_t> dp(size(), -1);
cost_t m = 0;
ll ind;
function<void(ll)> dfs = [&](ll x) {
for (auto &e : this->out(x)) {
ll nextnode = e->to;
if (dp[nextnode] == -1) {
dp[nextnode] = dp[x] + e->cost;
if (dp[nextnode] > m) {
m = dp[nextnode];
ind = nextnode;
}
dfs(nextnode);
}
}
};
dp[0] = 0;
ind = 0;
dfs(0);
ll first = ind;
fill_v(dp, -1);
dp[first] = 0;
dfs(first);
return m;
// remark two end points of diameter are 'first' and 'ind';
}
cost_t max_length() const {
// calculate the max lenth of path in the graph
vector<cost_t> dp(size(), -1);
auto dfs = [&](auto dfs, ll x) -> void {
for (auto &e : this->out(x)) {
if (dp[e->to] == -1) {
dp[e->to] = 0;
dfs(dfs, e->to);
}
chmax(dp[e->from], dp[e->to] + e->cost);
}
};
rep(node, 0, size()) dfs(dfs, node);
return *max_element(all(dp));
}
vll leaves() const {
vll res;
rep(i, 0, nodeSize) {
if (out(i).size() <= 1)
res.push_back(i);
}
return res;
}
template <class T, class S = decltype(nullAction)>
void dfs(ll startNode, T before_act, S after_act = nullAction) const {
// Impliment func: void(const Edge&) representing what this should do, when
// target node moves from visited node (e.from) to unvisited node (e.to).
const auto &graph = *this;
vb visited(graph.size());
auto dfs_impl = [&](auto dfs_impl, ll startNode) -> void {
visited[startNode] = 1;
for (auto &e : graph.out(startNode)) {
if (visited[e->to])
continue;
before_act(*e);
dfs_impl(dfs_impl, e->to);
after_act(*e);
}
};
dfs_impl(dfs_impl, startNode);
};
template <class T, class S = decltype(nullAction)>
void dfs_node(ll startNode, T before_act, S after_act = nullAction) const {
// Impliment func: void(ll node_ind) representing what this should do, when
// target node moves from visited node to unvisited node (node_ind).
const auto &graph = *this;
vb visited(graph.size());
auto dfs_impl = [&](auto dfs_impl, ll startNode) -> void {
before_act(startNode);
visited[startNode] = 1;
for (auto &e : graph.out(startNode)) {
if (visited[e->to])
continue;
dfs_impl(dfs_impl, e->to);
}
after_act(startNode);
};
dfs_impl(dfs_impl, startNode);
};
template <class T, class S = decltype(nullAction)>
void bfs(ll startNode, T before_act, S after_act = nullAction) const {
const auto &graph = *this;
vb visited(graph.size());
auto bfs_impl = [&](ll startNode) {
// if (visited[startNode] != 0) return;
visited[startNode] = 1;
queue<Edge> toVisit;
for (auto &e : graph.out(startNode))
toVisit.push(*e);
while (toVisit.size()) {
auto next = toVisit.front();
toVisit.pop();
if (visited[next.to])
continue;
visited[next.to] = 1;
before_act(next);
for (auto &e : graph.out(next.to)) {
if (!visited[e->to])
toVisit.push(*e);
}
after_act(next);
}
};
bfs_impl(startNode);
};
vector<cost_t> dijkstra(ll start) const {
vector<cost_t> fromList;
return dijkstra(start, fromList);
}
vector<cost_t> dijkstra(ll start, vector<cost_t> &from_list) const {
// graph: weighted directed graph of adjacent representation
// start: index of start point
// return1: minimum path length from start
// complexity : E*log(V)
const auto &graph = *this;
ll node_size = graph.size();
vector<cost_t> dist(node_size, INF);
from_list.resize(node_size);
fill_v(from_list, -1);
dist[start] = 0;
pq_greater<pair<cost_t, pll>> pq;
pq.push({0, {start, start}});
while (!pq.empty()) {
auto node = pq.top();
pq.pop();
// if not shortest path fixed, fix
ll from = node.second.first;
ll to = node.second.second;
if (from_list[to] != -1)
continue;
from_list[to] = from;
for (auto &edge : graph.out(to)) {
ll adj = edge->to;
cost_t cost = dist[to] + edge->cost;
if (dist[adj] > cost) {
dist[adj] = min(dist[adj], cost);
pq.push({cost, {to, adj}});
}
}
}
return dist;
}
vll euler_tour(ll start) const {
vll res;
res.push_back(start);
dfs(
start, [&](const Edge &e) { res.push_back(e.to); },
[&](const Edge &e) { res.push_back(e.from); });
return res;
}
Graph_Base kruskal(Graph_Base::Dir = Dir::undir) const {
// returns minimal spanning tree
Graph_Base res(nodeSize);
vpll sortedEdges;
rep(i, 0, edges.size()) { sortedEdges.push_back({edges[i].cost, i}); }
sort(all(sortedEdges));
UnionFind uf(nodeSize);
rep(i, 0, sortedEdges.size()) {
ll cost, eInd;
tie(cost, eInd) = sortedEdges[i];
ll from = (*this)[eInd].from;
ll to = (*this)[eInd].to;
if (!uf.is_same(from, to)) {
res.push((*this)[eInd], dir);
}
uf.unite(from, to);
}
return res;
}
vvll warshall_floyd() const {
// O(|V|^3)
const Graph_Base &g = *this;
ll n = g.size();
vvll d = g.adjacency_matrix();
rep(k, 0, n) rep(i, 0, n) rep(j, 0, n) {
if (d[i][j] > d[i][k] + d[k][j])
d[i][j] = d[i][k] + d[k][j];
}
return d;
}
vll bellman_ford(ll start, ll negative_closed_loop_value = -INF) const {
vll from_list;
return bellman_ford(start, from_list, negative_closed_loop_value);
}
vll bellman_ford(ll start, vll &from_list,
ll negative_closed_loop_value = -INF) const {
// O(|E| * |V|)
const Graph_Base &g = *this;
vll dist(g.size(), INF);
dist[start] = 0;
from_list.resize(g.size());
rep(i, 0, g.size()) {
for (const Edge &e : g) {
if (dist[e.from] != INF && dist[e.to] > dist[e.from] + e.cost) {
dist[e.to] = dist[e.from] + e.cost;
from_list[e.to] = e.from;
if (i == g.size() - 1 && dist[e.to] != INF) {
// check negative closed loop
dist[e.to] = negative_closed_loop_value;
}
}
}
}
// propagate negative path
rep(i, 0, g.size()) {
rep(j, 0, g.edges.size()) {
auto &e = g.edges[j];
if (dist[e.from] == negative_closed_loop_value && dist[e.from] != INF)
dist[e.to] = negative_closed_loop_value;
}
}
return dist;
}
bool is_bipartite() const {
vll even(size(), -1);
even[0] = 0;
bool ok = true;
dfs_node(0, [&](ll node) {
for (auto &e : out(node)) {
if (even[e->to] != -1) {
if (even[e->from] == even[e->to]) {
ok = false;
break;
}
} else {
even[e->to] = !even[e->from];
}
}
});
return ok;
}
bool acyclic() const {
auto &g = *this;
vll visited(size());
auto dfs = [&](auto dfs, ll node) -> bool {
visited[node] = 1;
for (auto &e : g.out(node)) {
if (visited[e->to] == 1)
return false;
else if (visited[e->to] == 0 && !dfs(dfs, e->to))
return false;
}
visited[node] = 2;
return true;
};
rep(i, 0, g.size()) {
if (!dfs(dfs, 0))
return false;
}
return true;
}
};
using Graph = Graph_Base<ll>;
vll shortest_path_generator(const vll &from_list, ll start, ll goal) {
// usage : vll path = shortest_path(dijkstra(g,s).second, s, g);
vll path;
path.emplace_back(goal);
while (true) {
ll from = from_list[goal];
path.emplace_back(from);
if (from == start) {
break;
}
goal = from;
}
reverse(all(path));
return path;
}
class FordFulkerson {
private:
vb usedNode;
using Edge = Edge_Base<ll>;
public:
struct RevEdge {
ll from, to, cap, rev;
};
FordFulkerson(Graph graph)
: usedNode(graph.size()), G(vec_t<2, RevEdge>(graph.size())) {
rep(i, 0, graph.size()) {
for (auto &e : graph.out(i)) {
add_revedge(*e);
}
}
}
vec_t<2, RevEdge> G;
void add_revedge(const Edge &e) {
G[e.from].push_back(RevEdge{e.from, e.to, e.cost, SZ(G[e.to])});
G[e.to].push_back(RevEdge{e.to, e.from, 0, SZ(G[e.from]) - 1});
}
ll single_flow(ll from, ll to, ll flow) {
// make a single flow
if (from == to)
return flow;
usedNode[from] = 1;
rep(i, 0, G[from].size()) {
RevEdge &e = G[from][i];
if (usedNode[e.to] || e.cap <= 0)
continue;
ll flow_from_e = single_flow(e.to, to, min(flow, e.cap));
if (flow_from_e > 0) {
e.cap -= flow_from_e;
assert(e.cap >= 0);
G[e.to][e.rev].cap += flow_from_e;
// get a larger flow
return flow_from_e;
}
}
// if we already visited all edges or cap = 0 flow = 0;
return 0;
}
ll max_flow(ll from, ll to) {
ll flow = 0;
while (true) {
fill_v(usedNode, 0);
ll f = single_flow(from, to, INF);
if (f == 0)
return flow;
else
flow += f;
}
}
};
// Least Common Ancestor
class LCA {
public:
LCA(const Graph &graph, ll root)
: max_par(ceil(log2(graph.size()) + 2)),
parent(graph.size(), vll(max_par, -1)), depth() {
// parent[root][0] = root;
graph.dfs(root, [&](const Edge &e) {
ll to = e.to;
parent[to][0] = e.from;
rep(i, 1, parent[to].size()) {
if (parent[to][i - 1] == -1)
return;
else
parent[to][i] = (parent[parent[to][i - 1]][i - 1]);
}
});
depth = graph.dijkstra(root);
}
ll operator()(ll node1, ll node2) {
if (depth[node1] > depth[node2])
swap(node1, node2);
rrep(i, 0, max_par) {
if (((depth[node2] - depth[node1]) >> i) & 1) {
node2 = parent[node2][i];
}
}
if (node1 == node2)
return node1;
rrep(i, 0, max_par) {
if (parent[node1][i] != parent[node2][i]) {
node1 = parent[node1][i];
node2 = parent[node2][i];
}
}
return parent[node1][0];
}
private:
ll max_par;
vvll parent;
vll depth;
};
class BipartiteMatching {
// O(V*E)
int n, left, right;
vector<vector<int>> graph;
vector<int> used;
int timestamp;
public:
BipartiteMatching(int left, ll right)
: n(left + right), left(left), right(right), graph(n), used(n, 0),
timestamp(0) {}
void push(int u, int v) {
graph[u].push_back(v + left);
graph[v + left].push_back(u);
}
bool dfs(int idx, vector<int> &match) {
used[idx] = timestamp;
for (auto &to : graph[idx]) {
int to_match = match[to];
if (to_match == -1 ||
(used[to_match] != timestamp && dfs(to_match, match))) {
match[idx] = to;
match[to] = idx;
return true;
}
}
return false;
}
int bipartite_match(vector<int> &match) {
match.resize(n);
fill_v(match, -1);
int ret = 0;
for (int i = 0; i < SZ(graph); i++) {
if (match[i] == -1) {
++timestamp;
ret += dfs(i, match);
}
}
return ret;
}
int bipartite_match() {
vector<int> match;
return bipartite_match(match);
}
};
// tree dfs
// auto dfs = [&](auto dfs, ll from, ll to) ->void {
// for (auto& e : g.out(to)) {
// if (e->to != from) {
// // do something
// }
// }
//};
// dfs(dfs, 0, 0);
#include <math.h>
struct AA {
bool f() { return true; }
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
ll n;
cin >> n;
Graph g(n * (n - 1) / 2);
auto index = [&](pll p) {
if (p.first > p.second)
swap(p.first, p.second);
ll i = p.first;
ll j = p.second;
return i * (2 * n - 2 - i + 1) / 2 + (j - i - 1);
};
rep(i, 0, n) {
vll A(n - 1);
cin >> A;
rep(j, 0, n - 2) {
g.push({index({i, A[j] - 1}), index({i, A[j + 1] - 1})});
}
}
if (!g.acyclic())
cout << -1 << endl;
else {
cout << g.max_length() + 1 << endl;
}
return 0;
}
|
//#pragma GCC optimize ("-O3")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <type_traits>
#include <typeinfo>
#include <unordered_map>
#include <vector>
#ifdef _MSC_VER
#include <intrin.h>
#define popcnt __popcnt64
//# define __builtin_popcount __popcnt
#else
#define popcnt __builtin_popcountll
#endif
//#include "boost/variant.hpp"
using namespace std;
typedef long long ll;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;
#define rep(i, N, M) for (ll i = N, i##_len = (M); i < i##_len; ++i)
#define rep_skip(i, N, M, ...) \
for (ll i = N, i##_len = (M); i < i##_len; i += (skip))
#define rrep(i, N, M) for (ll i = (M)-1, i##_len = (N - 1); i > i##_len; --i)
#define pb push_back
#define fir first
#define sec second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define perm(c) \
sort(all(c)); \
for (bool c##perm = 1; c##perm; \
c##perm = next_permutation( \
all(c))) // perm(c){write(c)} writes all permutation of c
typedef pair<double, double> pd;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
template <typename T>
using pq_greater = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using vpt = vector<complex<T>>;
template <int n> struct tll_impl {
using type = decltype(tuple_cat(tuple<ll>(),
declval<typename tll_impl<n - 1>::type>()));
};
template <> struct tll_impl<1> { using type = tuple<ll>; };
template <int n> using tll = typename tll_impl<n>::type;
template <class T> constexpr ll SZ(T &v) { return static_cast<ll>(v.size()); };
template <int n, typename T> struct vec_t_impl {
using type = vector<typename vec_t_impl<n - 1, T>::type>;
};
template <typename T> struct vec_t_impl<1, T> { using type = vector<T>; };
template <int n, typename T> using vec_t = typename vec_t_impl<n, T>::type;
// check
static_assert(is_same<vec_t<3, ll>, vector<vector<vector<ll>>>>::value, "");
// decompose vector into basetype and dimension.
template <typename T> struct vec_dec {
static constexpr int dim = 0;
using type = T;
};
template <typename T> struct vec_dec<vector<T>> {
static constexpr int dim = vec_dec<T>::dim + 1;
using type = typename vec_dec<T>::type;
};
static_assert(is_same<typename vec_dec<vec_t<3, ll>>::type, ll>::value, "");
static_assert(vec_dec<vec_t<3, ll>>::dim == 3, "");
template <typename T = ll> vector<T> makev(size_t a) { return vector<T>(a); }
template <typename T = ll, typename... Ts> auto makev(size_t a, Ts... ts) {
return vector<decltype(makev<T>(ts...))>(a, makev<T>(ts...));
} // ex: auto dp = makev<ll>(4,5) => vector<vector<ll>> dp(4,vector<ll>(5));
template <typename T>
struct is_vector : std::false_type {}; // check if T is vector
template <typename T> struct is_vector<vector<T>> : std::true_type {};
static_assert(is_vector<vector<ll>>::value == true &&
is_vector<ll>::value == false,
"");
// check if T is vector
template <typename T> struct is_pair : std::false_type {};
template <typename T, typename S>
struct is_pair<pair<T, S>> : std::true_type {};
static_assert(is_pair<pll>::value == true && is_pair<ll>::value == false, "");
template <typename T, typename V,
typename enable_if<!is_vector<T>::value, nullptr_t>::type = nullptr>
void fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V,
typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr>
void fill_v(T &t, const V &v) {
for (auto &&x : t)
fill_v(x, v);
} // ex: fill_v(dp, INF);
namespace std {
template <class T> bool operator<(const complex<T> &a, const complex<T> &b) {
return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
}
}; // namespace std
template <typename T, typename S>
istream &operator>>(istream &istr, pair<T, S> &x) {
return istr >> x.first >> x.second;
}
template <typename T> istream &operator>>(istream &istr, vector<T> &x) {
rep(i, 0, x.size()) istr >> x[i];
return istr;
}
template <typename T> istream &operator>>(istream &istr, complex<T> &x) {
T r, i;
istr >> r >> i;
x.real(r);
x.imag(i);
return istr;
}
template <typename T, typename Delim_t = string,
typename enable_if<!is_vector<T>::value, nullptr_t>::type = nullptr>
void write(T &x, Delim_t delim = " ") {
cout << x << delim;
}
template <typename T, typename Delim_t = string,
typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr>
void write(T &x, Delim_t delim = " ") {
rep(i, 0, x.size()) write(x[i], (i == (x.size() - 1) ? "" : delim));
cout << '\n';
}
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
vll seq(ll i, ll j) {
vll res(j - i);
rep(k, i, j) res[k] = i + k;
return res;
}
constexpr ll POW_0(ll x, ll y) {
if (y == 0)
return 1;
if (y == 1)
return x;
if (y == 2)
return x * x;
if (y % 2 == 0)
return POW_0(POW_0(x, y / 2), 2LL);
return ((POW_0(POW_0(x, y / 2), 2LL)) * (x));
}
constexpr ll POW(ll x, ll y, ll mod = 0) {
if (mod == 0)
return POW_0(x, y);
if (y == 0)
return 1;
if (y == 1)
return x % mod;
if (y == 2)
return x * x % mod;
if (y % 2 == 0)
return POW(POW(x, y / 2, mod), 2LL, mod) % mod;
return ((POW(POW(x, y / 2, mod), 2LL, mod)) * (x % mod)) % mod;
}
template <typename Inputs, typename Functor,
typename T = typename Inputs::value_type>
void sort_by(Inputs &inputs, Functor f) {
std::sort(std::begin(inputs), std::end(inputs),
[&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); });
}
template <typename Inputs, typename Functor,
typename T = typename Inputs::value_type>
void stable_sort_by(Inputs &inputs, Functor f) {
std::stable_sort(
std::begin(inputs), std::end(inputs),
[&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); });
}
template <typename Inputs> void sort_uniq(Inputs &inputs) {
sort(all(inputs));
inputs.erase(unique(all(inputs)), inputs.end());
}
vector<string> split(const string &s, char delim) {
vector<string> elems;
stringstream ss(s);
string item;
while (getline(ss, item, delim)) {
if (!item.empty()) {
elems.push_back(item);
}
}
return elems;
}
template <class T> map<T, ll> inv_map(vector<T> &x) {
map<T, ll> res;
rep(i, 0, x.size()) { res[x[i]] = i; }
return res;
}
template <class T, class val_t = typename T::value_type,
enable_if_t<!is_same<T, set<val_t>>::value> * = nullptr>
constexpr bool exist(const T &container, val_t val) {
return find(all(container), val) != container.end();
}
template <class T, class val_t = typename T::value_type,
enable_if_t<is_same<T, set<val_t>>::value> * = nullptr>
constexpr bool exist(const T &container, val_t val) {
return container.find(val) != container.end();
}
struct UnionFind {
vector<ll> data;
vll querySize_;
set<ll> roots;
UnionFind(ll size) : data(size, -1), querySize_(size, 0) {
rep(i, 0, size) roots.insert(i);
}
ll unite(ll x, ll y) {
// return: root
x = get_root(x);
y = get_root(y);
if (x != y) {
if (data[y] < data[x])
swap(x, y);
data[x] += data[y];
data[y] = x;
querySize_[x] += querySize_[y] + 1;
roots.erase(y);
return x;
} else {
querySize_[x]++;
return x;
}
}
bool is_same(ll x, ll y) {
// check whether x and y are connected
return get_root(x) == get_root(y);
}
ll get_root(ll x) {
// get root
return data[x] < 0 ? x : data[x] = get_root(data[x]);
}
ll size(ll x) { return -data[get_root(x)]; }
ll query_size(ll x) { return querySize_[get_root(x)]; }
const set<ll> &get_roots() { return roots; }
void initialize() {
for (auto &i : data) {
i = -1;
}
}
};
template <class cost_t> struct Edge_Base {
ll from;
ll to;
cost_t cost;
Edge_Base reverse() const { return Edge_Base{to, from, cost}; }
Edge_Base(ll from, ll to, cost_t cost = 1) : from(from), to(to), cost(cost){};
Edge_Base(pll e) : from(e.first), to(e.second), cost(1) {}
Edge_Base() : from(0), to(0), cost(0){};
bool operator<(const Edge_Base &e) const { return cost < e.cost; }
bool operator>(const Edge_Base &e) const { return cost > e.cost; }
bool operator==(const Edge_Base &e) const {
return cost == e.cost && from == e.from && to == e.to;
}
};
using Edge = Edge_Base<ll>;
template <class EdgeType, class EdgeContainerType> struct Edge_Itr_Base {
constexpr Edge_Itr_Base() : index(), edges(nullptr) {}
constexpr Edge_Itr_Base(ll index, EdgeContainerType &edges_)
: index(index), edges(&edges_) {}
constexpr Edge_Itr_Base &operator++() {
++index;
return *this;
}
constexpr bool operator==(const Edge_Itr_Base &rhs) const {
return index == rhs.index;
}
constexpr bool operator!=(const Edge_Itr_Base &rhs) const {
return index != rhs.index;
}
constexpr EdgeType *operator->() const { return &(*edges)[index]; }
constexpr EdgeType &operator*() const { return (*edges)[index]; }
constexpr Edge_Itr_Base &operator+=(ll n) {
index += n;
return *this;
}
ll index;
EdgeContainerType *edges;
};
auto nullAction = [](const auto &) {};
template <class cost_t> struct Graph_Base {
using Edge = Edge_Base<cost_t>;
using Edge_Itr = Edge_Itr_Base<Edge_Base<cost_t>, vector<Edge_Base<cost_t>>>;
using Edge_CItr =
Edge_Itr_Base<const Edge_Base<cost_t>, const vector<Edge_Base<cost_t>>>;
ll nodeSize;
vector<Edge> edges;
vector<vector<Edge_Itr>> out_edges;
vector<vector<Edge_Itr>> in_edges;
enum Dir { dir, undir };
Graph_Base(ll nodeSize, const vector<Edge> &edges_ = vector<Edge>(),
Dir dirct = dir)
: nodeSize(nodeSize), out_edges(nodeSize), in_edges(nodeSize) {
if (dirct == undir) {
for (const Edge &e : edges_)
push_undir(e);
} else {
for (const Edge &e : edges_)
push(e);
}
}
Graph_Base(ll nodeSize, vector<pll> edges_, Dir dirct = dir)
: nodeSize(nodeSize), out_edges(nodeSize), in_edges(nodeSize) {
if (dirct == undir) {
for (const pll &e : edges_)
push_undir(Edge(e));
} else {
for (const pll &e : edges_)
push(Edge(e));
}
}
Graph_Base(vvll ajacency_matrix, ll default_value)
: nodeSize(ajacency_matrix.size()), out_edges(nodeSize),
in_edges(nodeSize) {
ll n = ajacency_matrix.size();
rep(i, 0, n) rep(j, 0, n) {
if (ajacency_matrix[i][j] != default_value)
push(Edge(i, j, ajacency_matrix[i][j]));
}
}
Edge &operator[](ll ind) { return this->edges[ind]; }
const Edge &operator[](ll ind) const { return this->edges[ind]; }
vector<Edge_Itr> &out(ll ind) { return this->out_edges[ind]; }
const vector<Edge_Itr> &out(ll ind) const { return this->out_edges[ind]; }
vector<Edge_Itr> &in(ll ind) { return this->in_edges[ind]; }
const vector<Edge_Itr> &in(ll ind) const { return this->in_edges[ind]; }
Edge_Itr begin() { return Edge_Itr(0, edges); }
Edge_Itr end() { return Edge_Itr(edges.size(), edges); }
Edge_CItr begin() const { return Edge_CItr(0, edges); }
Edge_CItr end() const { return Edge_CItr(edges.size(), edges); }
ll size() const { return nodeSize; }
ll sizeEdges() const { return edges.size(); }
void push(const Edge &edge) {
assert(max(edge.from, edge.to) < nodeSize);
edges.emplace_back(edge);
out_edges[edge.from].emplace_back(Edge_Itr(edges.size() - 1, edges));
in_edges[edge.to].emplace_back(Edge_Itr(edges.size() - 1, edges));
}
void push(const Edge &edge, Graph_Base::Dir dir) {
if (dir == Dir::undir)
push_undir(edge);
else
push(edge);
}
void push_undir(const Edge &edge) {
push(edge);
push(edge.reverse());
}
void push(vector<Edge> edges) {
for (const Edge &e : edges) {
push(e);
}
}
vvll adjacency_matrix() const {
vvll d(size(), vll(size()));
for (auto &e : edges) {
d[e.from][e.to] = e.cost;
}
return d;
}
vll get_topologically_sorted_nodes() const {
// graph needs to be represented by adjacent list.
// complexity: O( node size + edge size)
ll nodeSize = this->size();
// find root
vll roots;
vll inDegree(nodeSize);
rep(i, 0, nodeSize) {
for (auto &sibling : this->out(i)) {
inDegree[sibling->to]++;
}
}
rep(i, 0, nodeSize) {
if (inDegree[i] == 0) {
roots.push_back(i);
}
}
stack<ll> parents;
for (ll i : roots)
parents.push(i);
vll sortedNodes;
while (!parents.empty()) {
ll parent = parents.top();
parents.pop();
sortedNodes.push_back(parent);
for (auto &sibling : this->out(parent)) {
inDegree[sibling->to]--;
if (inDegree[sibling->to] == 0) {
parents.push(sibling->to);
}
}
}
return sortedNodes;
}
// not safe for Edge_Itr
// void topological_sort() {
// vll sorted = get_topologically_sorted_nodes();
// vll new_ind(sorted.size());
// vector<Edge> new_edges;
// rep(i, 0, sorted.size()) {
// new_ind[sorted[i]] = i;
// }
// for (Edge& e : edges) {
// new_edges.emplace_back(Edge{ new_ind[e.from], new_ind[e.to],e.cost
//});
// }
// *this = Graph_Base(this->size(), new_edges);
//}
cost_t diameter() const {
// require : graph is tree
// calculate the diameter ( longest path length ) in O(N)
vector<cost_t> dp(size(), -1);
cost_t m = 0;
ll ind;
function<void(ll)> dfs = [&](ll x) {
for (auto &e : this->out(x)) {
ll nextnode = e->to;
if (dp[nextnode] == -1) {
dp[nextnode] = dp[x] + e->cost;
if (dp[nextnode] > m) {
m = dp[nextnode];
ind = nextnode;
}
dfs(nextnode);
}
}
};
dp[0] = 0;
ind = 0;
dfs(0);
ll first = ind;
fill_v(dp, -1);
dp[first] = 0;
dfs(first);
return m;
// remark two end points of diameter are 'first' and 'ind';
}
cost_t max_length() const {
// calculate the max lenth of path in the graph
vector<cost_t> dp(size(), -1);
auto dfs = [&](auto dfs, ll x) -> void {
for (auto &e : this->out(x)) {
if (dp[e->to] == -1) {
dp[e->to] = 0;
dfs(dfs, e->to);
}
chmax(dp[e->from], dp[e->to] + e->cost);
}
};
rep(node, 0, size()) dfs(dfs, node);
return *max_element(all(dp));
}
vll leaves() const {
vll res;
rep(i, 0, nodeSize) {
if (out(i).size() <= 1)
res.push_back(i);
}
return res;
}
template <class T, class S = decltype(nullAction)>
void dfs(ll startNode, T before_act, S after_act = nullAction) const {
// Impliment func: void(const Edge&) representing what this should do, when
// target node moves from visited node (e.from) to unvisited node (e.to).
const auto &graph = *this;
vb visited(graph.size());
auto dfs_impl = [&](auto dfs_impl, ll startNode) -> void {
visited[startNode] = 1;
for (auto &e : graph.out(startNode)) {
if (visited[e->to])
continue;
before_act(*e);
dfs_impl(dfs_impl, e->to);
after_act(*e);
}
};
dfs_impl(dfs_impl, startNode);
};
template <class T, class S = decltype(nullAction)>
void dfs_node(ll startNode, T before_act, S after_act = nullAction) const {
// Impliment func: void(ll node_ind) representing what this should do, when
// target node moves from visited node to unvisited node (node_ind).
const auto &graph = *this;
vb visited(graph.size());
auto dfs_impl = [&](auto dfs_impl, ll startNode) -> void {
before_act(startNode);
visited[startNode] = 1;
for (auto &e : graph.out(startNode)) {
if (visited[e->to])
continue;
dfs_impl(dfs_impl, e->to);
}
after_act(startNode);
};
dfs_impl(dfs_impl, startNode);
};
template <class T, class S = decltype(nullAction)>
void bfs(ll startNode, T before_act, S after_act = nullAction) const {
const auto &graph = *this;
vb visited(graph.size());
auto bfs_impl = [&](ll startNode) {
// if (visited[startNode] != 0) return;
visited[startNode] = 1;
queue<Edge> toVisit;
for (auto &e : graph.out(startNode))
toVisit.push(*e);
while (toVisit.size()) {
auto next = toVisit.front();
toVisit.pop();
if (visited[next.to])
continue;
visited[next.to] = 1;
before_act(next);
for (auto &e : graph.out(next.to)) {
if (!visited[e->to])
toVisit.push(*e);
}
after_act(next);
}
};
bfs_impl(startNode);
};
vector<cost_t> dijkstra(ll start) const {
vector<cost_t> fromList;
return dijkstra(start, fromList);
}
vector<cost_t> dijkstra(ll start, vector<cost_t> &from_list) const {
// graph: weighted directed graph of adjacent representation
// start: index of start point
// return1: minimum path length from start
// complexity : E*log(V)
const auto &graph = *this;
ll node_size = graph.size();
vector<cost_t> dist(node_size, INF);
from_list.resize(node_size);
fill_v(from_list, -1);
dist[start] = 0;
pq_greater<pair<cost_t, pll>> pq;
pq.push({0, {start, start}});
while (!pq.empty()) {
auto node = pq.top();
pq.pop();
// if not shortest path fixed, fix
ll from = node.second.first;
ll to = node.second.second;
if (from_list[to] != -1)
continue;
from_list[to] = from;
for (auto &edge : graph.out(to)) {
ll adj = edge->to;
cost_t cost = dist[to] + edge->cost;
if (dist[adj] > cost) {
dist[adj] = min(dist[adj], cost);
pq.push({cost, {to, adj}});
}
}
}
return dist;
}
vll euler_tour(ll start) const {
vll res;
res.push_back(start);
dfs(
start, [&](const Edge &e) { res.push_back(e.to); },
[&](const Edge &e) { res.push_back(e.from); });
return res;
}
Graph_Base kruskal(Graph_Base::Dir = Dir::undir) const {
// returns minimal spanning tree
Graph_Base res(nodeSize);
vpll sortedEdges;
rep(i, 0, edges.size()) { sortedEdges.push_back({edges[i].cost, i}); }
sort(all(sortedEdges));
UnionFind uf(nodeSize);
rep(i, 0, sortedEdges.size()) {
ll cost, eInd;
tie(cost, eInd) = sortedEdges[i];
ll from = (*this)[eInd].from;
ll to = (*this)[eInd].to;
if (!uf.is_same(from, to)) {
res.push((*this)[eInd], dir);
}
uf.unite(from, to);
}
return res;
}
vvll warshall_floyd() const {
// O(|V|^3)
const Graph_Base &g = *this;
ll n = g.size();
vvll d = g.adjacency_matrix();
rep(k, 0, n) rep(i, 0, n) rep(j, 0, n) {
if (d[i][j] > d[i][k] + d[k][j])
d[i][j] = d[i][k] + d[k][j];
}
return d;
}
vll bellman_ford(ll start, ll negative_closed_loop_value = -INF) const {
vll from_list;
return bellman_ford(start, from_list, negative_closed_loop_value);
}
vll bellman_ford(ll start, vll &from_list,
ll negative_closed_loop_value = -INF) const {
// O(|E| * |V|)
const Graph_Base &g = *this;
vll dist(g.size(), INF);
dist[start] = 0;
from_list.resize(g.size());
rep(i, 0, g.size()) {
for (const Edge &e : g) {
if (dist[e.from] != INF && dist[e.to] > dist[e.from] + e.cost) {
dist[e.to] = dist[e.from] + e.cost;
from_list[e.to] = e.from;
if (i == g.size() - 1 && dist[e.to] != INF) {
// check negative closed loop
dist[e.to] = negative_closed_loop_value;
}
}
}
}
// propagate negative path
rep(i, 0, g.size()) {
rep(j, 0, g.edges.size()) {
auto &e = g.edges[j];
if (dist[e.from] == negative_closed_loop_value && dist[e.from] != INF)
dist[e.to] = negative_closed_loop_value;
}
}
return dist;
}
bool is_bipartite() const {
vll even(size(), -1);
even[0] = 0;
bool ok = true;
dfs_node(0, [&](ll node) {
for (auto &e : out(node)) {
if (even[e->to] != -1) {
if (even[e->from] == even[e->to]) {
ok = false;
break;
}
} else {
even[e->to] = !even[e->from];
}
}
});
return ok;
}
bool acyclic() const {
auto &g = *this;
vll visited(size());
auto dfs = [&](auto dfs, ll node) -> bool {
visited[node] = 1;
for (auto &e : g.out(node)) {
if (visited[e->to] == 1)
return false;
else if (visited[e->to] == 0 && !dfs(dfs, e->to))
return false;
}
visited[node] = 2;
return true;
};
rep(i, 0, g.size()) {
if (!dfs(dfs, i))
return false;
}
return true;
}
};
using Graph = Graph_Base<ll>;
vll shortest_path_generator(const vll &from_list, ll start, ll goal) {
// usage : vll path = shortest_path(dijkstra(g,s).second, s, g);
vll path;
path.emplace_back(goal);
while (true) {
ll from = from_list[goal];
path.emplace_back(from);
if (from == start) {
break;
}
goal = from;
}
reverse(all(path));
return path;
}
class FordFulkerson {
private:
vb usedNode;
using Edge = Edge_Base<ll>;
public:
struct RevEdge {
ll from, to, cap, rev;
};
FordFulkerson(Graph graph)
: usedNode(graph.size()), G(vec_t<2, RevEdge>(graph.size())) {
rep(i, 0, graph.size()) {
for (auto &e : graph.out(i)) {
add_revedge(*e);
}
}
}
vec_t<2, RevEdge> G;
void add_revedge(const Edge &e) {
G[e.from].push_back(RevEdge{e.from, e.to, e.cost, SZ(G[e.to])});
G[e.to].push_back(RevEdge{e.to, e.from, 0, SZ(G[e.from]) - 1});
}
ll single_flow(ll from, ll to, ll flow) {
// make a single flow
if (from == to)
return flow;
usedNode[from] = 1;
rep(i, 0, G[from].size()) {
RevEdge &e = G[from][i];
if (usedNode[e.to] || e.cap <= 0)
continue;
ll flow_from_e = single_flow(e.to, to, min(flow, e.cap));
if (flow_from_e > 0) {
e.cap -= flow_from_e;
assert(e.cap >= 0);
G[e.to][e.rev].cap += flow_from_e;
// get a larger flow
return flow_from_e;
}
}
// if we already visited all edges or cap = 0 flow = 0;
return 0;
}
ll max_flow(ll from, ll to) {
ll flow = 0;
while (true) {
fill_v(usedNode, 0);
ll f = single_flow(from, to, INF);
if (f == 0)
return flow;
else
flow += f;
}
}
};
// Least Common Ancestor
class LCA {
public:
LCA(const Graph &graph, ll root)
: max_par(ceil(log2(graph.size()) + 2)),
parent(graph.size(), vll(max_par, -1)), depth() {
// parent[root][0] = root;
graph.dfs(root, [&](const Edge &e) {
ll to = e.to;
parent[to][0] = e.from;
rep(i, 1, parent[to].size()) {
if (parent[to][i - 1] == -1)
return;
else
parent[to][i] = (parent[parent[to][i - 1]][i - 1]);
}
});
depth = graph.dijkstra(root);
}
ll operator()(ll node1, ll node2) {
if (depth[node1] > depth[node2])
swap(node1, node2);
rrep(i, 0, max_par) {
if (((depth[node2] - depth[node1]) >> i) & 1) {
node2 = parent[node2][i];
}
}
if (node1 == node2)
return node1;
rrep(i, 0, max_par) {
if (parent[node1][i] != parent[node2][i]) {
node1 = parent[node1][i];
node2 = parent[node2][i];
}
}
return parent[node1][0];
}
private:
ll max_par;
vvll parent;
vll depth;
};
class BipartiteMatching {
// O(V*E)
int n, left, right;
vector<vector<int>> graph;
vector<int> used;
int timestamp;
public:
BipartiteMatching(int left, ll right)
: n(left + right), left(left), right(right), graph(n), used(n, 0),
timestamp(0) {}
void push(int u, int v) {
graph[u].push_back(v + left);
graph[v + left].push_back(u);
}
bool dfs(int idx, vector<int> &match) {
used[idx] = timestamp;
for (auto &to : graph[idx]) {
int to_match = match[to];
if (to_match == -1 ||
(used[to_match] != timestamp && dfs(to_match, match))) {
match[idx] = to;
match[to] = idx;
return true;
}
}
return false;
}
int bipartite_match(vector<int> &match) {
match.resize(n);
fill_v(match, -1);
int ret = 0;
for (int i = 0; i < SZ(graph); i++) {
if (match[i] == -1) {
++timestamp;
ret += dfs(i, match);
}
}
return ret;
}
int bipartite_match() {
vector<int> match;
return bipartite_match(match);
}
};
// tree dfs
// auto dfs = [&](auto dfs, ll from, ll to) ->void {
// for (auto& e : g.out(to)) {
// if (e->to != from) {
// // do something
// }
// }
//};
// dfs(dfs, 0, 0);
#include <math.h>
struct AA {
bool f() { return true; }
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
ll n;
cin >> n;
Graph g(n * (n - 1) / 2);
auto index = [&](pll p) {
if (p.first > p.second)
swap(p.first, p.second);
ll i = p.first;
ll j = p.second;
return i * (2 * n - 2 - i + 1) / 2 + (j - i - 1);
};
rep(i, 0, n) {
vll A(n - 1);
cin >> A;
rep(j, 0, n - 2) {
g.push({index({i, A[j] - 1}), index({i, A[j + 1] - 1})});
}
}
if (!g.acyclic())
cout << -1 << endl;
else {
cout << g.max_length() + 1 << endl;
}
return 0;
}
|
[
"identifier.replace.add",
"literal.replace.remove",
"control_flow.branch.if.condition.change"
] | 729,637
| 729,638
|
u304121198
|
cpp
|
p02925
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int N;
int order[1005][1005 - 1];
int convert[1005][1005 - 1];
vector<vector<int>> E;
const int MAXV = 1005 * (1005 - 1) / 2;
int dp[MAXV];
bool finished[MAXV];
bool reached[MAXV];
int dfs(int pos) {
if (reached[pos]) {
if (!finished[pos])
return -1;
return dp[pos];
}
dp[pos] = 0;
reached[pos] = true;
for (int i = 0; i < E[pos].size(); i++) {
// cout <<"pos == " << pos << "to " << E[pos][i] << endl;
int res = dfs(E[pos][i]);
if (res == -1)
return -1;
dp[pos] = max(dp[pos], res + 1);
}
finished[pos] = true;
return dp[pos];
}
int main() {
cin >> N;
E.resize(N * (N - 1));
int cnt1 = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (j < i)
convert[i][j] = convert[j][i];
else if (i > j) {
convert[i][j] = cnt1;
cnt1++;
}
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++) {
cin >> order[i][j], order[i][j]--;
order[i][j] = convert[i][order[i][j]];
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 2; j++) {
E[order[i][j]].push_back(order[i][j + 1]);
// cout << order[i][j] << " -> " << order[i][j + 1] << endl;
}
}
int ans = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++) {
int res = dfs(order[i][j]);
if (res == -1) {
cout << -1 << endl;
return 0;
}
ans = max(ans, res);
}
}
cout << ans + 1 << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int N;
int order[1005][1005 - 1];
int convert[1005][1005 - 1];
vector<vector<int>> E;
const int MAXV = 1005 * (1005 - 1) / 2;
int dp[MAXV];
bool finished[MAXV];
bool reached[MAXV];
int dfs(int pos) {
if (reached[pos]) {
if (!finished[pos])
return -1;
return dp[pos];
}
dp[pos] = 0;
reached[pos] = true;
for (int i = 0; i < E[pos].size(); i++) {
// cout <<"pos == " << pos << "to " << E[pos][i] << endl;
int res = dfs(E[pos][i]);
if (res == -1)
return -1;
dp[pos] = max(dp[pos], res + 1);
}
finished[pos] = true;
return dp[pos];
}
int main() {
cin >> N;
E.resize(N * (N - 1));
int cnt1 = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (j < i)
convert[i][j] = convert[j][i];
else if (i < j) {
convert[i][j] = cnt1;
cnt1++;
}
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++) {
cin >> order[i][j], order[i][j]--;
order[i][j] = convert[i][order[i][j]];
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 2; j++) {
E[order[i][j]].push_back(order[i][j + 1]);
// cout << order[i][j] << " -> " << order[i][j + 1] << endl;
}
}
int ans = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++) {
int res = dfs(order[i][j]);
if (res == -1) {
cout << -1 << endl;
return 0;
}
ans = max(ans, res);
}
}
cout << ans + 1 << endl;
return 0;
}
|
[
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 729,643
| 729,644
|
u107077805
|
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> E[MAXV];
int id[MAXN][MAXN];
bool reached[MAXV];
bool finished[MAXV];
int dp[MAXV]; // max length of path from v
int dfs(int pos) {
if (reached[pos]) {
if (!finished[pos])
return -1;
return dp[pos];
}
dp[pos] = 0;
reached[pos] = true;
for (int i = 0; i < E[pos].size(); i++) {
// cout <<"pos == " << pos << "to " << E[pos][i] << endl;
int res = dfs(E[pos][i]);
if (res == -1)
return -1;
dp[pos] = max(dp[pos], res + 1);
}
finished[pos] = true;
return dp[pos];
}
int main() {
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1));
int V = 0;
rep(i, n) rep(j, n) {
if (i < j) {
id[i][j] = V++;
} else if (i > j) {
id[i][j] = id[j][i];
}
}
rep(i, n) {
rep(j, n - 1) {
cin >> a[i][j];
a[i][j]--;
a[i][j] = id[i][a[i][j]];
}
}
rep(i, n) {
rep(j, n - 2) { E[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;
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> E[MAXV];
int id[MAXN][MAXN];
bool reached[MAXV];
bool finished[MAXV];
int dp[MAXV]; // max length of path from v
int dfs(int pos) {
if (reached[pos]) {
if (!finished[pos])
return -1;
return dp[pos];
}
dp[pos] = 0;
reached[pos] = true;
for (int i = 0; i < E[pos].size(); i++) {
// cout <<"pos == " << pos << "to " << E[pos][i] << endl;
int res = dfs(E[pos][i]);
if (res == -1)
return -1;
dp[pos] = max(dp[pos], res + 1);
}
finished[pos] = true;
return dp[pos];
}
int main() {
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n - 1));
int V = 0;
rep(i, n) rep(j, n) {
if (i < j) {
id[i][j] = V++;
} else if (i > j) {
id[i][j] = id[j][i];
}
}
rep(i, n) {
rep(j, n - 1) {
cin >> a[i][j];
a[i][j]--;
a[i][j] = id[i][a[i][j]];
}
}
rep(i, n) {
rep(j, n - 2) { E[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 + 1 << endl;
return 0;
}
|
[
"expression.operation.binary.add"
] | 729,645
| 729,646
|
u107077805
|
cpp
|
p02925
|
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_E 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
vvi es;
vvi games;
int get_game_id(int i, int j) {
if (i > j)
swap(i, j);
return games[i][j];
}
vb vis;
vb done;
vi dp;
int M;
int dfs(int n) {
if (n >= M)
return -1;
// Found a cycle
if (vis[n] && !done[n])
return -1;
if (dp[n] >= 1)
return dp[n];
vis[n] = true; // visitting
dp[n] = 1; // day 1
for (int i : es[n]) {
int res = dfs(i);
if (res == -1)
return -1;
dp[n] = max(dp[n], res + 1);
}
done[n] = true; // visited
return dp[n];
}
int main_E() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vvi A(N, vi(N - 1));
REP(i, N) {
REP(j, N - 1) {
cin >> A[i][j];
A[i][j]--;
}
}
games = vvi(N, vi(N));
int gm_id = 0;
REP(i, N) {
REP(j, N) {
if (i < j) {
games[i][j] = gm_id;
gm_id++;
}
}
}
M = gm_id;
vvi prog(N, vi(N));
set<pii> st;
es = vvi(M);
REP(i, N) {
REP(j, N - 1) { prog[i][j] = get_game_id(i, A[i][j]); }
REP(j, N - 2) {
int g1 = prog[i][j];
int g2 = prog[i][j + 1];
if (st.count(pii(g1, g2)) == 0)
st.insert(pii(g1, g2));
else
continue;
es[g1].push_back(g2);
}
}
int ans = 0;
vis = vb(M, false);
done = vb(M, false);
dp = vi(M, -1);
// dp[i] := Max path length from i
REP(i, M) {
int res = dfs(0);
if (res == -1) {
ans = -1;
break;
}
ans = max(ans, res);
}
cout << ans << endl;
return 0;
}
|
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_E 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
vvi es;
vvi games;
int get_game_id(int i, int j) {
if (i > j)
swap(i, j);
return games[i][j];
}
vb vis;
vb done;
vi dp;
int M;
int dfs(int n) {
if (n >= M)
return -1;
// Found a cycle
if (vis[n] && !done[n])
return -1;
if (dp[n] >= 1)
return dp[n];
vis[n] = true; // visitting
dp[n] = 1; // day 1
for (int i : es[n]) {
int res = dfs(i);
if (res == -1)
return -1;
dp[n] = max(dp[n], res + 1);
}
done[n] = true; // visited
return dp[n];
}
int main_E() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vvi A(N, vi(N - 1));
REP(i, N) {
REP(j, N - 1) {
cin >> A[i][j];
A[i][j]--;
}
}
games = vvi(N, vi(N));
int gm_id = 0;
REP(i, N) {
REP(j, N) {
if (i < j) {
games[i][j] = gm_id;
gm_id++;
}
}
}
M = gm_id;
vvi prog(N, vi(N));
set<pii> st;
es = vvi(M);
REP(i, N) {
REP(j, N - 1) { prog[i][j] = get_game_id(i, A[i][j]); }
REP(j, N - 2) {
int g1 = prog[i][j];
int g2 = prog[i][j + 1];
if (st.count(pii(g1, g2)) == 0)
st.insert(pii(g1, g2));
else
continue;
es[g1].push_back(g2);
}
}
int ans = 0;
vis = vb(M, false);
done = vb(M, false);
dp = vi(M, -1);
// dp[i] := Max path length from i
REP(i, M) {
int res = dfs(i);
if (res == -1) {
ans = -1;
break;
}
ans = max(ans, res);
}
cout << ans << endl;
return 0;
}
|
[
"identifier.replace.add",
"literal.replace.remove",
"call.arguments.change"
] | 729,651
| 729,652
|
u404244809
|
cpp
|
p02925
|
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_E 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
vvi es;
vvi games;
int get_game_id(int i, int j) {
if (i > j)
swap(i, j);
return games[i][j];
}
vb vis;
vb done;
vi dp;
int M;
int dfs(int n) {
if (n >= M)
return -1;
// Found a cycle
if (vis[n] && !done[n])
return -1;
if (dp[n] >= 1)
return dp[n];
vis[n] = true; // visitting
dp[n] = 1; // day 1
for (int i : es[n]) {
int res = dfs(i);
if (res == -1)
return -1;
dp[n] = max(dp[n], res + 1);
}
done[n] = true; // visited
return dp[n];
}
int main_E() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vvi A(N, vi(N - 1));
REP(i, N) {
REP(j, N - 1) {
cin >> A[i][j];
A[i][j]--;
}
}
games = vvi(N, vi(N));
int gm_id = 0;
REP(i, N) {
REP(j, N) {
if (i < j) {
games[i][j] = gm_id;
gm_id++;
}
}
}
M = gm_id;
vvi prog(N, vi(N));
set<pii> st;
es = vvi(M);
REP(i, N) {
REP(j, N - 1) { prog[i][j] = get_game_id(i, A[i][j]); }
REP(j, N - 2) {
int g1 = prog[i][j];
int g2 = prog[i][j + 1];
if (st.count(pii(g1, g2)) == 0)
st.insert(pii(g1, g2));
else
continue;
es[g1].push_back(g2);
}
}
int ans = 0;
vis = vb(M, false);
done = vb(M, false);
dp = vi(M, -1);
// dp[i] := Max path length from i
REP(i, M) {
int res = dfs(0);
if (res == -1) {
ans = -1;
}
ans = max(ans, res);
}
cout << ans << endl;
return 0;
}
|
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_E 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
vvi es;
vvi games;
int get_game_id(int i, int j) {
if (i > j)
swap(i, j);
return games[i][j];
}
vb vis;
vb done;
vi dp;
int M;
int dfs(int n) {
if (n >= M)
return -1;
// Found a cycle
if (vis[n] && !done[n])
return -1;
if (dp[n] >= 1)
return dp[n];
vis[n] = true; // visitting
dp[n] = 1; // day 1
for (int i : es[n]) {
int res = dfs(i);
if (res == -1)
return -1;
dp[n] = max(dp[n], res + 1);
}
done[n] = true; // visited
return dp[n];
}
int main_E() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vvi A(N, vi(N - 1));
REP(i, N) {
REP(j, N - 1) {
cin >> A[i][j];
A[i][j]--;
}
}
games = vvi(N, vi(N));
int gm_id = 0;
REP(i, N) {
REP(j, N) {
if (i < j) {
games[i][j] = gm_id;
gm_id++;
}
}
}
M = gm_id;
vvi prog(N, vi(N));
set<pii> st;
es = vvi(M);
REP(i, N) {
REP(j, N - 1) { prog[i][j] = get_game_id(i, A[i][j]); }
REP(j, N - 2) {
int g1 = prog[i][j];
int g2 = prog[i][j + 1];
if (st.count(pii(g1, g2)) == 0)
st.insert(pii(g1, g2));
else
continue;
es[g1].push_back(g2);
}
}
int ans = 0;
vis = vb(M, false);
done = vb(M, false);
dp = vi(M, -1);
// dp[i] := Max path length from i
REP(i, M) {
int res = dfs(i);
if (res == -1) {
ans = -1;
break;
}
ans = max(ans, res);
}
cout << ans << endl;
return 0;
}
|
[
"identifier.replace.add",
"literal.replace.remove",
"call.arguments.change"
] | 729,653
| 729,652
|
u404244809
|
cpp
|
p02925
|
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_E 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
vvi es;
vvi games;
int get_game_id(int i, int j) {
if (i > j)
swap(i, j);
return games[i][j];
}
vb vis;
vb done;
vi dp;
int M;
int dfs(int n) {
if (n >= M)
return -1;
// Found a cycle
if (vis[n]) {
if (!done[n])
return -1;
return dp[n];
}
vis[n] = true; // visitting
dp[n] = 1; // day 1
for (int i : es[n]) {
int res = dfs(i);
if (res == -1)
return -1;
dp[n] = max(dp[n], res + 1);
}
done[n] = true; // visited
return dp[n];
}
int main_E() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vvi A(N, vi(N - 1));
REP(i, N) {
REP(j, N - 1) {
cin >> A[i][j];
A[i][j]--;
}
}
games = vvi(N, vi(N));
int gm_id = 0;
REP(i, N) {
REP(j, N) {
if (i < j) {
games[i][j] = gm_id;
gm_id++;
}
}
}
M = gm_id;
vvi prog(N, vi(N));
set<pii> st;
es = vvi(M);
REP(i, N) {
REP(j, N - 1) { prog[i][j] = get_game_id(i, A[i][j]); }
REP(j, N - 2) {
int g1 = prog[i][j];
int g2 = prog[i][j + 1];
if (st.count(pii(g1, g2)) == 0)
st.insert(pii(g1, g2));
else
continue;
es[g1].push_back(g2);
}
}
int ans = 0;
vis = vb(M, false);
done = vb(M, false);
dp = vi(M, -1);
// dp[i] := Max path length from i
REP(i, M) {
int res = dfs(0);
if (res == -1) {
ans = -1;
break;
}
ans = max(ans, res);
}
cout << ans << endl;
return 0;
}
|
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_E 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
vvi es;
vvi games;
int get_game_id(int i, int j) {
if (i > j)
swap(i, j);
return games[i][j];
}
vb vis;
vb done;
vi dp;
int M;
int dfs(int n) {
if (n >= M)
return -1;
// Found a cycle
if (vis[n]) {
if (!done[n])
return -1;
return dp[n];
}
vis[n] = true; // visitting
dp[n] = 1; // day 1
for (int i : es[n]) {
int res = dfs(i);
if (res == -1)
return -1;
dp[n] = max(dp[n], res + 1);
}
done[n] = true; // visited
return dp[n];
}
int main_E() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vvi A(N, vi(N - 1));
REP(i, N) {
REP(j, N - 1) {
cin >> A[i][j];
A[i][j]--;
}
}
games = vvi(N, vi(N));
int gm_id = 0;
REP(i, N) {
REP(j, N) {
if (i < j) {
games[i][j] = gm_id;
gm_id++;
}
}
}
M = gm_id;
vvi prog(N, vi(N));
set<pii> st;
es = vvi(M);
REP(i, N) {
REP(j, N - 1) { prog[i][j] = get_game_id(i, A[i][j]); }
REP(j, N - 2) {
int g1 = prog[i][j];
int g2 = prog[i][j + 1];
if (st.count(pii(g1, g2)) == 0)
st.insert(pii(g1, g2));
else
continue;
es[g1].push_back(g2);
}
}
int ans = 0;
vis = vb(M, false);
done = vb(M, false);
dp = vi(M, -1);
// dp[i] := Max path length from i
REP(i, M) {
int res = dfs(i);
if (res == -1) {
ans = -1;
break;
}
ans = max(ans, res);
}
cout << ans << endl;
return 0;
}
|
[
"identifier.replace.add",
"literal.replace.remove",
"call.arguments.change"
] | 729,654
| 729,655
|
u404244809
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> g[1111][1111];
int d[1111][1111], v[1111][1111];
int f(int i, int j) {
if (v[i][j])
return d[i][j] ? d[i][j] : 1e9;
v[i][j] = 1;
int m = 0;
for (auto p : g[i][j])
m = max(m, f(p.first, p.second));
return d[i][j] = m + 1;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
pair<int, int> p;
for (int j = 1; j < n; j++) {
int a;
scanf("%d", &a);
auto q = minmax(i + 1, a);
if (j > 1)
g[p.first][p.second].push_back(q);
p = q;
}
}
int m = 0;
for (int i = 1; i < n; i++)
for (int j = i; j < n; j++)
m = max(m, f(i, j + 1));
cout << (m < 1e9 ? m : -1) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> g[1111][1111];
int d[1111][1111], v[1111][1111];
int f(int i, int j) {
if (v[i][j])
return d[i][j] ? d[i][j] : 1e9;
v[i][j] = 1;
int m = 0;
for (auto p : g[i][j])
m = max(m, f(p.first, p.second));
return d[i][j] = m + 1;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
pair<int, int> p, q;
for (int j = 1; j < n; j++) {
int a;
scanf("%d", &a);
q = minmax(i + 1, a);
if (j > 1)
g[p.first][p.second].push_back(q);
p = q;
}
}
int m = 0;
for (int i = 1; i < n; i++)
for (int j = i; j < n; j++)
m = max(m, f(i, j + 1));
cout << (m < 1e9 ? m : -1) << endl;
return 0;
}
|
[
"variable_declaration.add"
] | 729,677
| 729,678
|
u337381518
|
cpp
|
p02925
|
#include <bits/stdc++.h>
#define int long long
#define sd(a) scanf("%lld", &a)
#define pd(a) printf("%lld", a)
using namespace std;
const int maxn = 1e3 + 10;
int a[maxn][maxn];
int dur[maxn];
bool vis[maxn];
main() {
int n;
sd(n);
for (int i = 1; i <= n; ++i)
dur[i] = 1ll;
for (int i = 1; i <= n; ++i)
for (int j = 1; j < n; ++j)
sd(a[i][j]);
int day = 0;
while (1) {
day++;
memset(vis, false, sizeof(vis));
bool flag = true;
for (int i = 1; i <= n; ++i) {
int to = a[i][dur[i]];
if (dur[i] == n || vis[i] || vis[to])
continue;
if (a[to][dur[to]] != i || dur[to] == n)
break;
else {
flag = false;
vis[i] = true;
vis[to] = true;
dur[i]++;
dur[to]++;
}
}
if (flag)
break;
}
for (int i = 1; i <= n; ++i) {
if (dur[i] != n) {
puts("-1");
return 0;
}
}
pd(day - 1);
puts("");
}
|
#include <bits/stdc++.h>
#define int long long
#define sd(a) scanf("%lld", &a)
#define pd(a) printf("%lld", a)
using namespace std;
const int maxn = 1e3 + 10;
int a[maxn][maxn];
int dur[maxn];
bool vis[maxn];
main() {
int n;
sd(n);
for (int i = 1; i <= n; ++i)
dur[i] = 1ll;
for (int i = 1; i <= n; ++i)
for (int j = 1; j < n; ++j)
sd(a[i][j]);
int day = 0;
while (1) {
day++;
memset(vis, false, sizeof(vis));
bool flag = true;
for (int i = 1; i <= n; ++i) {
int to = a[i][dur[i]];
if (dur[i] == n || vis[i] || vis[to] || a[to][dur[to]] != i ||
dur[to] == n)
continue;
else {
flag = false;
vis[i] = true;
vis[to] = true;
dur[i]++;
dur[to]++;
}
}
if (flag)
break;
}
for (int i = 1; i <= n; ++i) {
if (dur[i] != n) {
puts("-1");
return 0;
}
}
pd(day - 1);
puts("");
}
|
[
"control_flow.branch.if.condition.change",
"control_flow.break.remove",
"control_flow.continue.add"
] | 729,686
| 729,687
|
u976418120
|
cpp
|
p02925
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);
int main() {
int n;
cin >> n;
queue<int> v[n + 1];
rep(i, n) {
rep(j, n - 1) {
int a;
cin >> a;
v[i + 1].push(a);
}
}
int day = 0;
vector<int> c(n + 1);
ll sum = 0;
ll suma = n * (n - 1) / 2;
ll g = 0;
while (true) {
day++;
bool t = false;
for (int i = 1; i < n + 1; i++) {
g++;
if (!v[i].empty()) {
int aite = v[i].front();
if (!v[aite].empty() && c[aite] != day && c[i] != day &&
v[aite].front() == i) {
v[aite].pop();
v[i].pop();
c[i] = day;
c[aite] = day;
sum++;
t = true;
}
}
}
if (t == false) {
break;
}
if (g > suma) {
cout << suma << endl;
return 0;
}
}
for (int i = 1; i <= n; i++) {
if (v[i].size() >= 1) {
cout << -1 << endl;
return 0;
}
}
day--;
cout << day << endl;
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);
int main() {
int n;
cin >> n;
queue<int> v[n + 1];
rep(i, n) {
rep(j, n - 1) {
int a;
cin >> a;
v[i + 1].push(a);
}
}
int day = 0;
vector<int> c(n + 1);
ll sum = 0;
ll suma = n * (n - 1) / 2;
ll g = 0;
while (true) {
day++;
bool t = false;
for (int i = 1; i < n + 1; i++) {
g++;
if (!v[i].empty()) {
int aite = v[i].front();
if (!v[aite].empty() && c[aite] != day && c[i] != day &&
v[aite].front() == i) {
v[aite].pop();
v[i].pop();
c[i] = day;
c[aite] = day;
sum++;
t = true;
}
}
}
if (t == false) {
break;
}
if (g > 1000000) {
cout << suma << endl;
return 0;
}
}
for (int i = 1; i <= n; i++) {
if (v[i].size() >= 1) {
cout << -1 << endl;
return 0;
}
}
day--;
cout << day << endl;
return 0;
}
|
[
"identifier.replace.remove",
"literal.replace.add",
"control_flow.branch.if.condition.change"
] | 729,701
| 729,702
|
u031448582
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)2e9 + 1;
const long long LINF = (long long)9e18 + 1;
const int MAXN = 1005;
const int MAXV = MAXN * (MAXN - 1) / 2;
vector<int> to[MAXV];
int id[MAXN][MAXV];
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]; // max length of path from v
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() {
cin.tie(0);
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 (auto &v : a[i]) {
cin >> v;
v--; // i -> i-1
}
}
int V = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i < j) {
id[i][j] = V++;
}
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++) {
a[i][j] = toId(i, a[i][j]);
}
for (int j = 0; j < N - 2; j++) {
to[a[i][j + 1]].push_back(a[i][j]);
}
}
int ans = 0;
for (int i = 0; i < V; i++) {
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>
using namespace std;
const int INF = (int)2e9 + 1;
const long long LINF = (long long)9e18 + 1;
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]; // max length of path from v
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() {
cin.tie(0);
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 (auto &v : a[i]) {
cin >> v;
v--; // i -> i-1
}
}
int V = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i < j) {
id[i][j] = V++;
}
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N - 1; j++) {
a[i][j] = toId(i, a[i][j]);
}
for (int j = 0; j < N - 2; j++) {
to[a[i][j + 1]].push_back(a[i][j]);
}
}
int ans = 0;
for (int i = 0; i < V; i++) {
int res = dfs(i);
if (res == -1) {
puts("-1");
return 0;
}
ans = max(ans, dfs(i));
}
cout << ans << endl;
return 0;
// cin.tie(0);
// 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 (auto &v : a[i]) {
// cin >> v;
// v--; // i -> i-1
// }
// reverse(a[i].begin(), a[i].end());
// }
// vector<pair<int, int>> que;
// auto check = [&](int i) {
// if (a[i].size() == 0) return;
// int j = a[i].back();
// if (a[j].size() == 0) return;
// if (a[j].back() == i) {
// pair<int, int> p(i, j);
// if (p.second < p.first) swap(p.first, p.second);
// que.push_back(p);
// }
// };
// for (int i = 0; i < N; i++) {
// check(i);
// }
// int day = 0;
// while (que.size() > 0) {
// day++;
// sort(que.begin(), que.end());
// que.erase(unique(que.begin(), que.end()), que.end());
// vector<pair<int, int>> prevQ;
// swap(prevQ, que);
// for (auto &p : prevQ) {
// int i = p.first, j = p.second;
// a[i].pop_back();
// a[j].pop_back();
// }
// for (auto &p : prevQ) {
// int i = p.first, j = p.second;
// check(i);
// check(j);
// }
// }
// for (int i = 0; i < N; i++) {
// if (a[i].size() != 0) {
// puts("-1");
// return 0;
// }
// }
// cout << day << endl;
// return 0;
}
|
[
"identifier.change",
"variable_declaration.array_dimensions.change"
] | 729,709
| 729,710
|
u480117549
|
cpp
|
p02925
|
#if 1
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e3 + 5;
const int inf = 80000;
#define endl '\n'
int vs[N][N];
int p[N], idx[N];
bool vis[N], flag;
int getint() {
int w = 0, q = 0;
char c = getchar();
while (c < '0' || c > '9' && c != '-')
c = getchar();
if (c == '-')
q = 1, c = getchar();
while (c >= '0' && c <= '9')
w = w * 10 + c - '0', c = getchar();
return q ? -w : w;
}
int main() {
int n, sum;
n = getint();
for (int i = 1; i <= n; i++)
for (int j = 1; j < n; j++)
vs[i][j] = getint();
for (int i = 1; i <= n; i++)
p[i] = 1;
flag = 0;
sum = 0;
memset(vis, 0, sizeof(vis));
while (!flag && sum < inf) {
flag = 1;
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (p[i] == n)
continue;
int cp = vs[i][p[i]];
if (p[cp] == n)
continue;
int tp = vs[cp][p[cp]];
if (tp == i && !vis[i] && !vis[cp]) {
vis[i] = vis[cp] = 1;
p[i]++;
p[cp]++;
idx[cnt++] = i;
idx[cnt++] = cp;
if (flag)
flag = 0;
}
}
for (int i = 0; i < cnt; i++)
vis[idx[i]] = 0;
sum++;
}
if (sum == inf) {
printf("%d\n", n * (n - 1) / 2);
return 0;
}
for (int i = 1; i <= n; i++) {
if (p[i] != n) {
flag = 0;
break;
}
}
if (!flag)
sum = 0;
else
printf("%d\n", sum - 1);
return 0;
}
#endif
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e3 + 5;
const int inf = 80000;
#define endl '\n'
int vs[N][N];
int p[N], idx[N];
bool vis[N], flag;
int getint() {
int w = 0, q = 0;
char c = getchar();
while (c < '0' || c > '9' && c != '-')
c = getchar();
if (c == '-')
q = 1, c = getchar();
while (c >= '0' && c <= '9')
w = w * 10 + c - '0', c = getchar();
return q ? -w : w;
}
int main() {
int n, sum;
n = getint();
for (int i = 1; i <= n; i++)
for (int j = 1; j < n; j++)
vs[i][j] = getint();
for (int i = 1; i <= n; i++)
p[i] = 1;
flag = 0;
sum = 0;
memset(vis, 0, sizeof(vis));
while (!flag && sum < inf) {
flag = 1;
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (p[i] == n)
continue;
int cp = vs[i][p[i]];
if (p[cp] == n)
continue;
int tp = vs[cp][p[cp]];
if (tp == i && !vis[i] && !vis[cp]) {
vis[i] = vis[cp] = 1;
p[i]++;
p[cp]++;
idx[cnt++] = i;
idx[cnt++] = cp;
if (flag)
flag = 0;
}
}
for (int i = 0; i < cnt; i++)
vis[idx[i]] = 0;
sum++;
}
if (sum == inf) {
printf("%d\n", n * (n - 1) / 2);
return 0;
}
for (int i = 1; i <= n; i++) {
if (p[i] != n) {
flag = 0;
break;
}
}
if (!flag)
sum = 0;
printf("%d\n", sum - 1);
return 0;
}
|
[
"control_flow.branch.else.remove"
] | 729,715
| 729,716
|
u278034730
|
cpp
|
p02925
|
#include <algorithm>
#include <array>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <vector>
using namespace std;
//#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
typedef long long ll;
// static const ll MOD = 1000000007;
int main() {
ll N;
ll day = 0;
// input
cin >> N;
ll A[N][N - 1];
for (ll i = 0; i < N; i++) {
for (ll j = 0; j < N - 1; j++) {
ll a;
cin >> a;
A[i][j] = a - 1;
};
}
// process
ll progress[N];
memset(progress, 0, sizeof(progress));
int day_play[N];
ll complete = 0;
while (1) {
ll day_progress = 0;
day++;
memset(day_play, 0, sizeof(day_play));
for (ll player = 0; player < N; player++) {
if (day_play[player] == 1 || progress[player] == N - 1) {
continue;
}
ll enemy_player = A[player][progress[player]];
if (day_play[enemy_player] == 1) {
continue;
}
if (progress[enemy_player] == N - 1) {
cout << -1 << endl;
return 0;
}
if (A[enemy_player][progress[enemy_player] == player]) {
progress[player]++;
if (progress[player] == N - 1) {
complete++;
}
progress[enemy_player]++;
if (progress[enemy_player] == N - 1) {
complete++;
}
day_progress++;
day_play[player] = 1;
day_play[enemy_player] = 1;
}
}
if (complete >= N) {
break;
}
if (day_progress == 0) {
cout << -1 << endl;
return 0;
}
}
cout << day << endl;
return 0;
}
|
#include <algorithm>
#include <array>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <vector>
using namespace std;
//#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
typedef long long ll;
// static const ll MOD = 1000000007;
int main() {
ll N;
ll day = 0;
// input
cin >> N;
ll A[N][N - 1];
for (ll i = 0; i < N; i++) {
for (ll j = 0; j < N - 1; j++) {
ll a;
cin >> a;
A[i][j] = a - 1;
};
}
// process
ll progress[N];
memset(progress, 0, sizeof(progress));
int day_play[N];
ll complete = 0;
while (1) {
ll day_progress = 0;
day++;
memset(day_play, 0, sizeof(day_play));
for (ll player = 0; player < N; player++) {
if (day_play[player] == 1 || progress[player] == N - 1) {
continue;
}
ll enemy_player = A[player][progress[player]];
if (day_play[enemy_player] == 1) {
continue;
}
if (progress[enemy_player] == N - 1) {
cout << -1 << endl;
return 0;
}
if (A[enemy_player][progress[enemy_player]] == player) {
progress[player]++;
if (progress[player] == N - 1) {
complete++;
}
progress[enemy_player]++;
if (progress[enemy_player] == N - 1) {
complete++;
}
day_progress++;
day_play[player] = 1;
day_play[enemy_player] = 1;
}
}
if (complete >= N) {
break;
}
if (day_progress == 0) {
cout << -1 << endl;
return 0;
}
}
cout << day << endl;
return 0;
}
|
[
"control_flow.branch.if.condition.change"
] | 729,734
| 729,735
|
u909577618
|
cpp
|
p02925
|
#include <bits/stdc++.h>
#define maxn 1005
using namespace std;
int n;
inline int id(int i, int j) { return i * n + j; }
vector<int> G[maxn * maxn];
int vis[maxn * maxn];
int dp[maxn * maxn];
bool dfs(int u) {
dp[u] = 1;
vis[u] = 1;
for (int v : G[u]) {
if (vis[v] == 1)
return false;
else {
if (vis[v] == 0 && !dfs(v))
return false;
dp[u] = max(dp[u], dp[v] + 1);
}
}
vis[u] = -1;
return true;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1, pre = -1; j < n; j++) {
int u = i, v;
cin >> v;
u--;
v--;
if (u > v)
swap(u, v);
int now = id(u, v);
if (pre != -1)
G[pre].emplace_back(now);
pre = now;
}
}
int m = n * (n - 1) / 2;
int ans = 0;
for (int i = 0; i < m; i++)
if (vis[i] == 0) {
if (dfs(i))
ans = max(ans, dp[i]);
else {
ans = -1;
break;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define maxn 1005
using namespace std;
int n;
inline int id(int i, int j) { return i * n + j; }
vector<int> G[maxn * maxn];
int vis[maxn * maxn];
int dp[maxn * maxn];
bool dfs(int u) {
dp[u] = 1;
vis[u] = 1;
for (int v : G[u]) {
if (vis[v] == 1)
return false;
else {
if (vis[v] == 0 && !dfs(v))
return false;
dp[u] = max(dp[u], dp[v] + 1);
}
}
vis[u] = -1;
return true;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1, pre = -1; j < n; j++) {
int u = i, v;
cin >> v;
u--;
v--;
if (u > v)
swap(u, v);
int now = id(u, v);
if (pre != -1)
G[pre].emplace_back(now);
pre = now;
}
}
int m = n * (n - 1) + (n - 2);
int ans = 0;
for (int i = 0; i < m; i++)
if (vis[i] == 0) {
if (dfs(i))
ans = max(ans, dp[i]);
else {
ans = -1;
break;
}
}
cout << ans << endl;
return 0;
}
|
[
"expression.operator.arithmetic.change",
"expression.operation.binary.change"
] | 729,759
| 729,760
|
u399391169
|
cpp
|
p02925
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#pragma region
using namespace std;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0LL, n)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define rrep(i, n) RFOR(i, 0LL, n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define COUNT(a, y, x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) \
sort(all(a)); \
a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
// const ll mod = 998244353LL;
ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
ll dx[9] = {0, 1, 0, -1, 0, 1, 1, -1, -1},
dy[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
#define endl '\n'
#pragma endregion
#define MAX 222222
bool used[1111], b[1111][1111];
ll idx[1111];
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
vll a[1111];
FOR(i, 1, n + 1) {
rep(j, n - 1) {
cin >> tmp;
a[i].pb(tmp);
}
}
ans = 1;
queue<ll> q;
FOR(i, 1, n + 1) q.push(i);
while (!q.empty()) {
ll cur = q.front();
q.pop();
ll to = a[cur][idx[cur]];
if (b[to][cur]) {
idx[cur]++;
if (used[cur] || used[to]) {
ans++;
FOR(i, 1, n + 1) used[i] = false;
} else {
used[cur] = true;
used[to] = true;
}
if (idx[cur] < n - 1)
q.push(cur);
if (idx[to] < n - 1)
q.push(to);
} else {
b[cur][to] = true;
idx[cur]++;
}
}
bool ok = true;
FOR(i, 1, n + 1) if (idx[i] != n - 1) ok = false;
if (!ok)
cout << "-1" << endl;
else
cout << ans + 1 << endl;
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#pragma region
using namespace std;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0LL, n)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define rrep(i, n) RFOR(i, 0LL, n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define COUNT(a, y, x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) \
sort(all(a)); \
a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
// const ll mod = 998244353LL;
ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
ll dx[9] = {0, 1, 0, -1, 0, 1, 1, -1, -1},
dy[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
#define endl '\n'
#pragma endregion
#define MAX 222222
bool used[1111], b[1111][1111];
ll idx[1111];
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
vll a[1111];
FOR(i, 1, n + 1) {
rep(j, n - 1) {
cin >> tmp;
a[i].pb(tmp);
}
}
ans = 1;
queue<ll> q;
FOR(i, 1, n + 1) q.push(i);
while (!q.empty()) {
ll cur = q.front();
q.pop();
ll to = a[cur][idx[cur]];
if (b[to][cur]) {
idx[cur]++;
if (used[cur] || used[to]) {
ans++;
FOR(i, 1, n + 1) used[i] = false;
}
used[cur] = true;
used[to] = true;
if (idx[cur] < n - 1)
q.push(cur);
if (idx[to] < n - 1)
q.push(to);
} else {
b[cur][to] = true;
idx[cur]++;
}
}
bool ok = true;
FOR(i, 1, n + 1) if (idx[i] != n - 1) ok = false;
if (!ok)
cout << "-1" << endl;
else
cout << ans << endl;
return 0;
}
|
[
"expression.operation.binary.remove"
] | 729,761
| 729,762
|
u215122692
|
cpp
|
p02925
|
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if (test)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 1000;
int N;
vector<pii> nxt[MAX_N + 1][MAX_N + 1];
int cnt[MAX_N + 1][MAX_N + 1];
int vst[MAX_N + 1][MAX_N + 1];
deque<pii> dq;
vector<int> v;
bool chk[MAX_N + 1];
int ans = 1;
int main() {
cin >> N;
for (int i = 1; i <= N; i++) {
int prv;
for (int k = 1; k < N; k++) {
int x;
scanf("%d", &x);
if (k != 1) {
nxt[min(i, prv)][max(i, prv)].pb({min(i, x), max(i, x)});
cnt[min(i, x)][max(i, x)]++;
}
prv = x;
}
}
for (int i = 1; i <= N; i++) {
for (int j = i + 1; j <= N; j++) {
if (cnt[i][j] == 0) {
dq.pb({i, j});
}
}
}
while (!dq.empty()) {
pii now = dq.back();
dq.pop_back();
vst[now.first][now.second] = true;
if (chk[now.first] || chk[now.second]) {
ans++;
while (!v.empty()) {
chk[v.back()] = false;
v.pop_back();
}
}
chk[now.first] = true;
chk[now.second] = true;
v.pb(now.first);
v.pb(now.second);
for (pii p : nxt[now.first][now.second]) {
cnt[p.first][p.second]--;
if (cnt[p.first][p.second] == 0) {
dq.push_back(p);
}
}
}
for (int i = 1; i <= N; i++) {
for (int j = i + 1; j <= N; j++) {
if (!vst[i][j]) {
printf("-1");
}
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if (test)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 1000;
int N;
vector<pii> nxt[MAX_N + 1][MAX_N + 1];
int cnt[MAX_N + 1][MAX_N + 1];
int vst[MAX_N + 1][MAX_N + 1];
deque<pii> dq;
vector<int> v;
bool chk[MAX_N + 1];
int ans = 1;
int main() {
cin >> N;
for (int i = 1; i <= N; i++) {
int prv;
for (int k = 1; k < N; k++) {
int x;
scanf("%d", &x);
if (k != 1) {
nxt[min(i, prv)][max(i, prv)].pb({min(i, x), max(i, x)});
cnt[min(i, x)][max(i, x)]++;
}
prv = x;
}
}
for (int i = 1; i <= N; i++) {
for (int j = i + 1; j <= N; j++) {
if (cnt[i][j] == 0) {
dq.pb({i, j});
}
}
}
while (!dq.empty()) {
pii now = dq.front();
dq.pop_front();
vst[now.first][now.second] = true;
if (chk[now.first] || chk[now.second]) {
ans++;
while (!v.empty()) {
chk[v.back()] = false;
v.pop_back();
}
}
chk[now.first] = true;
chk[now.second] = true;
v.pb(now.first);
v.pb(now.second);
for (pii p : nxt[now.first][now.second]) {
cnt[p.first][p.second]--;
if (cnt[p.first][p.second] == 0) {
dq.push_back(p);
}
}
}
for (int i = 1; i <= N; i++) {
for (int j = i + 1; j <= N; j++) {
if (!vst[i][j]) {
printf("-1");
return 0;
}
}
}
cout << ans;
return 0;
}
|
[
"call.function.change",
"control_flow.return.add",
"control_flow.return.0.add"
] | 729,771
| 729,770
|
u950523274
|
cpp
|
p02925
|
#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <vector>
int main() {
size_t N;
scanf("%zu", &N);
auto enc = [&](size_t i, size_t j) {
if (i > j)
std::swap(i, j);
return i * N + j;
};
std::vector<std::vector<size_t>> g(N * N);
std::vector<size_t> indeg(g.size());
for (size_t i = 0; i < N; ++i) {
std::vector<size_t> h(N - 1);
for (auto &hi : h)
scanf("%zu", &hi), --hi;
for (size_t j = 1; j < h.size(); ++j) {
g[enc(i, h[j - 1])].push_back(enc(i, h[j]));
++indeg[enc(i, h[j])];
}
}
std::vector<int> dp(g.size());
// for (size_t i = 0; i < N; ++i)
// for (size_t j = 0; j < N; ++j)
// if (i != j) dp[enc(i, j)] = inf;
std::queue<size_t> q;
// for (size_t i = 0; i < g.size(); ++i) {
// if (indeg[i] == 0) {
// q.push(i);
// dp[i] = 1;
// }
// }
for (size_t i = 0; i < N; ++i)
for (size_t j = 0; j < i; ++j) {
size_t ij = enc(i, j);
if (indeg[ij] == 0) {
q.push(ij);
dp[ij] = 1;
}
}
if (q.empty())
return puts("-1"), 0;
while (!q.empty()) {
size_t v = q.front();
q.pop();
for (size_t w : g[v]) {
dp[w] = std::max(dp[w], dp[v] + 1);
--indeg[w];
if (indeg[w] == 0)
q.push(w);
}
}
if (*std::min_element(indeg.begin(), indeg.end()) > 0)
return puts("-1"), 0;
// for (size_t i = 0; i < N; ++i)
// for (size_t j = 0; j < i; ++j)
// fprintf(stderr, "%zu vs. %zu: %d\n", i, j, dp[enc(i, j)]);
int res = 0;
for (size_t i = 0; i < N; ++i)
for (size_t j = 0; j < i; ++j)
res = std::max(res, dp[enc(i, j)]);
if (res == 0)
return puts("-1"), 0;
printf("%d\n", res);
}
|
#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <vector>
int main() {
size_t N;
scanf("%zu", &N);
auto enc = [&](size_t i, size_t j) {
if (i > j)
std::swap(i, j);
return i * N + j;
};
std::vector<std::vector<size_t>> g(N * N);
std::vector<size_t> indeg(g.size());
for (size_t i = 0; i < N; ++i) {
std::vector<size_t> h(N - 1);
for (auto &hi : h)
scanf("%zu", &hi), --hi;
for (size_t j = 1; j < h.size(); ++j) {
g[enc(i, h[j - 1])].push_back(enc(i, h[j]));
++indeg[enc(i, h[j])];
}
}
std::vector<int> dp(g.size());
// for (size_t i = 0; i < N; ++i)
// for (size_t j = 0; j < N; ++j)
// if (i != j) dp[enc(i, j)] = inf;
std::queue<size_t> q;
// for (size_t i = 0; i < g.size(); ++i) {
// if (indeg[i] == 0) {
// q.push(i);
// dp[i] = 1;
// }
// }
for (size_t i = 0; i < N; ++i)
for (size_t j = 0; j < i; ++j) {
size_t ij = enc(i, j);
if (indeg[ij] == 0) {
q.push(ij);
dp[ij] = 1;
}
}
if (q.empty())
return puts("-1"), 0;
while (!q.empty()) {
size_t v = q.front();
q.pop();
for (size_t w : g[v]) {
dp[w] = std::max(dp[w], dp[v] + 1);
--indeg[w];
if (indeg[w] == 0)
q.push(w);
}
}
if (*std::max_element(indeg.begin(), indeg.end()) > 0)
return puts("-1"), 0;
// for (size_t i = 0; i < N; ++i)
// for (size_t j = 0; j < i; ++j)
// fprintf(stderr, "%zu vs. %zu: %d\n", i, j, dp[enc(i, j)]);
int res = 0;
for (size_t i = 0; i < N; ++i)
for (size_t j = 0; j < i; ++j)
res = std::max(res, dp[enc(i, j)]);
if (res == 0)
return puts("-1"), 0;
printf("%d\n", res);
}
|
[
"identifier.change",
"control_flow.branch.if.condition.change"
] | 729,774
| 729,775
|
u352499693
|
cpp
|
p02925
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n;
int a[N][N];
int idx[N];
bool waiting[N][N];
int main() {
scanf("%d", &n);
vector<int> toCheck;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n - 1; ++j) {
scanf("%d", &a[i][j]);
--a[i][j];
}
idx[i] = 0;
toCheck.push_back(i);
}
int day = 0;
bool can = true;
while (can) {
can = false;
vector<int> ncheck;
for (int u : toCheck) {
int v = a[u][idx[u]];
if (v < u)
swap(u, v);
if (waiting[u][v]) {
can = true;
waiting[u][v] = false;
++idx[u], ++idx[v];
if (idx[u] < n - 1)
ncheck.push_back(u);
if (idx[v] < n - 1)
ncheck.push_back(v);
} else {
waiting[u][v] = true;
}
}
toCheck = ncheck;
++day;
}
for (int i = 0; i < n; ++i) {
if (idx[i] != n - 1)
day = -1;
}
printf("%d\n", day);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n;
int a[N][N];
int idx[N];
bool waiting[N][N];
int main() {
scanf("%d", &n);
vector<int> toCheck;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n - 1; ++j) {
scanf("%d", &a[i][j]);
--a[i][j];
}
idx[i] = 0;
toCheck.push_back(i);
}
int day = 0;
bool can = true;
while (can) {
can = false;
vector<int> ncheck;
for (int u : toCheck) {
int v = a[u][idx[u]];
if (v < u)
swap(u, v);
if (waiting[u][v]) {
can = true;
waiting[u][v] = false;
++idx[u], ++idx[v];
if (idx[u] < n - 1)
ncheck.push_back(u);
if (idx[v] < n - 1)
ncheck.push_back(v);
} else {
waiting[u][v] = true;
}
}
toCheck = ncheck;
if (can)
++day;
}
for (int i = 0; i < n; ++i) {
if (idx[i] != n - 1)
day = -1;
}
printf("%d\n", day);
return 0;
}
|
[
"control_flow.branch.if.add"
] | 729,780
| 729,781
|
u574811687
|
cpp
|
p02925
|
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep3(i, a, b) for (ll i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pq priority_queue<int>
#define pqg priority_queue<int, vector<int>, greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c), end(c)
using namespace std;
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
#define LLINF 1e18 + 7
#define N 250000
ll MOD = 1e9 + 7;
main() {
int n = in();
vector<queue<int>> v;
v.resize(n + 1);
rep(i, n) {
rep(j, n - 1) { v[i + 1].push(in()); }
}
int m = 0;
vec w;
w.resize(n + 1);
rep2(i, 1, n) {
w[i] = v[i].front();
v[i].pop();
}
vector<int> used(n + 1);
while (1) {
m++;
int t = 0, s = 0;
rep2(i, 1, n) {
if (w[i] == -1) {
t++;
continue;
}
if (w[w[i]] == i && !used[i] && !used[w[i]]) {
s++;
used[i] = used[w[i]] = 1;
if (!v[w[i]].empty()) {
w[w[i]] = v[w[i]].front();
v[w[i]].pop();
} else {
w[w[i]] = -1;
}
if (!v[i].empty()) {
w[i] = v[i].front();
v[i].pop();
} else
w[i] = -1;
}
}
used = vector<int>(n + 1);
if (t == n) {
cout << m << endl;
return 0;
}
if (s == 0) {
cout << -1 << endl;
return 0;
}
}
}
|
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep3(i, a, b) for (ll i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pq priority_queue<int>
#define pqg priority_queue<int, vector<int>, greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c), end(c)
using namespace std;
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
#define LLINF 1e18 + 7
#define N 250000
ll MOD = 1e9 + 7;
main() {
int n = in();
vector<queue<int>> v;
v.resize(n + 1);
rep(i, n) {
rep(j, n - 1) { v[i + 1].push(in()); }
}
int m = 0;
vec w;
w.resize(n + 1);
rep2(i, 1, n) {
w[i] = v[i].front();
v[i].pop();
}
vector<int> used(n + 1);
while (1) {
m++;
int t = 0, s = 0;
rep2(i, 1, n) {
if (w[i] == -1) {
t++;
continue;
}
if (w[w[i]] == i && !used[i] && !used[w[i]]) {
s++;
used[i] = used[w[i]] = 1;
if (!v[w[i]].empty()) {
w[w[i]] = v[w[i]].front();
v[w[i]].pop();
} else {
w[w[i]] = -1;
}
if (!v[i].empty()) {
w[i] = v[i].front();
v[i].pop();
} else
w[i] = -1;
}
}
// rep2(i,1,n)cout<<w[i]<<" ";
// cout<<endl;
used = vector<int>(n + 1);
if (t == n) {
cout << m - 1 << endl;
return 0;
}
if (s == 0) {
cout << -1 << endl;
return 0;
}
}
}
|
[
"expression.operation.binary.add"
] | 729,784
| 729,785
|
u495699318
|
cpp
|
p02926
|
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n) \
do { \
ostringstream os; \
os << setw(n) << setfill('0') << s; \
s = os.str(); \
} while (0);
#define UNIQUE(v) \
v.erase(unique(v.begin(), v.end()), v.end()) // sortしてからつかうこと
#define INIT \
std::cin.tie(nullptr); \
std::ios_base::sync_with_stdio(false); \
cout << std::fixed << std::setprecision(15);
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pi = pair<int, int>;
template <typename T> using Pq = priority_queue<T>;
template <typename T> using pQ = priority_queue<T, vector<T>, greater<T>>;
template <typename T> vector<T> make_vec(size_t a, T n) {
return vector<T>(a, n);
}
template <typename T, typename... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
class Args {
private:
int upperSize = 0;
public:
vector<pair<int, int>> pts;
vector<pair<int, int>> rotPts;
Args() = default;
void add(int x, int y) { pts.push_back({x, y}); }
void sort() {
int n = pts.size();
vector<pair<int, int>> upper, lower;
for (int i = 0; i < n; i++) {
if (pts[i].second == 0) {
if (pts[i].first > 0) {
upper.push_back(pts[i]);
} else {
lower.push_back(pts[i]);
}
} else if (pts[i].second > 0) {
upper.push_back(pts[i]);
} else {
lower.push_back(pts[i]);
}
}
upperSize = upper.size();
auto comp = [&](pair<int, int> l, pair<int, int> r) -> bool {
return (l.first * r.second - r.first * l.second > 0);
};
std::sort(upper.begin(), upper.end(), comp);
std::sort(lower.begin(), lower.end(), comp);
copy(upper.begin(), upper.end(), pts.begin());
copy(lower.begin(), lower.end(), pts.begin() + upper.size());
rotPts.resize(n);
copy(lower.begin(), lower.end(), rotPts.begin());
copy(upper.begin(), upper.end(), rotPts.begin() + lower.size());
}
//[0, 2N)の値を返す、インデックスを使うときは%Nすること
int binary_search180(int index, bool isLowerBound = 1) {
auto f = [&](vector<pair<int, int>> &v) {
int ok = v.size();
int ng = index;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
int cross =
v[index].first * v[mid].second - v[mid].first * v[index].second;
int dot =
v[mid].first * v[index].first + v[mid].second * v[index].second;
if (cross == 0 && dot > 0) {
ng = mid;
} else if (cross + !isLowerBound <= 0) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
};
if (pts[index].second < 0 ||
(pts[index].second == 0 && pts[index].first < 0)) {
index -= upperSize;
return f(rotPts) + upperSize;
} else {
return f(pts);
}
}
//[0, 2N)の値を返す、インデックスを使うときは%Nすること
int binary_search90(int index, bool isLowerBound = 1) {
auto f = [&](vector<pair<int, int>> &v, int bordor180) {
int ok = bordor180;
int ng = index;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
int dot =
v[mid].first * v[index].first + v[mid].second * v[index].second;
if (dot + !isLowerBound <= 0) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
};
if (pts[index].second < 0 ||
(pts[index].second == 0 && pts[index].first < 0)) {
int bordor180 = binary_search180(index) - upperSize;
index -= upperSize;
return f(rotPts, bordor180) + upperSize;
} else {
return f(pts, binary_search180(index));
}
}
};
signed main() {
INIT;
cin >> N;
vector<int> x(N), y(N);
REP(i, N)
cin >> x[i] >> y[i];
Args args;
REP(i, N) {
if (x[i] == 0 && y[i] == 0)
continue;
args.add(x[i], y[i]);
}
N = args.pts.size();
args.sort();
double ans = 0;
REP(i, N) {
int j = args.binary_search180(i);
auto a = args.pts[i];
auto b = args.pts[(j - 1) % N];
// dump(i, j, c, d);
ll x = 0, y = 0;
REP(j, N) {
auto [vx, vy] = args.pts[(i + j) % N];
x += vx;
y += vy;
}
chmax(ans, sqrt(x * x + y * y));
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n) \
do { \
ostringstream os; \
os << setw(n) << setfill('0') << s; \
s = os.str(); \
} while (0);
#define UNIQUE(v) \
v.erase(unique(v.begin(), v.end()), v.end()) // sortしてからつかうこと
#define INIT \
std::cin.tie(nullptr); \
std::ios_base::sync_with_stdio(false); \
cout << std::fixed << std::setprecision(15);
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pi = pair<int, int>;
template <typename T> using Pq = priority_queue<T>;
template <typename T> using pQ = priority_queue<T, vector<T>, greater<T>>;
template <typename T> vector<T> make_vec(size_t a, T n) {
return vector<T>(a, n);
}
template <typename T, typename... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
class Args {
private:
int upperSize = 0;
public:
vector<pair<int, int>> pts;
vector<pair<int, int>> rotPts;
Args() = default;
void add(int x, int y) { pts.push_back({x, y}); }
void sort() {
int n = pts.size();
vector<pair<int, int>> upper, lower;
for (int i = 0; i < n; i++) {
if (pts[i].second == 0) {
if (pts[i].first > 0) {
upper.push_back(pts[i]);
} else {
lower.push_back(pts[i]);
}
} else if (pts[i].second > 0) {
upper.push_back(pts[i]);
} else {
lower.push_back(pts[i]);
}
}
upperSize = upper.size();
auto comp = [&](pair<int, int> l, pair<int, int> r) -> bool {
return (l.first * r.second - r.first * l.second > 0);
};
std::sort(upper.begin(), upper.end(), comp);
std::sort(lower.begin(), lower.end(), comp);
copy(upper.begin(), upper.end(), pts.begin());
copy(lower.begin(), lower.end(), pts.begin() + upper.size());
rotPts.resize(n);
copy(lower.begin(), lower.end(), rotPts.begin());
copy(upper.begin(), upper.end(), rotPts.begin() + lower.size());
}
//[0, 2N)の値を返す、インデックスを使うときは%Nすること
int binary_search180(int index, bool isLowerBound = 1) {
auto f = [&](vector<pair<int, int>> &v) {
int ok = v.size();
int ng = index;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
int cross =
v[index].first * v[mid].second - v[mid].first * v[index].second;
int dot =
v[mid].first * v[index].first + v[mid].second * v[index].second;
if (cross == 0 && dot > 0) {
ng = mid;
} else if (cross + !isLowerBound <= 0) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
};
if (pts[index].second < 0 ||
(pts[index].second == 0 && pts[index].first < 0)) {
index -= upperSize;
return f(rotPts) + upperSize;
} else {
return f(pts);
}
}
//[0, 2N)の値を返す、インデックスを使うときは%Nすること
int binary_search90(int index, bool isLowerBound = 1) {
auto f = [&](vector<pair<int, int>> &v, int bordor180) {
int ok = bordor180;
int ng = index;
while (abs(ok - ng) > 1) {
int mid = (ok + ng) / 2;
int dot =
v[mid].first * v[index].first + v[mid].second * v[index].second;
if (dot + !isLowerBound <= 0) {
ok = mid;
} else {
ng = mid;
}
}
return ok;
};
if (pts[index].second < 0 ||
(pts[index].second == 0 && pts[index].first < 0)) {
int bordor180 = binary_search180(index) - upperSize;
index -= upperSize;
return f(rotPts, bordor180) + upperSize;
} else {
return f(pts, binary_search180(index));
}
}
};
signed main() {
INIT;
cin >> N;
vector<int> x(N), y(N);
REP(i, N)
cin >> x[i] >> y[i];
Args args;
REP(i, N) {
if (x[i] == 0 && y[i] == 0)
continue;
args.add(x[i], y[i]);
}
N = args.pts.size();
args.sort();
double ans = 0;
REP(i, N) {
int j = args.binary_search180(i);
auto a = args.pts[i];
auto b = args.pts[(j - 1) % N];
// dump(i, j, c, d);
ll x = 0, y = 0;
REP(j, N) {
auto [vx, vy] = args.pts[(i + j) % N];
x += vx;
y += vy;
chmax(ans, sqrt(x * x + y * y));
}
}
cout << ans << endl;
}
|
[] | 729,786
| 729,787
|
u030090262
|
cpp
|
p02926
|
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdint.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;
// BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree,
// chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu,
// topologicalsort, kyourenketuseibun
#define REP(i, a, b) for (ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")
#define MINS(a, b) a = min(a, (decltype(a))(b))
#define MAXS(a, b) a = max(a, (decltype(a))(b))
int main() {
ll N;
cin >> N;
vector<pair<ll, ll>> P(N);
REP(i, 0, N) { cin >> P[i].first >> P[i].second; }
sort(P.begin(), P.end(), [](const pair<ll, ll> &a, const pair<ll, ll> &b) {
return atan2l(a.second, a.first) < atan2(b.second, b.first);
});
ldb ans = 0;
REP(i, 0, N) {
REP(j, i, i + N) {
pair<ll, ll> p = {0, 0};
REP(k, i, j + 1) {
p.first += P[k % N].first;
p.second += P[k % N].second;
}
MAXS(ans, sqrtl(p.first * p.first + p.second * p.second));
}
}
printf("%.11f\n", ans);
return 0;
}
|
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdint.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;
// BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree,
// chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu,
// topologicalsort, kyourenketuseibun
#define REP(i, a, b) for (ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")
#define MINS(a, b) a = min(a, (decltype(a))(b))
#define MAXS(a, b) a = max(a, (decltype(a))(b))
int main() {
ll N;
cin >> N;
vector<pair<ll, ll>> P(N);
REP(i, 0, N) { cin >> P[i].first >> P[i].second; }
sort(P.begin(), P.end(), [](const pair<ll, ll> &a, const pair<ll, ll> &b) {
return atan2l(a.second, a.first) < atan2l(b.second, b.first);
});
ldb ans = 0;
REP(i, 0, N) {
REP(j, i, i + N) {
pair<ll, ll> p = {0, 0};
REP(k, i, j + 1) {
p.first += P[k % N].first;
p.second += P[k % N].second;
}
MAXS(ans, sqrtl(p.first * p.first + p.second * p.second));
}
}
printf("%.11Lf\n", ans);
return 0;
}
|
[
"identifier.change",
"call.function.change",
"call.arguments.change",
"function.return_value.change",
"expression.operation.binary.change",
"literal.string.change",
"io.output.change"
] | 729,790
| 729,789
|
u539145601
|
cpp
|
p02926
|
#include <bits/stdc++.h>
using namespace std;
using pll = pair<long long, long long>;
const long double pi = atan2l(0, -1);
int N;
pair<long long, long long> operator+(pair<long long, long long> &a,
pair<long long, long long> &b) {
return make_pair(a.first + b.first, a.second + b.second);
}
int main() {
cin >> N;
vector<pll> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i].first >> A[i].second;
}
vector<pair<long double, int>> arg(2 * N);
for (int i = 0; i < N; i++) {
arg[i] = make_pair(atan2(A[i].second, A[i].first), i);
arg[i + N] = make_pair(atan2(A[i].second, A[i].first) + 2 * pi, i);
}
sort(arg.begin(), arg.end());
long double ans = 0;
for (int i = 0; i < N; i++) {
int j = i;
pair<long long, long long> X =
make_pair(A[arg[i].second].first, A[arg[i].second].second);
while (
((X.first + A[arg[j + 1].second].first) * A[arg[j + 1].second].first +
(X.second + A[arg[j + 1].second].second) *
A[arg[j + 1].second].second >=
-1 * X.first * A[arg[j + 1].second].first -
X.second * A[arg[j + 1].second].second &&
arg[j + 1].first - atan2(X.second, X.first) < pi) &&
X.first * A[arg[j + 1].second].first +
X.second * A[arg[j + 1].second].second >=
0 &&
j + 1 < i + N) {
j++;
X = X + A[arg[j].second];
}
long long x = 0LL, y = 0LL;
for (int k = i; k <= j; k++) {
x += A[arg[k].second].first;
y += A[arg[k].second].second;
}
long double d = sqrt(x * x + y * y);
ans = max(ans, d);
}
cout << setprecision(20) << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using pll = pair<long long, long long>;
const long double pi = atan2l(0, -1);
int N;
pair<long long, long long> operator+(pair<long long, long long> &a,
pair<long long, long long> &b) {
return make_pair(a.first + b.first, a.second + b.second);
}
int main() {
cin >> N;
vector<pll> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i].first >> A[i].second;
}
vector<pair<long double, int>> arg(2 * N);
for (int i = 0; i < N; i++) {
arg[i] = make_pair(atan2(A[i].second, A[i].first), i);
arg[i + N] = make_pair(atan2(A[i].second, A[i].first) + 2 * pi, i);
}
sort(arg.begin(), arg.end());
long double ans = 0;
for (int i = 0; i < N; i++) {
int j = i;
pair<long long, long long> X =
make_pair(A[arg[i].second].first, A[arg[i].second].second);
while (
((X.first + A[arg[j + 1].second].first) * A[arg[j + 1].second].first +
(X.second + A[arg[j + 1].second].second) *
A[arg[j + 1].second].second >=
-1 * X.first * A[arg[j + 1].second].first -
X.second * A[arg[j + 1].second].second &&
arg[j + 1].first - atan2(X.second, X.first) < pi) ||
X.first * A[arg[j + 1].second].first +
X.second * A[arg[j + 1].second].second >=
0 &&
j + 1 < i + N) {
j++;
X = X + A[arg[j].second];
}
long long x = 0LL, y = 0LL;
for (int k = i; k <= j; k++) {
x += A[arg[k].second].first;
y += A[arg[k].second].second;
}
long double d = sqrt(x * x + y * y);
ans = max(ans, d);
}
cout << setprecision(20) << ans << endl;
}
|
[
"misc.opposites",
"control_flow.loop.condition.change"
] | 729,794
| 729,795
|
u844382784
|
cpp
|
p02926
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
struct V {
double x, y;
V(double x = 0, double y = 0) : x(x), y(y) {}
V &operator+=(const V &v) {
x += v.x;
y += v.y;
return *this;
}
double dot(const V &v) const { return x * v.x + y * v.x; }
double cross(const V &v) const { return x * v.y - v.x * y; }
int ort() const {
if (y > 0)
return x > 0 ? 1 : 2;
else
return x < 0 ? 4 : 3;
}
bool operator<(const V &v) const {
int o = ort(), vo = v.ort();
if (o != vo)
return o < vo;
return cross(v) > 0;
}
double norm2() const { return x * x + y * y; }
double norm() const { return sqrt(norm2()); }
V &operator+(const V &v) const { return V(*this) += v; }
};
istream &operator>>(istream &i, V &v) {
i >> v.x >> v.y;
return i;
}
ostream &operator>>(ostream &o, const V &v) {
o << "(" << v.x << "," << v.y << ")";
return o;
}
int main() {
int n;
cin >> n;
vector<V> v(n);
rep(i, n) { cin >> v[i]; }
sort(v.begin(), v.end());
double ans = 0;
rep(l, n) {
int r = l;
V now;
rep(i, n) {
now += v[r];
ans = max(ans, now.norm());
r = (r + 1) % n;
}
}
printf("%.12f\n", ans);
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
struct V {
double x, y;
V(double x = 0, double y = 0) : x(x), y(y) {}
V &operator+=(const V &v) {
x += v.x;
y += v.y;
return *this;
}
double dot(const V &v) const { return x * v.x + y * v.x; }
double cross(const V &v) const { return x * v.y - v.x * y; }
int ort() const {
if (y > 0)
return x > 0 ? 1 : 2;
else
return x > 0 ? 4 : 3;
}
bool operator<(const V &v) const {
int o = ort(), vo = v.ort();
if (o != vo)
return o < vo;
return cross(v) > 0;
}
double norm2() const { return x * x + y * y; }
double norm() const { return sqrt(norm2()); }
V &operator+(const V &v) const { return V(*this) += v; }
};
istream &operator>>(istream &i, V &v) {
i >> v.x >> v.y;
return i;
}
ostream &operator>>(ostream &o, const V &v) {
o << "(" << v.x << "," << v.y << ")";
return o;
}
int main() {
int n;
cin >> n;
vector<V> v(n);
rep(i, n) { cin >> v[i]; }
sort(v.begin(), v.end());
double ans = 0;
rep(l, n) {
int r = l;
V now;
rep(i, n) {
now += v[r];
ans = max(ans, now.norm());
r = (r + 1) % n;
}
}
printf("%.12f\n", ans);
}
|
[
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 729,805
| 729,806
|
u564182781
|
cpp
|
p02926
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9 + 7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template <typename T> T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
double atan(int a, int b) {
if (a == 0)
return (b > 0 ? M_PI / 2 : -M_PI / 2);
if (b == 0 && a < 0)
return M_PI;
if (a < 0 && b < 0)
return atan((double)b / a) - M_PI;
if (a < 0 && b > 0)
return atan((double)b / a) + M_PI;
return atan((double)b / a);
}
bool comp(pii a, pii b) { return atan(a.F, a.S) < atan(b.F, b.S); }
int main() {
int n;
cin >> n;
vector<pii> v;
rep(i, n) {
int x, y;
cin >> x >> y;
if (x == 0 && y == 0)
continue;
v.eb(pii(x, y));
}
double ans = 0;
sort(all(v), comp);
// cout << '\n'; rep(i, sz(v)) cout << v[i].F << " " << v[i].S << " " <<
// atan(v[i].F, v[i].S) << '\n';
rep(i, sz(v)) rep3(j, i, sz(v)) {
int x = 0, y = 0;
rep3(k, i, j + 1) {
x += v[k].F;
y += v[k].S;
}
chmax(ans, sqrt((double)x * x + (double)y * y));
}
// 逆方向に延ばす
rep(i, sz(v)) {
int x = 0, y = 0;
rep(j, sz(v)) {
int k = (i - j + sz(v)) % sz(v);
x += v[k].F;
y += v[k].S;
}
chmax(ans, sqrt((double)x * x + (double)y * y));
}
cout << fixed << setprecision(11) << ans << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9 + 7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template <typename T> T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
double atan(int a, int b) {
if (a == 0)
return (b > 0 ? M_PI / 2 : -M_PI / 2);
if (b == 0 && a < 0)
return M_PI;
if (a < 0 && b < 0)
return atan((double)b / a) - M_PI;
if (a < 0 && b > 0)
return atan((double)b / a) + M_PI;
return atan((double)b / a);
}
bool comp(pii a, pii b) { return atan(a.F, a.S) < atan(b.F, b.S); }
int main() {
int n;
cin >> n;
vector<pii> v;
rep(i, n) {
int x, y;
cin >> x >> y;
if (x == 0 && y == 0)
continue;
v.eb(pii(x, y));
}
double ans = 0;
sort(all(v), comp);
// cout << '\n'; rep(i, sz(v)) cout << v[i].F << " " << v[i].S << " " <<
// atan(v[i].F, v[i].S) << '\n';
rep(i, sz(v)) rep3(j, i, sz(v)) {
int x = 0, y = 0;
rep3(k, i, j + 1) {
x += v[k].F;
y += v[k].S;
}
chmax(ans, sqrt((double)x * x + (double)y * y));
}
// 逆方向に延ばす
rep(i, sz(v)) {
int x = 0, y = 0;
rep(j, sz(v)) {
int k = (i - j + sz(v)) % sz(v);
x += v[k].F;
y += v[k].S;
chmax(ans, sqrt((double)x * x + (double)y * y));
}
}
cout << fixed << setprecision(11) << ans << '\n';
}
|
[] | 729,814
| 729,815
|
u277556971
|
cpp
|
p02926
|
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <queue>
#include <tuple>
template <typename T> void fin(T const &t) {
std::cout << t << std::endl;
exit(0);
}
struct vec {
int64_t x, y;
vec() : x(0), y(0) {}
vec(int64_t x, int64_t y) : x(x), y(y) {}
vec operator+(vec const &v) const { return vec(x + v.x, y + v.y); }
vec operator-(vec const &v) const { return vec(x - v.x, y - v.y); }
bool operator==(vec const &v) const {
return x * v.y == y * v.x && x * v.x >= 0 && y * v.y >= 0;
}
bool operator<(vec const &v) const {
if (*this == v)
return false;
if (y > 0 && v.y > 0) {
if ((x > 0 && v.x > 0) || (x < 0 && v.x < 0))
return y * v.x < x * v.y;
if (x <= 0 && v.x >= 0)
return false;
return true;
} else if (y < 0 && v.y < 0) {
if ((x < 0 && v.x < 0) || (x > 0 && v.x > 0))
return y * v.x < x * v.y;
if (x >= 0 && v.x <= 0)
return false;
return true;
} else if (y > 0 && v.y < 0)
return true;
if (y < 0 && v.y > 0)
return false;
if (y == 0 && x > 0 && (v.y != 0 || (v.y == 0 && v.x < 0)))
return true;
if (y == 0 && x < 0 && v.y < 0)
return true;
if (v.y == 0 && v.x < 0 && y > 0)
return true;
return false;
}
friend std::ostream &operator<<(std::ostream &os, const vec &v) {
return os << "[" << v.x << "," << v.y << "]";
}
};
int const MAXN = 100;
vec p[MAXN * 2];
int N;
int main() {
std::cout << std::setprecision(15) << std::fixed;
std::cin >> N;
int j = 0;
for (int i = 0; i < N; ++i) {
int x, y;
std::cin >> x >> y;
if (x == 0 && y == 0)
continue;
p[j++] = vec(0, 0);
}
N = j;
if (N < 1)
fin(0.0);
std::sort(p, p + N);
for (int i = 0; i < N; ++i)
p[i + N] = p[i];
int64_t sum2 = 0, ans2 = 0;
vec sum;
j = 0;
for (int i = 0; i < N; ++i) {
while (j < i + N) {
vec nv = sum + p[j];
int64_t n2 = nv.x * nv.x + nv.y * nv.y;
if (n2 <= sum2)
break;
sum = nv;
sum2 = n2;
ans2 = std::max(ans2, sum2);
++j;
}
sum = sum - p[i];
sum2 = sum.x * sum.x + sum.y * sum.y;
ans2 = std::max(ans2, sum2);
}
fin(std::sqrt((double)ans2));
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <queue>
#include <tuple>
template <typename T> void fin(T const &t) {
std::cout << t << std::endl;
exit(0);
}
struct vec {
int64_t x, y;
vec() : x(0), y(0) {}
vec(int64_t x, int64_t y) : x(x), y(y) {}
vec operator+(vec const &v) const { return vec(x + v.x, y + v.y); }
vec operator-(vec const &v) const { return vec(x - v.x, y - v.y); }
bool operator==(vec const &v) const {
return x * v.y == y * v.x && x * v.x >= 0 && y * v.y >= 0;
}
bool operator<(vec const &v) const {
if (*this == v)
return false;
if (y > 0 && v.y > 0) {
if ((x > 0 && v.x > 0) || (x < 0 && v.x < 0))
return y * v.x < x * v.y;
if (x <= 0 && v.x >= 0)
return false;
return true;
} else if (y < 0 && v.y < 0) {
if ((x < 0 && v.x < 0) || (x > 0 && v.x > 0))
return y * v.x < x * v.y;
if (x >= 0 && v.x <= 0)
return false;
return true;
} else if (y > 0 && v.y < 0)
return true;
if (y < 0 && v.y > 0)
return false;
if (y == 0 && x > 0 && (v.y != 0 || (v.y == 0 && v.x < 0)))
return true;
if (y == 0 && x < 0 && v.y < 0)
return true;
if (v.y == 0 && v.x < 0 && y > 0)
return true;
return false;
}
friend std::ostream &operator<<(std::ostream &os, const vec &v) {
return os << "[" << v.x << "," << v.y << "]";
}
};
int const MAXN = 100;
vec p[MAXN * 2];
int N;
int main() {
std::cout << std::setprecision(15) << std::fixed;
std::cin >> N;
int j = 0;
for (int i = 0; i < N; ++i) {
int x, y;
std::cin >> x >> y;
if (x == 0 && y == 0)
continue;
p[j++] = vec(x, y);
}
N = j;
if (N < 1)
fin(0.0);
std::sort(p, p + N);
for (int i = 0; i < N; ++i)
p[i + N] = p[i];
int64_t sum2 = 0, ans2 = 0;
vec sum;
j = 0;
for (int i = 0; i < N; ++i) {
while (j < i + N) {
vec nv = sum + p[j];
int64_t n2 = nv.x * nv.x + nv.y * nv.y;
if (n2 <= sum2)
break;
sum = nv;
sum2 = n2;
ans2 = std::max(ans2, sum2);
++j;
}
sum = sum - p[i];
sum2 = sum.x * sum.x + sum.y * sum.y;
ans2 = std::max(ans2, sum2);
}
fin(std::sqrt((double)ans2));
return 0;
}
|
[
"assignment.value.change",
"identifier.replace.add",
"literal.replace.remove",
"call.arguments.change"
] | 729,849
| 729,850
|
u294638337
|
cpp
|
p02926
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 203;
int n;
struct pt {
ll x = 0, y = 0;
pt operator+(const pt &p) const {
pt res;
res.x = x + p.x;
res.y = y + p.y;
return res;
}
pt operator-(const pt &p) const {
pt res;
res.x = x - p.x;
res.y = y - p.y;
return res;
}
ll operator*(const pt &p) const { return x * p.y - y * p.x; }
bool half() {
pt p = *this;
return p.y > 0 || (p.y == 0 && p.x < 0);
}
bool operator<(pt b) const {
pt a = *this;
if (a.half() == b.half()) {
return a * b > 0;
}
return a.half() < b.half();
}
};
pt p[N];
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
cin >> n;
vector<pii> vec;
pii t;
for (int i = 1; i <= n; i++) {
cin >> t.F >> t.S;
if (t.F > 0 || t.S > 0) {
vec.pb(t);
}
}
if (vec.empty()) {
cout << 0;
return 0;
}
n = vec.size();
for (int i = 1; i <= n; i++) {
p[i].x = vec[i - 1].F;
p[i].y = vec[i - 1].S;
}
sort(p + 1, p + n + 1);
for (int i = 1; i <= n; i++) {
p[n + i] = p[i];
}
n *= 2;
db ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
if (j - i + 1 > n / 2) {
continue;
}
pt tmp;
for (int k = i; k <= j; k++) {
tmp = tmp + p[k];
}
ans = max(ans, (db)tmp.x * tmp.x + (db)tmp.y * tmp.y);
}
}
cout << setprecision(50) << sqrtl(ans);
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 203;
int n;
struct pt {
ll x = 0, y = 0;
pt operator+(const pt &p) const {
pt res;
res.x = x + p.x;
res.y = y + p.y;
return res;
}
pt operator-(const pt &p) const {
pt res;
res.x = x - p.x;
res.y = y - p.y;
return res;
}
ll operator*(const pt &p) const { return x * p.y - y * p.x; }
bool half() {
pt p = *this;
return p.y > 0 || (p.y == 0 && p.x < 0);
}
bool operator<(pt b) const {
pt a = *this;
if (a.half() == b.half()) {
return a * b > 0;
}
return a.half() < b.half();
}
};
pt p[N];
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
cin >> n;
vector<pii> vec;
pii t;
for (int i = 1; i <= n; i++) {
cin >> t.F >> t.S;
if (t.F != 0 || t.S != 0) {
vec.pb(t);
}
}
if (vec.empty()) {
cout << 0;
return 0;
}
n = vec.size();
for (int i = 1; i <= n; i++) {
p[i].x = vec[i - 1].F;
p[i].y = vec[i - 1].S;
}
sort(p + 1, p + n + 1);
for (int i = 1; i <= n; i++) {
p[n + i] = p[i];
}
n *= 2;
db ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
if (j - i + 1 > n / 2) {
continue;
}
pt tmp;
for (int k = i; k <= j; k++) {
tmp = tmp + p[k];
}
ans = max(ans, (db)tmp.x * tmp.x + (db)tmp.y * tmp.y);
}
}
cout << setprecision(50) << sqrtl(ans);
}
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 729,853
| 729,854
|
u322084037
|
cpp
|
p02926
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.begin(), v.end(), greater<long long>());
#define ALL(X) (X).begin(), (X).end()
#define INF 99999999
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#ifdef __LOCAL
#define DBG(X) cout << #X << " = " << (X) << endl;
#define SAY(X) cout << (X) << endl;
#else
#define DBG(X)
#define SAY(X)
#endif
#ifdef __LOCAL
#include <filesystem>
namespace fs = std::filesystem;
#endif
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int dx[] = {1, 0, -1, 0, 0};
int dy[] = {0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
std::string pad(int num) {
char buffer[4];
std::snprintf(buffer, sizeof(buffer), "%03d", num);
return buffer;
}
inline ll randint(ll a, ll b) {
ll w = (_g() << 31LL) ^ _g();
return a + w % (b - a + 1);
}
inline void fast_io() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
};
template <typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template <typename T, typename S>
inline ostream &operator<<(ostream &os, const pair<T, S> p) {
cout << "[" << p.first << ";" << p.second << "]";
return os;
}
template <typename T, typename S>
inline ostream &operator<<(ostream &os, const map<T, S> p) {
for (auto el : p)
os << "[" << el.first << " " << el.second << "]";
return os;
}
template <typename T>
inline ostream &operator<<(ostream &os, const vector<T> &v) {
for (auto el : v)
os << el << " ";
return os;
}
template <typename T> inline T fetch() {
T ret;
cin >> ret;
return ret;
}
template <typename T> inline vector<T> fetch_vec(int sz) {
vector<T> ret(sz);
for (auto &elem : ret)
cin >> elem;
return ret;
}
struct point {
double x, y;
complex<double> z;
double theta;
point(double x = 0, double y = 0) : x(x), y(y) {
complex<double> w(x, y);
z = w;
calc_theta();
}
void calc_theta() { theta = arg(z); }
double dist() { return sqrt(x * x + y * y); }
double dist2() { return (x * x + y * y); }
point operator+=(const point &a) {
x += a.x;
y += a.y;
return *this;
}
};
int N;
vector<point> X;
void input() {
fast_io();
#ifdef __LOCAL
fs::path p = __FILE__;
fs::path input, output;
input = output = p.parent_path();
input += string("/input/") + string(p.stem()) + string(".txt");
output += string("/output/") + string(p.stem()) + string(".txt");
freopen(input.c_str(), "r", stdin);
freopen(output.c_str(), "w", stdout);
#endif
cin >> N;
for (int i = 0; i < N; i++) {
int x, y;
cin >> x >> y;
X.emplace_back(x, y);
}
}
double diff_theta(double a, double b) {
if (a * b >= 0)
return abs(a - b);
else {
if (b < 0)
swap(a, b);
return min(b - a, 2 * M_PI - b + a);
}
}
double eps = 1e-9;
void solve() {
double ans = 0;
auto cmp = [&](point a, point b) { return a.theta < b.theta; };
sort(X.begin(), X.end(), cmp);
for (int i = 0; i < N; i++) {
point z;
for (int j = i; j < 2 * N; j++) {
point tmp = z;
tmp += X[j];
if (tmp.dist2() >= z.dist2())
z = tmp;
else
break;
if (j == N + i - 1)
break;
}
ans = max(ans, z.dist2());
}
// for (int i = -180000; i <= 180000; i++)
// {
// double arg = (double)i/360000*M_PI;
// point po;
// for(auto p:X) {
// if(diff_theta(arg,p.theta)<M_PI_2-eps) {po+=p;}
// }
// ans = max(ans,po.dist2());
// }
cout << setprecision(12) << sqrt(ans) << endl;
}
int main() {
input();
solve();
return 0;
}
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.begin(), v.end(), greater<long long>());
#define ALL(X) (X).begin(), (X).end()
#define INF 99999999
#define M_PI 3.14159265358979323846
#define MOD 1000000007
#ifdef __LOCAL
#define DBG(X) cout << #X << " = " << (X) << endl;
#define SAY(X) cout << (X) << endl;
#else
#define DBG(X)
#define SAY(X)
#endif
#ifdef __LOCAL
#include <filesystem>
namespace fs = std::filesystem;
#endif
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int dx[] = {1, 0, -1, 0, 0};
int dy[] = {0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
std::string pad(int num) {
char buffer[4];
std::snprintf(buffer, sizeof(buffer), "%03d", num);
return buffer;
}
inline ll randint(ll a, ll b) {
ll w = (_g() << 31LL) ^ _g();
return a + w % (b - a + 1);
}
inline void fast_io() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
};
template <typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template <typename T, typename S>
inline ostream &operator<<(ostream &os, const pair<T, S> p) {
cout << "[" << p.first << ";" << p.second << "]";
return os;
}
template <typename T, typename S>
inline ostream &operator<<(ostream &os, const map<T, S> p) {
for (auto el : p)
os << "[" << el.first << " " << el.second << "]";
return os;
}
template <typename T>
inline ostream &operator<<(ostream &os, const vector<T> &v) {
for (auto el : v)
os << el << " ";
return os;
}
template <typename T> inline T fetch() {
T ret;
cin >> ret;
return ret;
}
template <typename T> inline vector<T> fetch_vec(int sz) {
vector<T> ret(sz);
for (auto &elem : ret)
cin >> elem;
return ret;
}
struct point {
double x, y;
complex<double> z;
double theta;
point(double x = 0, double y = 0) : x(x), y(y) {
complex<double> w(x, y);
z = w;
calc_theta();
}
void calc_theta() { theta = arg(z); }
double dist() { return sqrt(x * x + y * y); }
double dist2() { return (x * x + y * y); }
point operator+=(const point &a) {
x += a.x;
y += a.y;
return *this;
}
};
int N;
vector<point> X;
void input() {
fast_io();
#ifdef __LOCAL
fs::path p = __FILE__;
fs::path input, output;
input = output = p.parent_path();
input += string("/input/") + string(p.stem()) + string(".txt");
output += string("/output/") + string(p.stem()) + string(".txt");
freopen(input.c_str(), "r", stdin);
freopen(output.c_str(), "w", stdout);
#endif
cin >> N;
for (int i = 0; i < N; i++) {
int x, y;
cin >> x >> y;
X.emplace_back(x, y);
}
}
double diff_theta(double a, double b) {
if (a * b >= 0)
return abs(a - b);
else {
if (b < 0)
swap(a, b);
return min(b - a, 2 * M_PI - b + a);
}
}
double eps = 1e-9;
void solve() {
double ans = 0;
auto cmp = [&](point a, point b) { return a.theta < b.theta; };
sort(X.begin(), X.end(), cmp);
for (int i = 0; i < N; i++) {
point z;
for (int j = i; j < 2 * N; j++) {
point tmp = z;
tmp += X[j % N];
if (tmp.dist2() >= z.dist2())
z = tmp;
else
break;
if (j == (N + i - 1))
break;
}
ans = max(ans, z.dist2());
}
// for (int i = -180000; i <= 180000; i++)
// {
// double arg = (double)i/360000*M_PI;
// point po;
// for(auto p:X) {
// if(diff_theta(arg,p.theta)<M_PI_2-eps) {po+=p;}
// }
// ans = max(ans,po.dist2());
// }
cout << setprecision(12) << sqrt(ans) << endl;
}
int main() {
input();
solve();
return 0;
}
|
[
"assignment.change",
"control_flow.branch.if.condition.change"
] | 729,865
| 729,866
|
u858670323
|
cpp
|
p02926
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <queue>
#include <vector>
using namespace std;
int main() {
int n;
double x[100], y[100], dis, ans = 0.0, xx, yy, a, b;
const double PI = 3.14159265358979323846;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lf%lf", &x[i], &y[i]);
}
for (double i = 0; i < 1000.0; i++) {
xx = yy = 0.0;
a = cos(PI * i / 1000.0);
b = sin(PI * i / 1000.0);
for (int j = 0; j < n; j++) {
if (a * x[j] + b * y[j] >= 0) {
xx += x[j];
yy += y[j];
}
}
dis = xx * xx + yy * yy;
ans = max(ans, sqrt(dis));
}
printf("%.12f\n", ans);
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <queue>
#include <vector>
using namespace std;
int main() {
int n;
double x[100], y[100], dis, ans = 0.0, xx, yy, a, b;
const double PI = 3.14159265358979323846;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%lf%lf", &x[i], &y[i]);
}
for (double i = 0; i < 100000.0; i++) {
xx = yy = 0.0;
a = cos(PI * i / 1000.0);
b = sin(PI * i / 1000.0);
for (int j = 0; j < n; j++) {
if (a * x[j] + b * y[j] >= 0) {
xx += x[j];
yy += y[j];
}
}
dis = xx * xx + yy * yy;
ans = max(ans, sqrt(dis));
}
printf("%.12f\n", ans);
}
|
[
"literal.number.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 729,881
| 729,882
|
u855429581
|
cpp
|
p02926
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 10;
struct point {
double x, y;
};
bool cmp1(point a, point b) {
if (atan2(a.y, a.x) != atan2(b.y, b.x))
return atan2(a.y, a.x) < atan2(b.y, b.x);
else
return a.x < b.x;
}
point a[maxx];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int x, y;
scanf("%d%d", &x, &y);
a[i] = point{x, y};
}
sort(a + 1, a + 1 + n, cmp1);
for (int i = n + 1; i <= n * 2; i++) {
a[i] = a[i - n];
}
double ans = 0;
for (int i = 1; i <= n; i++) {
double rex = 0, rey = 0;
for (int j = i; j < i + n; j++) {
rex += a[j].x;
rey += a[j].y;
}
ans = max(ans, sqrt(rex * rex + rey * rey));
}
printf("%.15f\n", ans);
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 10;
struct point {
double x, y;
};
bool cmp1(point a, point b) {
if (atan2(a.y, a.x) != atan2(b.y, b.x))
return atan2(a.y, a.x) < atan2(b.y, b.x);
else
return a.x < b.x;
}
point a[maxx];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int x, y;
scanf("%d%d", &x, &y);
a[i] = point{x, y};
}
sort(a + 1, a + 1 + n, cmp1);
for (int i = n + 1; i <= n * 2; i++) {
a[i] = a[i - n];
}
double ans = 0;
for (int i = 1; i <= n; i++) {
double rex = 0, rey = 0;
for (int j = i; j < i + n; j++) {
rex += a[j].x;
rey += a[j].y;
ans = max(ans, sqrt(rex * rex + rey * rey));
}
}
printf("%.15f\n", ans);
}
|
[] | 729,893
| 729,894
|
u128408308
|
cpp
|
p02926
|
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep3(i, a, b) for (ll i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pq priority_queue<int>
#define pqg priority_queue<int, vector<int>, greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c), end(c)
using namespace std;
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
#define LLINF 1e18 + 7
#define N 250000
ll MOD = 1e9 + 7;
main() {
int n = in();
vector<pll> v;
rep(i, n) { v.pb({in(), in()}); }
double M = 100000.0;
double pi = 3.14159265358979;
double m = 2 * pi / M;
double ans = 0;
rep(i, M) {
double t = m * i;
double tmp = 0.0;
rep(j, n) {
double T = cos(t) * v[j].first + sin(t) * v[j].second;
if (T > 0)
tmp += T;
}
ans = max(ans, tmp);
}
printf("%.15f", ans);
}
|
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep3(i, a, b) for (ll i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pq priority_queue<int>
#define pqg priority_queue<int, vector<int>, greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c), end(c)
using namespace std;
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
#define LLINF 1e18 + 7
#define N 250000
ll MOD = 1e9 + 7;
main() {
int n = in();
vector<pll> v;
rep(i, n) { v.pb({in(), in()}); }
double M = 300000.0;
double pi = 3.14159265358979;
double m = 2 * pi / M;
double ans = 0;
rep(i, M) {
double t = m * i;
double tmp = 0.0;
rep(j, n) {
double T = cos(t) * v[j].first + sin(t) * v[j].second;
if (T > 0)
tmp += T;
}
ans = max(ans, tmp);
}
printf("%.15f", ans);
}
|
[
"literal.number.change",
"variable_declaration.value.change"
] | 729,899
| 729,898
|
u495699318
|
cpp
|
p02926
|
#include <bits/stdc++.h>
using namespace std;
template <typename T> struct Pt {
T x, y;
Pt() : x(0), y(0) {}
Pt(const T x, const T y) : x(x), y(y) {}
template <class F> explicit operator Pt<F>() const {
return Pt<F>((F)x, (F)y);
}
Pt operator+(const Pt b) const { return Pt(x + b.x, y + b.y); }
Pt operator-(const Pt b) const { return Pt(x - b.x, y - b.y); }
template <class F> Pt<F> operator*(const F fac) {
return Pt<F>(x * fac, y * fac);
}
template <class F> Pt<F> operator/(const F fac) {
return Pt<F>(x / fac, y / fac);
}
T operator&(const Pt b) const { return x * b.x + y * b.y; }
T operator^(const Pt b) const { return x * b.y - y * b.x; }
bool operator==(const Pt b) const { return x == b.x and y == b.y; }
bool operator<(const Pt b) const {
auto a = *this;
auto sgn = [](const Pt t) { return (t.y == 0 ? t.x : t.y) < 0; };
if (sgn(a) != sgn(b))
return sgn(a) < sgn(b);
return (a ^ b) > 0;
}
Pt operator-() const { return Pt(-x, -y); }
T norm() const { return *this & *this; }
Pt prep() const { return Pt(-y, x); }
};
template <class F> istream &operator>>(istream &is, Pt<F> &pt) {
return is >> pt.x >> pt.y;
}
template <class F> ostream &operator<<(ostream &os, Pt<F> &pt) {
return os << pt.x << ' ' << pt.y;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<Pt<long long>> A;
for (int i = 0; i < n; ++i) {
Pt<long long> b;
cin >> b;
if (not(b == Pt<long long>(0, 0)))
A.push_back(b);
}
n = A.size();
sort(A.begin(), A.end());
long long ans = 0;
for (int i = 0; i < n; ++i) {
Pt<long long> cur;
for (int j = i; j != i + n; ++j) {
cur = cur + A[j];
ans = max(ans, cur.norm());
}
}
cout << fixed << setprecision(20) << sqrt(ans) << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T> struct Pt {
T x, y;
Pt() : x(0), y(0) {}
Pt(const T x, const T y) : x(x), y(y) {}
template <class F> explicit operator Pt<F>() const {
return Pt<F>((F)x, (F)y);
}
Pt operator+(const Pt b) const { return Pt(x + b.x, y + b.y); }
Pt operator-(const Pt b) const { return Pt(x - b.x, y - b.y); }
template <class F> Pt<F> operator*(const F fac) {
return Pt<F>(x * fac, y * fac);
}
template <class F> Pt<F> operator/(const F fac) {
return Pt<F>(x / fac, y / fac);
}
T operator&(const Pt b) const { return x * b.x + y * b.y; }
T operator^(const Pt b) const { return x * b.y - y * b.x; }
bool operator==(const Pt b) const { return x == b.x and y == b.y; }
bool operator<(const Pt b) const {
auto a = *this;
auto sgn = [](const Pt t) { return (t.y == 0 ? t.x : t.y) < 0; };
if (sgn(a) != sgn(b))
return sgn(a) < sgn(b);
return (a ^ b) > 0;
}
Pt operator-() const { return Pt(-x, -y); }
T norm() const { return *this & *this; }
Pt prep() const { return Pt(-y, x); }
};
template <class F> istream &operator>>(istream &is, Pt<F> &pt) {
return is >> pt.x >> pt.y;
}
template <class F> ostream &operator<<(ostream &os, Pt<F> &pt) {
return os << pt.x << ' ' << pt.y;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<Pt<long long>> A;
for (int i = 0; i < n; ++i) {
Pt<long long> b;
cin >> b;
if (not(b == Pt<long long>(0, 0)))
A.push_back(b);
}
n = A.size();
sort(A.begin(), A.end());
long long ans = 0;
for (int i = 0; i < n; ++i) {
Pt<long long> cur;
for (int j = i; j != i + n; ++j) {
cur = cur + A[j % n];
ans = max(ans, cur.norm());
}
}
cout << fixed << setprecision(20) << sqrt(ans) << '\n';
}
|
[
"assignment.change"
] | 729,902
| 729,903
|
u459737327
|
cpp
|
p02926
|
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<long long> X(N), Y(N);
for (int i = 0; i < N; i++)
cin >> X[i] >> Y[i];
long long answer = 0;
for (int r = 0; r < 100; r++) {
for (int i = 0; i < N; i++) {
long long tx = X[i];
long long ty = Y[i];
for (int j = 0; j < N; j++) {
long long sx = 0;
long long sy = 0;
for (int k = 0; k < N; k++)
if (tx * X[k] + ty * Y[k] > 0 ||
tx * X[k] + ty * Y[k] == 0 && rand() % 2 == 0)
sx += X[k], sy += Y[k];
tx = sx;
ty = sy;
}
answer = max(answer, tx * tx + ty * ty);
}
}
printf("%.16f\n", sqrt((double)answer));
}
|
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<long long> X(N), Y(N);
for (int i = 0; i < N; i++)
cin >> X[i] >> Y[i];
long long answer = 0;
for (int r = 0; r < 10; r++) {
for (int i = 0; i < N * 10; i++) {
long long tx = X[i];
long long ty = Y[i];
for (int j = 0; j < N; j++) {
long long sx = 0;
long long sy = 0;
for (int k = 0; k < N; k++)
if (tx * X[k] + ty * Y[k] > 0 ||
tx * X[k] + ty * Y[k] == 0 && rand() % 2 == 0)
sx += X[k], sy += Y[k];
tx = sx;
ty = sy;
}
answer = max(answer, tx * tx + ty * ty);
}
}
printf("%.16f\n", sqrt((double)answer));
}
|
[
"literal.number.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 729,910
| 729,911
|
u374099594
|
cpp
|
p02927
|
#include <cstdio>
#include <iostream>
using namespace std;
int m, d;
int main() {
scanf("%d%d", &m, &d);
int ans = 0;
for (int i = 1; i <= m; i++) {
for (int d10 = 2; d10 <= d / 10; d10++)
if (i % d10 == 0) {
int d1 = i / d10;
if (d1 >= 2 && d10 * 10 + d1 <= d)
ans++;
}
}
printf("%d", ans);
return 0;
}
|
#include <cstdio>
#include <iostream>
using namespace std;
int m, d;
int main() {
scanf("%d%d", &m, &d);
int ans = 0;
for (int i = 1; i <= m; i++) {
for (int d10 = 2; d10 <= d / 10; d10++)
if (i % d10 == 0) {
int d1 = i / d10;
if (d1 >= 2 && d1 <= 9 && d10 * 10 + d1 <= d)
ans++;
}
}
printf("%d", ans);
return 0;
}
|
[
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change"
] | 729,930
| 729,931
|
u648316846
|
cpp
|
p02927
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, d;
cin >> m >> d;
int ans = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= d; j++) {
int d1 = j % 10;
int d10 = j / 10;
if (d1 >= 2 && d10 >= 2 && d1 * d10 == m)
ans++;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, d;
cin >> m >> d;
int ans = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= d; j++) {
int d1 = j % 10;
int d10 = j / 10;
if (d1 >= 2 && d10 >= 2 && d1 * d10 == i)
ans++;
}
}
cout << ans << endl;
}
|
[
"identifier.change",
"control_flow.branch.if.condition.change"
] | 729,932
| 729,933
|
u528258842
|
cpp
|
p02927
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, n) for (ll i = 0; i < (n); i++)
#define For1(i, n) for (ll i = 1; i < (n); i++)
#define MOD 1000000007
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
ll d, m, ans = 0;
cin >> m >> d;
For1(i, m + 1) {
For1(j, d) {
if (j / 10 > 1 && j % 10 > 1 && (j / 10) * (j % 10) == i) {
ans++;
}
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, n) for (ll i = 0; i < (n); i++)
#define For1(i, n) for (ll i = 1; i < (n); i++)
#define MOD 1000000007
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
ll d, m, ans = 0;
cin >> m >> d;
For1(i, m + 1) {
For1(j, d + 1) {
if (j / 10 > 1 && j % 10 > 1 && (j / 10) * (j % 10) == i) {
ans++;
}
}
}
cout << ans << endl;
}
|
[
"expression.operation.binary.add"
] | 729,941
| 729,942
|
u813174766
|
cpp
|
p02927
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int M, D, i = 0;
cin >> M >> D;
for (int m = 4; m <= M; m++)
for (int d10 = 2; d10 * 10 <= D; d10++)
for (int d1 = 2; d10 * 10 + d1 <= D; d1++)
if (m == d1 * d10)
i++;
cout << i << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int M, D, i = 0;
cin >> M >> D;
for (int m = 4; m <= M; m++)
for (int d10 = 2; d10 * 10 <= D; d10++)
for (int d1 = 2; d10 * 10 + d1 <= D && d1 < 10; d1++)
if (m == d1 * d10)
i++;
cout << i << endl;
}
|
[
"control_flow.loop.for.condition.change"
] | 729,951
| 729,952
|
u306482197
|
cpp
|
p02927
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<long long, long long>
#define ff first
#define ss second
#define ld long double
main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int M, D;
cin >> M >> D;
int ans = 0, cnt = 0;
for (int i = 2; i <= D; i++) {
for (int j = 2; j <= D; j++) {
if (i * 10 + j > D || i * j > M)
continue;
ans++;
}
}
cout << ans;
}
|
/*#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<long long, long long>
#define ff first
#define ss second
#define ld long double
main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<long long, long long>
#define ff first
#define ss second
#define ld long double
main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int M, D;
cin >> M >> D;
int ans = 0, cnt = 0;
for (int i = 2; i <= 9; i++) {
for (int j = 2; j <= 9; j++) {
if (i * 10 + j > D || i * j > M)
continue;
ans++;
}
}
cout << ans;
}
|
[
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 729,953
| 729,954
|
u827016215
|
cpp
|
p02927
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int m, d;
cin >> m >> d;
int ans = 0;
if (m == 1 || d < 22)
cout << 0 << endl;
else {
for (int i = 2; i <= m; i++) {
for (int j = 22; j <= d; j++) {
int j1 = j % 10;
int j10 = j / 10;
if (j1 == 1)
continue;
if (j1 * j10 == i)
ans++;
}
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int m, d;
cin >> m >> d;
int ans = 0;
if (m == 1 || d < 22)
cout << 0 << endl;
else {
for (int i = 2; i <= m; i++) {
for (int j = 22; j <= d; j++) {
int j1 = j % 10;
int j10 = j / 10;
if (j1 == 1)
continue;
if (j1 * j10 == i)
ans++;
}
}
cout << ans << endl;
}
}
|
[] | 729,958
| 729,959
|
u021657949
|
cpp
|
p02927
|
// Problem: JSC2019 Qual A
// Progress: Working
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, m, ans = 0;
cin >> n >> m;
for (ll i = 22; i < m; i++)
if (i % 10 >= 2 && (i / 10) >= 2 && i % 10 * (i / 10) <= n)
ans++;
cout << ans;
return 0;
}
|
// Problem: JSC2019 Qual A
// Progress: Working
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, m, ans = 0;
cin >> n >> m;
for (ll i = 22; i <= m; i++)
if (i % 10 >= 2 && (i / 10) >= 2 && i % 10 * (i / 10) <= n)
ans++;
cout << ans;
return 0;
}
|
[
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 729,965
| 729,966
|
u393558821
|
cpp
|
p02927
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main() {
int m, d;
cin >> m >> d;
int ans = 0;
for (int i = 4; i <= m; ++i) {
for (int j = 22; j <= d; ++j) {
if (d % 10 <= 1)
continue;
if (i == (j / 10) * (j % 10))
ans++;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main() {
int m, d;
cin >> m >> d;
int ans = 0;
for (int i = 4; i <= m; ++i) {
for (int j = 22; j <= d; ++j) {
if (j % 10 <= 1)
continue;
if (i == (j / 10) * (j % 10))
ans++;
}
}
cout << ans << endl;
return 0;
}
|
[
"identifier.change",
"control_flow.branch.if.condition.change"
] | 729,971
| 729,972
|
u754114382
|
cpp
|
p02927
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, d;
cin >> m >> d;
int cnt = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= d; j++) {
int d1 = j % 10;
int d10 = j / 10;
if ((d1 >= 2) && (d10 >= 2) && (d1 * 10 == i)) {
cnt++;
}
}
}
cout << cnt << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, d;
cin >> m >> d;
int cnt = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= d; j++) {
int d1 = j % 10;
int d10 = j / 10;
if ((d1 >= 2) && (d10 >= 2) && (d1 * d10 == i)) {
cnt++;
}
}
}
cout << cnt << endl;
return 0;
}
|
[
"identifier.replace.add",
"literal.replace.remove",
"control_flow.branch.if.condition.change"
] | 729,973
| 729,974
|
u729703601
|
cpp
|
p02927
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define P pair<ll, ll>
#define sz(x) (ll) x.size()
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define VE vector<ll>
#define COUT(x) cout << (x) << endl
#define MA map<ll, ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, VE, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define EPS (1e-10)
#define pb push_back
long long MOD = 1000000007;
// long long MOD = 998244353;
const long long INF = 1LL << 60;
const long double PI = acos(-1.0);
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
bool operator==(const mint a) const { return x == a.x; }
bool operator!=(const mint a) const { return x != a.x; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n = 1) : n(n), f(n + 1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i])
continue;
primes.push_back(i);
f[i] = i;
for (ll j = i * i; j <= n; j += i) {
if (!f[j])
f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x; }
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<P> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0)
return {};
vector<P> res(1, P(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
};
template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
bool prime(ll n) {
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return n != 1;
}
map<ll, ll> prime_factor(ll n) {
map<ll, ll> ret;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
vector<pair<char, int>> RunLength(string s) {
if (s.size() == 0)
return {};
vector<pair<char, int>> res(1, pair<char, int>(s[0], 0));
for (char p : s) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
// Digit Count
int GetDigit(int num) { return log10(num) + 1; }
// bit calculation[how many "1"] (= __builtin_popcount())
int bit_count(int n) {
int cnt = 0;
while (n > 0) {
if (n % 2 == 1)
cnt++;
n /= 2;
}
return cnt;
}
vector<long long> enum_divisors(long long N) {
vector<long long> res;
for (long long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
if (N / i != i)
res.push_back(N / i);
}
}
sort(res.begin(), res.end());
return res;
}
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
// struct edge { ll to, cost; };
typedef long double ld;
using Graph = vector<vector<int>>;
class UnionFind {
public:
vector<ll> par; // 各元の親を表す配列
vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)
// Constructor
UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
for (ll i = 0; i < sz_; ++i)
par[i] = i; // 初期では親は自分自身
}
void init(ll sz_) {
par.resize(sz_);
siz.resize(sz_, 1);
for (ll i = 0; i < sz_; ++i)
par[i] = i; // 初期では親は自分自身
}
// Member Function
// Find
ll root(ll x) { // 根の検索
while (par[x] != x) {
x = par[x] = par[par[x]]; // x の親の親を x の親とする
}
return x;
}
// Union(Unite, Merge)
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
// merge technique(データ構造をマージするテク.小を大にくっつける)
if (siz[x] < siz[y])
swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) { // 連結判定
return root(x) == root(y);
}
ll size(ll x) { // 素集合のサイズ
return siz[root(x)];
}
};
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
// assert(n < mod);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
};
struct edge {
int to, cost;
};
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// cout << fixed << setprecision(20);
// combination com(200010);
int m, d;
cin >> m >> d;
int ans = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= 9; j++) {
for (int k = 1; k <= 9; k++) {
if (10 * j + k > d)
continue;
if (j * k == i)
ans++;
}
}
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define P pair<ll, ll>
#define sz(x) (ll) x.size()
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define VE vector<ll>
#define COUT(x) cout << (x) << endl
#define MA map<ll, ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, VE, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define EPS (1e-10)
#define pb push_back
long long MOD = 1000000007;
// long long MOD = 998244353;
const long long INF = 1LL << 60;
const long double PI = acos(-1.0);
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
bool operator==(const mint a) const { return x == a.x; }
bool operator!=(const mint a) const { return x != a.x; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n = 1) : n(n), f(n + 1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i])
continue;
primes.push_back(i);
f[i] = i;
for (ll j = i * i; j <= n; j += i) {
if (!f[j])
f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x; }
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<P> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0)
return {};
vector<P> res(1, P(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
};
template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
bool prime(ll n) {
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return n != 1;
}
map<ll, ll> prime_factor(ll n) {
map<ll, ll> ret;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
vector<pair<char, int>> RunLength(string s) {
if (s.size() == 0)
return {};
vector<pair<char, int>> res(1, pair<char, int>(s[0], 0));
for (char p : s) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
// Digit Count
int GetDigit(int num) { return log10(num) + 1; }
// bit calculation[how many "1"] (= __builtin_popcount())
int bit_count(int n) {
int cnt = 0;
while (n > 0) {
if (n % 2 == 1)
cnt++;
n /= 2;
}
return cnt;
}
vector<long long> enum_divisors(long long N) {
vector<long long> res;
for (long long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
if (N / i != i)
res.push_back(N / i);
}
}
sort(res.begin(), res.end());
return res;
}
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
// struct edge { ll to, cost; };
typedef long double ld;
using Graph = vector<vector<int>>;
class UnionFind {
public:
vector<ll> par; // 各元の親を表す配列
vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)
// Constructor
UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
for (ll i = 0; i < sz_; ++i)
par[i] = i; // 初期では親は自分自身
}
void init(ll sz_) {
par.resize(sz_);
siz.resize(sz_, 1);
for (ll i = 0; i < sz_; ++i)
par[i] = i; // 初期では親は自分自身
}
// Member Function
// Find
ll root(ll x) { // 根の検索
while (par[x] != x) {
x = par[x] = par[par[x]]; // x の親の親を x の親とする
}
return x;
}
// Union(Unite, Merge)
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
// merge technique(データ構造をマージするテク.小を大にくっつける)
if (siz[x] < siz[y])
swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) { // 連結判定
return root(x) == root(y);
}
ll size(ll x) { // 素集合のサイズ
return siz[root(x)];
}
};
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
// assert(n < mod);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
};
struct edge {
int to, cost;
};
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// cout << fixed << setprecision(20);
// combination com(200010);
int m, d;
cin >> m >> d;
int ans = 0;
for (int i = 1; i <= m; i++) {
for (int j = 2; j <= 9; j++) {
for (int k = 2; k <= 9; k++) {
if (10 * j + k > d)
continue;
if (j * k == i)
ans++;
}
}
}
cout << ans << endl;
return 0;
}
|
[
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 729,975
| 729,976
|
u809967037
|
cpp
|
p02927
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = (s); i < (int)n; i++)
int INF = 1e9 + 7;
int main() {
int M, D;
cin >> M >> D;
int ans = 0;
rep(i, D) {
int a = i / 10, b = i % 10;
if (a >= 2 && b >= 2 && a * b <= M)
ans++;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = (s); i < (int)n; i++)
int INF = 1e9 + 7;
int main() {
int M, D;
cin >> M >> D;
int ans = 0;
rep2(i, 1, D + 1) {
int a = i / 10, b = i % 10;
if (a >= 2 && b >= 2 && a * b <= M)
ans++;
}
cout << ans << endl;
}
|
[
"call.arguments.add"
] | 729,977
| 729,978
|
u236658355
|
cpp
|
p02927
|
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define double long double
#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 repeq(i, n) for (int i = 0; i <= (int)(n); ++i)
#define rep1eq(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n)-1; i > 0; --i)
#define rrepeq(i, n) for (int i = (int)(n); i >= 0; --i)
#define rrep1eq(i, n) for (int i = (int)(n); i > 0; --i)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define RREP(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
template <typename T> using Graph = vector<vector<T>>;
template <typename T> using Spacial = vector<vector<vector<T>>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using greater_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
// const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
string interval[2] = {" ", "\n"}; // {" ", "\n"}
template <typename T> struct is_plural : false_type {};
template <typename T1, typename T2>
struct is_plural<pair<T1, T2>> : true_type {};
template <typename T> struct is_plural<vector<T>> : true_type {};
template <typename T> struct is_plural<complex<T>> : true_type {};
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
return is >> p.first >> p.second;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
return os << p.first << " " << p.second;
}
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (auto itr = vec.begin(); itr != vec.end(); ++itr)
is >> *itr;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
if (vec.empty())
return os;
bool pl = is_plural<T>();
os << vec.front();
for (auto itr = ++vec.begin(); itr != vec.end(); ++itr)
os << interval[pl] << *itr;
return os;
}
bool CoutYN(bool a, string y = "Yes", string n = "No") {
cout << (a ? y : n) << "\n";
return a;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
long long modpow(int a, long long n, int mod = MOD) {
long long ret = 1;
do {
if (n & 1)
ret = ret * a % mod;
a = 1LL * a * a % mod;
} while (n >>= 1);
return ret;
}
template <typename T> T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template <typename T> T LCM(T a, T b) { return a / GCD(a, b) * b; }
template <typename T1, typename T2>
bool CompareBySecond(pair<T1, T2> a, pair<T1, T2> b) {
return a.second != b.second ? a.second < b.second : a.first < b.first;
}
template <typename T1, typename T2>
bool CompareByInverse(pair<T1, T2> a, pair<T1, T2> b) {
return a.first != b.first ? a.first < b.first : a.second > b.second;
}
/* -------- <templates end> -------- */
void solve() {
int m, d;
cin >> m >> d;
int ans = 0;
REP(i, 22, d) {
int x = d % 10;
int y = d / 10;
if (x < 2)
continue;
if (x * y <= m)
++ans;
}
cout << ans << endl;
}
/* -------- <programs end> -------- */
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
solve();
return 0;
}
|
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define double long double
#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 repeq(i, n) for (int i = 0; i <= (int)(n); ++i)
#define rep1eq(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n)-1; i > 0; --i)
#define rrepeq(i, n) for (int i = (int)(n); i >= 0; --i)
#define rrep1eq(i, n) for (int i = (int)(n); i > 0; --i)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define RREP(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
template <typename T> using Graph = vector<vector<T>>;
template <typename T> using Spacial = vector<vector<vector<T>>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using greater_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
// const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
string interval[2] = {" ", "\n"}; // {" ", "\n"}
template <typename T> struct is_plural : false_type {};
template <typename T1, typename T2>
struct is_plural<pair<T1, T2>> : true_type {};
template <typename T> struct is_plural<vector<T>> : true_type {};
template <typename T> struct is_plural<complex<T>> : true_type {};
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
return is >> p.first >> p.second;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
return os << p.first << " " << p.second;
}
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (auto itr = vec.begin(); itr != vec.end(); ++itr)
is >> *itr;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
if (vec.empty())
return os;
bool pl = is_plural<T>();
os << vec.front();
for (auto itr = ++vec.begin(); itr != vec.end(); ++itr)
os << interval[pl] << *itr;
return os;
}
bool CoutYN(bool a, string y = "Yes", string n = "No") {
cout << (a ? y : n) << "\n";
return a;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
long long modpow(int a, long long n, int mod = MOD) {
long long ret = 1;
do {
if (n & 1)
ret = ret * a % mod;
a = 1LL * a * a % mod;
} while (n >>= 1);
return ret;
}
template <typename T> T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template <typename T> T LCM(T a, T b) { return a / GCD(a, b) * b; }
template <typename T1, typename T2>
bool CompareBySecond(pair<T1, T2> a, pair<T1, T2> b) {
return a.second != b.second ? a.second < b.second : a.first < b.first;
}
template <typename T1, typename T2>
bool CompareByInverse(pair<T1, T2> a, pair<T1, T2> b) {
return a.first != b.first ? a.first < b.first : a.second > b.second;
}
/* -------- <templates end> -------- */
void solve() {
int m, d;
cin >> m >> d;
int ans = 0;
REP(i, 22, d) {
int x = i % 10;
int y = i / 10;
if (x < 2)
continue;
if (x * y <= m)
++ans;
}
cout << ans << endl;
}
/* -------- <programs end> -------- */
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
solve();
return 0;
}
|
[
"identifier.change",
"expression.operation.binary.change"
] | 729,981
| 729,982
|
u104057163
|
cpp
|
p02927
|
#pragma GCC optimize("Ofast")
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int m, d;
cin >> m >> d;
int res = 0;
int d1;
int d2;
for (int month = 4; month <= m; month++) {
for (int day = 22; day <= d; day++) {
int tmp = day;
d1 = day % 10;
if (d1 < 2)
continue;
tmp -= d1;
d2 = tmp / 10;
if (month == d1 * d2)
res++;
cout << res << endl;
}
}
}
|
#pragma GCC optimize("Ofast")
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int m, d;
cin >> m >> d;
int res = 0;
int d1;
int d2;
for (int month = 4; month <= m; month++) {
for (int day = 22; day <= d; day++) {
int tmp = day;
d1 = day % 10;
if (d1 < 2)
continue;
tmp -= d1;
d2 = tmp / 10;
if (month == d1 * d2)
res++;
}
}
cout << res << endl;
}
|
[] | 729,985
| 729,986
|
u583888880
|
cpp
|
p02927
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <sstream> //���炵���̂Œ���
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout << s << endl
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
string Yes(bool b) {
if (b) {
return "Yes";
} else {
return "No";
}
}
string YES(bool b) {
if (b) {
return "YES";
} else {
return "NO";
}
}
//================================================
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;
int main() {
int m, d;
cin >> m >> d;
int cnt = 0;
rep(i, d) {
int d1 = i % 10, d10 = i / 10;
if (d1 >= 2 && d10 >= 2 && d1 * d10 <= m) {
cnt++;
}
}
cout << cnt << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <sstream> //���炵���̂Œ���
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout << s << endl
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
string Yes(bool b) {
if (b) {
return "Yes";
} else {
return "No";
}
}
string YES(bool b) {
if (b) {
return "YES";
} else {
return "NO";
}
}
//================================================
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;
int main() {
int m, d;
cin >> m >> d;
int cnt = 0;
rep(i, d + 1) {
int d1 = i % 10, d10 = i / 10;
if (d1 >= 2 && d10 >= 2 && d1 * d10 <= m) {
cnt++;
}
}
cout << cnt << endl;
return 0;
}
|
[
"expression.operation.binary.add"
] | 729,987
| 729,988
|
u465760322
|
cpp
|
p02927
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int M, D;
cin >> M >> D;
int Ans = 0;
for (int i = 1; i <= M; i++) {
for (int j = 1; j <= D; j++) {
int D10 = D / 10;
int D1 = D - 10 * D10;
if (D10 >= 2 && D1 >= 2 && D10 * D1 == M) {
Ans++;
}
}
}
cout << Ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int M, D;
cin >> M >> D;
int Ans = 0;
for (int i = 1; i <= M; i++) {
for (int j = 1; j <= D; j++) {
int D10 = j / 10;
int D1 = j - 10 * D10;
if (D10 >= 2 && D1 >= 2 && D10 * D1 == i) {
Ans++;
}
}
}
cout << Ans << endl;
}
|
[
"identifier.change",
"expression.operation.binary.change",
"control_flow.branch.if.condition.change"
] | 729,989
| 729,990
|
u164730704
|
cpp
|
p02927
|
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << (x) << endl
int main() {
int m, d;
cin >> m >> d;
int ans = 0;
if (m < 4 || d < 21)
ans = 0;
else {
for (int i = 22; i < d; i++) {
int num1 = i % 10;
int num10 = i / 10;
if (num1 >= 2 && num10 >= 2 && num1 * num10 <= m)
ans++;
}
}
COUT(ans);
return 0;
}
|
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << (x) << endl
int main() {
int m, d;
cin >> m >> d;
int ans = 0;
if (m < 4 || d < 21)
ans = 0;
else {
for (int i = 22; i <= d; i++) {
int num1 = i % 10;
int num10 = i / 10;
if (num1 >= 2 && num10 >= 2 && num1 * num10 <= m)
ans++;
}
}
COUT(ans);
return 0;
}
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 729,991
| 729,992
|
u459105164
|
cpp
|
p02927
|
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int m, d;
int count = 0;
cin >> m >> d;
for (int i = 1; i <= m; i++) {
for (int j = 2; j <= d; j++) {
for (int k = 2; k <= d; k++) {
if (10 * j + k > d)
continue;
if (j * k == i)
count++;
}
}
}
cout << count << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int m, d;
int count = 0;
cin >> m >> d;
for (int i = 1; i <= m; i++) {
for (int j = 2; j <= d; j++) {
for (int k = 2; k < 10; k++) {
if (10 * j + k > d)
continue;
if (j * k == i)
count++;
}
}
}
cout << count << endl;
return 0;
}
|
[
"control_flow.loop.for.condition.change"
] | 730,006
| 730,007
|
u198469037
|
cpp
|
p02927
|
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
int M, D;
cin >> M >> D;
if (D < 22) {
cout << 0 << endl;
} else {
int ans = 0;
for (int i = 22; i < D; i++) {
int d1 = i / 10;
int d2 = i - 10 * d1;
if (d2 < 2)
continue;
if (d1 * d2 <= M)
ans++;
}
cout << ans << endl;
}
}
|
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
int M, D;
cin >> M >> D;
if (D < 22) {
cout << 0 << endl;
} else {
int ans = 0;
for (int i = 22; i <= D; i++) {
int d1 = i / 10;
int d2 = i % 10;
if (d2 < 2)
continue;
if (d1 * d2 <= M)
ans++;
}
cout << ans << endl;
}
}
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"expression.operator.arithmetic.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 730,008
| 730,009
|
u868132236
|
cpp
|
p02927
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reprev(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
int main() {
int m, d, res, d10, d1;
cin >> m >> d;
res = 0;
d10 = d / 10;
d1 = d % 10;
rep2(i, 4, m + 1) {
rep2(j, 2, d10 + 1) {
rep2(k, 2, 9) {
if (j == d10 && k > d1)
break;
if (i == (j * k))
res++;
}
}
}
cout << res << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reprev(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
int main() {
int m, d, res, d10, d1;
cin >> m >> d;
res = 0;
d10 = d / 10;
d1 = d % 10;
rep2(i, 4, m + 1) {
rep2(j, 2, d10 + 1) {
rep2(k, 2, 9 + 1) {
if (j == d10 && k > d1)
break;
if (i == (j * k))
res++;
}
}
}
cout << res << endl;
}
|
[
"expression.operation.binary.add"
] | 730,012
| 730,013
|
u430419385
|
cpp
|
p02927
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
int main() {
long long int M, D;
scanf("%lld%lld", &M, &D);
long long int ans = 0;
for (long long int i = 20; i < D; i++) {
if ((i + 10) % 10 >= 2 && (i / 10) * (i % 10) <= M) {
ans++;
}
}
std::cerr << "Answer: " << std::endl;
std::cout << ans << std::endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
int main() {
long long int M, D;
scanf("%lld%lld", &M, &D);
long long int ans = 0;
for (long long int i = 20; i <= D; i++) {
if ((i + 10) % 10 >= 2 && (i / 10) * (i % 10) <= M) {
ans++;
}
}
std::cerr << "Answer: " << std::endl;
std::cout << ans << std::endl;
return 0;
}
|
[
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 730,014
| 730,015
|
u401013791
|
cpp
|
p02927
|
#include <bits/stdc++.h>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define fix(n) cout << fixed << setprecision(n)
#define co(n) cout << n << endl
#define all(n) (n).begin(), (n).end()
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
double pi = 3.1415926535;
int main() {
int m, d, a, b;
cin >> m >> d;
int c = 0;
if (m < 4 || d < 22)
co(0);
else {
rep(i, 4, m + 1) {
rep(j, 22, d + 1) {
a = j / 10;
b = j % 10;
if (a >= 2 && b >= 2 && i == a * b) {
c++;
}
}
}
}
co(c);
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define fix(n) cout << fixed << setprecision(n)
#define co(n) cout << n << endl
#define all(n) (n).begin(), (n).end()
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
double pi = 3.1415926535;
int main() {
int m, d, a, b;
cin >> m >> d;
int c = 0;
if (m < 4 || d < 22)
co(0);
else {
rep(i, 4, m + 1) {
rep(j, 22, d + 1) {
a = j / 10;
b = j % 10;
if (a >= 2 && b >= 2 && i == a * b) {
c++;
}
}
}
co(c);
}
return 0;
}
|
[] | 730,016
| 730,017
|
u558115145
|
cpp
|
p02927
|
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
// inline int in() { int x; scanf("%d",&x); return x;}
inline ll in() {
ll x;
cin >> x;
return x;
}
template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
rep(j, sz(v)) i >> v[j];
return i;
}
template <typename T> string join(const v(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 v(T) & v) {
if (sz(v))
o << join(v);
return o;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
return i >> v.fi >> v.se;
}
template <typename T1, typename T2>
inline ostream &operator<<(ostream &o, const pair<T1, T2> &v) {
return o << v.fi << "," << v.se;
}
template <typename T> inline ll suma(const v(T) & a) {
ll res(0);
for (auto &&x : a)
res += x;
return res;
}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define yn \
{ puts("YES"); } \
else { \
puts("NO"); \
}
const int MX = 200005;
vector<int> to[2505];
vector<int> rto[2505];
bool reachablefrom1[2505];
bool reachableToN[2505];
bool ok[2505];
void dfs(int v) {
if (reachablefrom1[v])
return;
reachablefrom1[v] = true;
for (int u : to[v]) {
dfs(u);
}
}
void rdfs(int v) {
if (reachableToN[v])
return;
reachableToN[v] = true;
for (int u : rto[v]) {
rdfs(u);
}
}
int main() {
int m = in(), d = in();
int ans = 0;
rep(i, d) {
int d1 = i % 10;
int d10 = i / 10;
if (d1 < 2 || d10 < 2)
continue;
if (m >= d1 * d10)
ans++;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
// inline int in() { int x; scanf("%d",&x); return x;}
inline ll in() {
ll x;
cin >> x;
return x;
}
template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
rep(j, sz(v)) i >> v[j];
return i;
}
template <typename T> string join(const v(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 v(T) & v) {
if (sz(v))
o << join(v);
return o;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
return i >> v.fi >> v.se;
}
template <typename T1, typename T2>
inline ostream &operator<<(ostream &o, const pair<T1, T2> &v) {
return o << v.fi << "," << v.se;
}
template <typename T> inline ll suma(const v(T) & a) {
ll res(0);
for (auto &&x : a)
res += x;
return res;
}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define yn \
{ puts("YES"); } \
else { \
puts("NO"); \
}
const int MX = 200005;
vector<int> to[2505];
vector<int> rto[2505];
bool reachablefrom1[2505];
bool reachableToN[2505];
bool ok[2505];
void dfs(int v) {
if (reachablefrom1[v])
return;
reachablefrom1[v] = true;
for (int u : to[v]) {
dfs(u);
}
}
void rdfs(int v) {
if (reachableToN[v])
return;
reachableToN[v] = true;
for (int u : rto[v]) {
rdfs(u);
}
}
int main() {
int m = in(), d = in();
int ans = 0;
rep(i, d + 1) {
int d1 = i % 10;
int d10 = i / 10;
if (d1 < 2 || d10 < 2)
continue;
if (m >= d1 * d10)
ans++;
}
cout << ans << endl;
return 0;
}
|
[
"expression.operation.binary.add"
] | 730,020
| 730,021
|
u526630579
|
cpp
|
p02927
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000 // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979
//.size()はunsigned int 0-1をするとオーバーフローする
using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;
int dy[5] = {-1, 0, 1, 0, 0};
int dx[5] = {0, -1, 0, 1, 0};
int main(void) {
int total = 0;
int m, d;
cin >> m >> d;
FOR(i, 1, m) {
FOR(k, 1, d) {
int p, q;
p = k % 10;
q = k;
q = q / 10;
if (p >= 2 && q >= 2 && p * q == m) {
total++;
}
}
}
cout << total << endl;
}
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000 // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979
//.size()はunsigned int 0-1をするとオーバーフローする
using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;
int dy[5] = {-1, 0, 1, 0, 0};
int dx[5] = {0, -1, 0, 1, 0};
int main(void) {
int total = 0;
int m, d;
cin >> m >> d;
FOR(i, 1, m) {
FOR(k, 1, d) {
int p, q;
p = k % 10;
q = k;
q = q / 10;
if (p >= 2 && q >= 2 && p * q == i) {
total++;
}
}
}
cout << total << endl;
}
|
[
"identifier.change",
"control_flow.branch.if.condition.change"
] | 730,022
| 730,023
|
u057611820
|
cpp
|
p02927
|
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
#define PI 3.141592653589793
int main() {
int m, d;
cin >> m >> d;
int cnt = 0;
rep(i, d) {
if (i <= 11)
continue;
int k = i;
int da = k % 10;
k /= 10;
int di = k % 10;
if (da * di >= 2 && da * di <= m && da > 1 && di > 1)
cnt++;
}
cout << cnt << endl;
}
|
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
#define PI 3.141592653589793
int main() {
int m, d;
cin >> m >> d;
int cnt = 0;
rep(i, d + 1) {
if (i <= 11)
continue;
int k = i;
int da = k % 10;
k /= 10;
int di = k % 10;
if (da * di >= 2 && da * di <= m && da > 1 && di > 1) {
cnt++;
}
}
cout << cnt << endl;
}
|
[
"expression.operation.binary.add"
] | 730,024
| 730,025
|
u841131859
|
cpp
|
p02927
|
#include <bits/stdc++.h>
using namespace std;
pair<int, int> mul(int n) {
int d1 = n % 10;
int d2 = n / 10;
pair<int, int> p = make_pair(d2, d1);
return p;
}
int main() {
int m;
int d;
cin >> m >> d;
int ans = 0;
for (int i = 1; i < d; i++) {
pair<int, int> p = mul(i);
if (p.first >= 2 && p.second >= 2 && p.first * p.second <= m)
ans++;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
pair<int, int> mul(int n) {
int d1 = n % 10;
int d2 = n / 10;
pair<int, int> p = make_pair(d2, d1);
return p;
}
int main() {
int m;
int d;
cin >> m >> d;
int ans = 0;
for (int i = 1; i <= d; i++) {
pair<int, int> p = mul(i);
if (p.first >= 2 && p.second >= 2 && p.first * p.second <= m)
ans++;
}
cout << ans << endl;
}
|
[
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 730,030
| 730,031
|
u045368371
|
cpp
|
p02927
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long
using namespace std;
int main() {
int m, d;
cin >> m >> d;
int result = 0;
rep(i, m) rep(j, d) {
if ((j + 1) % 10 < 2 || (j + 1) / 10 < 2)
continue;
if (((j + 1) % 10) * ((j + 1) / 10) == m + 1)
result++;
}
cout << result << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long
using namespace std;
int main() {
int m, d;
cin >> m >> d;
int result = 0;
rep(i, m) rep(j, d) {
if ((j + 1) % 10 < 2 || (j + 1) / 10 < 2)
continue;
if ((((j + 1) % 10) * ((j + 1) / 10)) == (i + 1))
result++;
// if( ( ((j+1)%10)*((j+1)/10) )==( i+1 ) )cout<<i+1<<' '<<j+1<<endl;
}
cout << result << endl;
return 0;
}
|
[
"control_flow.branch.if.condition.change"
] | 730,032
| 730,033
|
u021358975
|
cpp
|
p02927
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, d;
cin >> m >> d;
int ans = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j < d; j++) {
int d1 = j % 10, d10 = j / 10;
if (d1 >= 2 && d10 >= 2) {
if (d1 * d10 == i) {
ans++;
}
}
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, d;
cin >> m >> d;
int ans = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= d; j++) {
int d1 = j % 10, d10 = j / 10;
if (d1 >= 2 && d10 >= 2) {
if (d1 * d10 == i) {
ans++;
}
}
}
}
cout << ans << endl;
}
|
[
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 730,038
| 730,039
|
u648009244
|
cpp
|
p02927
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define co(x) cout << x << endl
#define cs(x) cout << x << " "
#define ALL(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
int main() {
int m, d;
cin >> m >> d;
int ans = 0;
rep1(i, m) rep(j, d) {
int d1 = j % 10;
int d10 = j / 10;
if (d1 >= 2 && d10 >= 2 && i == d1 * d10)
ans++;
}
co(ans);
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define co(x) cout << x << endl
#define cs(x) cout << x << " "
#define ALL(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
int main() {
int m, d;
cin >> m >> d;
int ans = 0;
rep1(i, m) rep1(j, d) {
int d1 = j % 10;
int d10 = j / 10;
if (d1 >= 2 && d10 >= 2 && i == d1 * d10)
ans++;
}
co(ans);
return 0;
}
|
[
"identifier.change"
] | 730,043
| 730,044
|
u984529214
|
cpp
|
p02927
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, d, d1, d10, answer;
answer = 0;
cin >> m >> d;
for (int i = 0; i < m; i++) {
for (int j = 0; j < d; j++) {
d1 = j % 10;
d10 = j / 10;
if (d1 > 1 && d10 > 1 & i == d1 * d10)
answer++;
}
}
cout << answer << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, d, d1, d10, answer;
answer = 0;
cin >> m >> d;
for (int i = 1; i < m + 1; i++) {
for (int j = 1; j < d + 1; j++) {
d1 = j % 10;
d10 = j / 10;
if (d1 > 1 && d10 > 1 & i == d1 * d10)
answer++;
}
}
cout << answer << endl;
}
|
[
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 730,045
| 730,046
|
u993074316
|
cpp
|
p02927
|
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}
void print(const std::vector<int> &v) {
std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
std::cout << std::endl;
}
int main() {
int M, D;
cin >> M >> D;
ll cnt = 0;
for (int i = 1; i <= M; i++) {
for (int j = 22; j <= D; j++) {
if (j % 10 < 2) {
continue;
}
if (j / 10 * j % 10 == i) {
cnt++;
}
}
}
cout << cnt << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}
void print(const std::vector<int> &v) {
std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
std::cout << std::endl;
}
int main() {
int M, D;
cin >> M >> D;
ll cnt = 0;
for (int i = 1; i <= M; i++) {
for (int j = 22; j <= D; j++) {
if (j % 10 < 2) {
continue;
}
if ((j / 10) * (j % 10) == i) {
cnt++;
// cout << i << " " << j << endl;
}
}
}
cout << cnt << endl;
return 0;
}
|
[
"control_flow.branch.if.condition.change"
] | 730,055
| 730,056
|
u824337972
|
cpp
|
p02927
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, d, count = 0;
cin >> m >> d;
if (d < 22 || m < 4) {
cout << 0 << endl;
return 0;
}
for (int j = 4; j <= m; j++) {
for (int i = 22; i <= d; i++) {
int d1 = d % 10, d10 = d / 10;
if (d1 < 2)
continue;
else if (d1 * d10 == j)
count++;
}
}
cout << count << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, d, count = 0;
cin >> m >> d;
if (d < 22 || m < 4) {
cout << 0 << endl;
return 0;
}
for (int j = 4; j <= m; j++) {
for (int i = 22; i <= d; i++) {
int d1 = i % 10, d10 = i / 10;
if (d1 < 2)
continue;
else if (d1 * d10 == j)
count++;
}
}
cout << count << endl;
}
|
[
"identifier.change",
"expression.operation.binary.change"
] | 730,066
| 730,067
|
u351265848
|
cpp
|
p02927
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, d;
cin >> m >> d;
int ans = 0;
for (int i = 1; i <= m; i++)
for (int j = 1; j <= d; j++)
if (m == (j / 10 >= 2 ? j / 10 : 0) * (j % 10 >= 2 ? j % 10 : 0))
ans++;
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, d;
cin >> m >> d;
int ans = 0;
for (int i = 1; i <= m; i++)
for (int j = 1; j <= d; j++)
if (i == (j / 10 >= 2 ? j / 10 : 1000) * (j % 10 >= 2 ? j % 10 : 1000))
ans++;
cout << ans << endl;
}
|
[
"identifier.change",
"control_flow.branch.if.condition.change",
"literal.number.change"
] | 730,068
| 730,069
|
u481694065
|
cpp
|
p02927
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int int_len(int n) {
int s = 0;
while (n != 0)
s++, n /= 10;
return s;
}
int int_sum(int n) {
int m = 0, s = 0, a = n;
while (a != 0)
s++, a /= 10;
for (int i = s - 1; i >= 0; i--)
m += n / ((int)pow(10, i)) - (n / ((int)pow(10, i + 1))) * 10;
return m;
}
int vec_sum(vector<int> v) {
int n = 0;
for (int i = 0; i < v.size(); i++)
n += v[i];
return n;
}
int main() {
int m, d, ans = 0;
cin >> m >> d;
for (int i = 1; i <= m; i++) {
for (int j = 1; j < d; j++) {
if (i == (j / 10) * (j % 10) && (j / 10) >= 2 && (j % 10) >= 2) {
ans++;
}
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int int_len(int n) {
int s = 0;
while (n != 0)
s++, n /= 10;
return s;
}
int int_sum(int n) {
int m = 0, s = 0, a = n;
while (a != 0)
s++, a /= 10;
for (int i = s - 1; i >= 0; i--)
m += n / ((int)pow(10, i)) - (n / ((int)pow(10, i + 1))) * 10;
return m;
}
int vec_sum(vector<int> v) {
int n = 0;
for (int i = 0; i < v.size(); i++)
n += v[i];
return n;
}
int main() {
int m, d, ans = 0;
cin >> m >> d;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= d; j++) {
if (i == (j / 10) * (j % 10) && (j / 10) >= 2 && (j % 10) >= 2) {
ans++;
}
}
}
cout << ans << endl;
}
|
[
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 730,070
| 730,071
|
u264265458
|
cpp
|
p02927
|
#include <iostream>
using namespace std;
int main() {
int M, D;
cin >> M >> D;
/*m月d日:d=10*e+f
e>=2 && f>=2 && e*f==m */
int count = 0;
for (int e = 2; e <= D / 10; e++) {
for (int f = 0; e * 10 + f <= D; f++) {
if (e * f <= M)
count++;
}
}
cout << count << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int M, D;
cin >> M >> D;
/*m月d日:d=10*e+f
e>=2 && f>=2 && e*f==m */
int count = 0;
for (int e = 2; e <= D / 10; e++) {
for (int f = 2; e * 10 + f <= D && f <= 9; f++) {
if (e * f <= M)
count++;
}
}
cout << count << endl;
return 0;
}
|
[
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"control_flow.loop.for.condition.change"
] | 730,077
| 730,078
|
u660112829
|
cpp
|
p02927
|
#include <iostream>
using namespace std;
int main() {
int M, D;
cin >> M >> D;
/*m月d日:d=10*e+f
e>=2 && f>=2 && e*f==m */
int count = 0;
for (int e = 2; e <= D / 10; e++) {
for (int f = 1; e * 10 + f <= D; f++) {
if (e * f <= M)
count++;
}
}
cout << count << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int M, D;
cin >> M >> D;
/*m月d日:d=10*e+f
e>=2 && f>=2 && e*f==m */
int count = 0;
for (int e = 2; e <= D / 10; e++) {
for (int f = 2; e * 10 + f <= D && f <= 9; f++) {
if (e * f <= M)
count++;
}
}
cout << count << endl;
return 0;
}
|
[
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"control_flow.loop.for.condition.change"
] | 730,079
| 730,078
|
u660112829
|
cpp
|
p02927
|
#include <iostream>
using namespace std;
int main() {
int M, D;
cin >> M >> D;
/*m月d日:d=10*e+f
e>=2 && f>=2 && e*f==m */
int count = 0;
for (int e = 2; e <= D / 10; e++) {
for (int f = 2; e * 10 + f <= D; f++) {
if (e * f <= M)
count++;
}
}
cout << count << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int M, D;
cin >> M >> D;
/*m月d日:d=10*e+f
e>=2 && f>=2 && e*f==m */
int count = 0;
for (int e = 2; e <= D / 10; e++) {
for (int f = 2; e * 10 + f <= D && f <= 9; f++) {
if (e * f <= M)
count++;
}
}
cout << count << endl;
return 0;
}
|
[
"control_flow.loop.for.condition.change"
] | 730,080
| 730,078
|
u660112829
|
cpp
|
p02927
|
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
int M, D;
cin >> M >> D;
int answer = 0;
if (D >= 22) {
for (int i = 2; i <= D / 10; i++) {
if (i < D / 10) {
for (int j = 2; j <= 9; j++) {
if (i * j <= M) {
answer++;
}
}
} else if (i == D / 10 && D % 10 > 2) {
for (int j = 2; j <= D % 10; j++) {
if (i * j <= M) {
answer++;
}
}
}
}
}
cout << answer << endl;
}
/*int main(){
int N;
cin>>N;
int A[20],B[20],C[20];
for(int i=1;i<=N;i++){
cin>>A[i];
}
for(int i=1;i<=N;i++){
cin>>B[i];
}
int answer=0;
for(int i=1;i<=N-1;i++){
cin>>C[i];
}
for(int i=1;i<=N;i++){
answer+=B[A[i]];
if(i>=2&&A[i]-A[i-1]==1){
answer+=C[A[i-1]];
}
}
cout<<answer<<endl;
}*/
/*int main(){
int N;
cin>>N;
cout<<N*N*N<<endl;
}*/
|
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
int M, D;
cin >> M >> D;
int answer = 0;
if (D >= 22) {
for (int i = 2; i <= D / 10; i++) {
if (i < D / 10) {
for (int j = 2; j <= 9; j++) {
if (i * j <= M) {
answer++;
}
}
} else if (i == D / 10 && D % 10 >= 2) {
for (int j = 2; j <= D % 10; j++) {
if (i * j <= M) {
answer++;
}
}
}
}
}
cout << answer << endl;
}
/*int main(){
int N;
cin>>N;
int A[20],B[20],C[20];
for(int i=1;i<=N;i++){
cin>>A[i];
}
for(int i=1;i<=N;i++){
cin>>B[i];
}
int answer=0;
for(int i=1;i<=N-1;i++){
cin>>C[i];
}
for(int i=1;i<=N;i++){
answer+=B[A[i]];
if(i>=2&&A[i]-A[i-1]==1){
answer+=C[A[i-1]];
}
}
cout<<answer<<endl;
}*/
/*int main(){
int N;
cin>>N;
cout<<N*N*N<<endl;
}*/
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 730,085
| 730,086
|
u088111798
|
cpp
|
p02927
|
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr auto inf = static_cast<ll>(1e18);
template <typename T = ll> inline T in() {
T ret;
cin >> ret;
return ret;
}
template <typename T = ll> inline auto vec2(size_t h, size_t w, T v = T()) {
return vector<vector<T>>(h, vector<T>(w, v));
}
inline void setp(int n) { cout << fixed << setprecision(n); }
inline void delnl() { cin.ignore(numeric_limits<streamsize>::max(), '\n'); }
int main() {
ll m = in(), d = in();
ll cnt = 0;
for (ll i = 1; i <= m; ++i) {
for (ll j = 2; j < i; ++j) {
if (i % j == 0) {
ll dd = (i / j) * 10 + j;
if (1 <= dd && dd <= d)
++cnt;
}
}
}
cout << cnt << endl;
}
|
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr auto inf = static_cast<ll>(1e18);
template <typename T = ll> inline T in() {
T ret;
cin >> ret;
return ret;
}
template <typename T = ll> inline auto vec2(size_t h, size_t w, T v = T()) {
return vector<vector<T>>(h, vector<T>(w, v));
}
inline void setp(int n) { cout << fixed << setprecision(n); }
inline void delnl() { cin.ignore(numeric_limits<streamsize>::max(), '\n'); }
int main() {
ll m = in(), d = in();
ll cnt = 0;
for (ll i = 1; i <= m; ++i) {
for (ll j = 2; j < 10; ++j) {
if (i != j && i % j == 0) {
ll dd = (i / j) * 10 + j;
if (1 <= dd && dd <= d)
++cnt;
}
}
}
cout << cnt << endl;
}
|
[
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change",
"control_flow.branch.if.condition.change"
] | 730,089
| 730,090
|
u388817534
|
cpp
|
p02927
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int M, D;
cin >> M >> D;
int counter = 0;
for (int x = 2; x < 9; x++) {
for (int y = 2; y < 9; y++) {
if (10 * x + y <= D && x * y <= M) {
counter++;
}
}
}
cout << counter << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int M, D;
cin >> M >> D;
int counter = 0;
for (int x = 2; x <= 9; x++) {
for (int y = 2; y <= 9; y++) {
if (10 * x + y <= D && x * y <= M) {
counter++;
}
}
}
cout << counter << endl;
}
|
[
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 730,093
| 730,094
|
u854161810
|
cpp
|
p02927
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, d;
cin >> m >> d;
int c = 0;
for (int i = 2; i <= d; i++) {
for (int j = 2; j <= d; j++) {
if (i * j <= m && (10 * i + j) <= d) {
++c;
} else {
break;
}
}
}
cout << c << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, d;
cin >> m >> d;
int c = 0;
for (int i = 2; i <= 9; i++) {
for (int j = 2; j <= 9; j++) {
if (i * j <= m && (10 * i + j) <= d) {
++c;
} else {
break;
}
}
}
cout << c << endl;
}
|
[
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 730,095
| 730,096
|
u278530069
|
cpp
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.