problem_id stringlengths 6 6 | language stringclasses 2 values | original_status stringclasses 3 values | original_src stringlengths 19 243k | changed_src stringlengths 19 243k | change stringclasses 3 values | i1 int64 0 8.44k | i2 int64 0 8.44k | j1 int64 0 8.44k | j2 int64 0 8.44k | error stringclasses 270 values | stderr stringlengths 0 226k |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02682 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <ctype.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
#define ll long long int
#define read(a) \
long long int a; \
cin >> a;
#define readstr(s) \
string s; \
cin >> s;
#define readc(c) \
char c; \
cin >> c;
#define readarr(a, l) \
long long int a[l] = {0}; \
for (ll i = 0; i < l; i++) \
cin >> a[i];
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define rloop(i, a, b) for (ll i = a; i > b; i--)
#define loopchar() for (char c = 'a'; c <= 'z'; c++)
#define printarr(a, n) \
fori(i, 1, n) cout << a[i] << " "; \
cout << endl;
#define printv(v) \
for (int i : v) \
cout << i << " "; \
cout << endl;
#define loopitr(vec) for (auto itr = vec.begin(); itr != vec.end(); itr++)
#define ff first
#define ss second
#define readmtrx(i, j, a, b) \
ll arr[a][b] = {0}; \
for (ll i = 0; i < a; i++) \
for (ll j = 0; j < b; j++) \
cin >> arr[i][j];
#define all(a) a.begin(), a.end()
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define sc(x) cout << (#x) << " is " << (x) << endl;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0);
#define pb(p) push_back(p)
#define mp make_pair
#define fsort(vec) sort(vec.begin(), vec.end())
#define rsort(vec) sort(vec.begin(), vec.end(), compare)
#define Endl endl
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define roundoff std::cout << std::setprecision(15)
#define inf 9223372036854775807
#define infn -9223372036854775807
#define pi 3.14159265358979323846
const int mod = 1e9 + 7;
#define intsize ll size = trunc(log10(num)) + 1
#define REVERSE(vec) reverse(vec.begin(), vec.end())
using namespace __gnu_pbds;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// code start from here
int main() {
fast;
read(a) read(b) read(c) read(d) ll sum = 0;
while (d > 0) {
if (a > 0) {
sum += 1;
a--;
} else if (b > 0) {
b--;
} else if (c > 0) {
sum -= 1;
}
d--;
}
cout << sum << endl;
return 0;
}
// ends here | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <ctype.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
#define ll long long int
#define read(a) \
long long int a; \
cin >> a;
#define readstr(s) \
string s; \
cin >> s;
#define readc(c) \
char c; \
cin >> c;
#define readarr(a, l) \
long long int a[l] = {0}; \
for (ll i = 0; i < l; i++) \
cin >> a[i];
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define rloop(i, a, b) for (ll i = a; i > b; i--)
#define loopchar() for (char c = 'a'; c <= 'z'; c++)
#define printarr(a, n) \
fori(i, 1, n) cout << a[i] << " "; \
cout << endl;
#define printv(v) \
for (int i : v) \
cout << i << " "; \
cout << endl;
#define loopitr(vec) for (auto itr = vec.begin(); itr != vec.end(); itr++)
#define ff first
#define ss second
#define readmtrx(i, j, a, b) \
ll arr[a][b] = {0}; \
for (ll i = 0; i < a; i++) \
for (ll j = 0; j < b; j++) \
cin >> arr[i][j];
#define all(a) a.begin(), a.end()
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define sc(x) cout << (#x) << " is " << (x) << endl;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0);
#define pb(p) push_back(p)
#define mp make_pair
#define fsort(vec) sort(vec.begin(), vec.end())
#define rsort(vec) sort(vec.begin(), vec.end(), compare)
#define Endl endl
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define roundoff std::cout << std::setprecision(15)
#define inf 9223372036854775807
#define infn -9223372036854775807
#define pi 3.14159265358979323846
const int mod = 1e9 + 7;
#define intsize ll size = trunc(log10(num)) + 1
#define REVERSE(vec) reverse(vec.begin(), vec.end())
using namespace __gnu_pbds;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// code start from here
int main() {
fast;
read(a) read(b) read(c) read(d) ll sum = 0;
ll m = min(a, d);
sum += m;
d -= m;
ll n = min(d, b);
sum += 0;
d -= n;
ll p = min(d, c);
sum -= p;
cout << sum << endl;
return 0;
}
// ends here | replace | 78 | 89 | 78 | 87 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long A, B, C, K;
cin >> A >> B >> C >> K;
long long sum = 0;
for (int i = 0; i < K; ++i) {
if (A > 0) {
sum++;
A--;
} else if (B > 0) {
B--;
} else if (C > 0) {
sum--;
C--;
}
}
cout << sum << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long A, B, C, K;
cin >> A >> B >> C >> K;
long long sum = 0;
if ((A + B) >= K && A < K) {
sum = A;
} else if (A >= K) {
sum = K;
} else {
sum = A - (K - A - B);
}
cout << sum << endl;
}
| replace | 7 | 18 | 7 | 13 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
int count = 0;
rep(i, a + b + c) {
rep(j, a) {
if (k == 0) {
break;
}
count++;
k--;
}
rep(j, b) {
if (k == 0) {
break;
}
k--;
}
rep(j, c) {
if (k == 0) {
break;
}
count--;
k--;
}
}
cout << count << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
int count = 0;
rep(i, k) {
rep(j, a) {
if (k == 0) {
break;
}
count++;
k--;
}
rep(j, b) {
if (k == 0) {
break;
}
k--;
}
rep(j, c) {
if (k == 0) {
break;
}
count--;
k--;
}
}
cout << count << endl;
}
| replace | 7 | 8 | 7 | 8 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int ap, a0, am, k;
cin >> ap >> a0 >> am >> k;
long long ans = 0;
for (int i = 0; i < k; i++) {
if (ap > 0) {
ap--;
ans++;
} else if (a0 > 0) {
a0--;
} else {
am--;
ans--;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int ap, a0, am, k;
cin >> ap >> a0 >> am >> k;
if (a0 == 0 && am == 0) {
cout << k << endl;
return 0;
}
long long ans = 0;
for (int i = 0; i < k; i++) {
if (ap > 0) {
ap--;
ans++;
} else if (a0 > 0) {
a0--;
} else {
am--;
ans--;
}
}
cout << ans << endl;
} | insert | 6 | 6 | 6 | 10 | TLE | |
p02683 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int a[12][12];
const int INF = 1001001001;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<int> c(n);
rep(i, n) {
cin >> c[i];
rep(j, m) cin >> a[i][j];
}
int ans = INF;
rep(s, 1 << n) {
int cost = 0;
vector<int> d(m);
rep(i, n) {
if (s >> i & 1) {
cost += c[i];
rep(j, m) d[j] += a[i][j];
}
}
bool ok = true;
rep(j, m) if (d[j] < x) ok = false;
if (ok)
ans = min(ans, cost);
}
if (ans == INF)
cout << -1 << endl;
else
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int a[12][12];
const int INF = 1001001001;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<int> c(n);
rep(i, n) {
cin >> c[i];
rep(j, m) cin >> a[i][j];
}
int ans = INF;
rep(s, 1 << n) {
int cost = 0;
vector<int> d(m);
rep(i, n) {
if (s >> i & 1) {
cost += c[i];
rep(j, m) d[j] += a[i][j];
}
}
bool ok = true;
rep(j, m) if (d[j] < x) ok = false;
if (ok)
ans = min(ans, cost);
}
if (ans == INF)
cout << -1 << endl;
else
cout << ans << endl;
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
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;
}
const long long INF = 1e18;
int n, m;
long long x;
vector<long long> C(15, 0);
vector<vector<long long>> A(15, vector<long long>(15, 0));
int main() {
cin >> n >> m >> x;
for (int i = 0; i < n; ++i) {
cin >> C.at(i);
for (int j = 0; j < m; ++j) {
cin >> A.at(i).at(j);
}
}
long long ansmin = INF;
for (int bit = 0; bit < (1 << n); ++bit) {
long long cans = 0;
vector<long long> AA(n, 0);
for (int i = 0; i < n; ++i) {
if (bit & (1 << i)) {
cans += C.at(i);
for (int j = 0; j < m; ++j) {
AA.at(j) += A.at(i).at(j);
}
}
}
bool flg = true;
for (int i = 0; i < m; ++i) {
if (AA.at(i) < x) {
flg = false;
break;
}
}
if (flg) {
chmin(ansmin, cans);
}
}
if (ansmin == INF) {
cout << -1 << endl;
} else {
cout << ansmin << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
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;
}
const long long INF = 1e18;
int n, m;
long long x;
vector<long long> C(15, 0);
vector<vector<long long>> A(15, vector<long long>(15, 0));
int main() {
cin >> n >> m >> x;
for (int i = 0; i < n; ++i) {
cin >> C.at(i);
for (int j = 0; j < m; ++j) {
cin >> A.at(i).at(j);
}
}
long long ansmin = INF;
for (int bit = 0; bit < (1 << n); ++bit) {
long long cans = 0;
vector<long long> AA(m, 0);
for (int i = 0; i < n; ++i) {
if (bit & (1 << i)) {
cans += C.at(i);
for (int j = 0; j < m; ++j) {
AA.at(j) += A.at(i).at(j);
}
}
}
bool flg = true;
for (int i = 0; i < m; ++i) {
if (AA.at(i) < x) {
flg = false;
break;
}
}
if (flg) {
chmin(ansmin, cans);
}
}
if (ansmin == INF) {
cout << -1 << endl;
} else {
cout << ansmin << endl;
}
} | replace | 35 | 36 | 35 | 36 | 0 | |
p02683 | C++ | Runtime Error | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(v) v.begin(), v.end()
typedef long long ll;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<vector<int>> a(n, vector<int>(m));
vector<int> c(m);
rep(i, n) {
cin >> c.at(i);
rep(j, m) { cin >> a.at(i).at(j); }
}
int ans = 1001001001;
rep(i, 1 << n) {
int cost = 0;
vector<int> d(m);
rep(j, n) {
if (i >> j & 1) {
cost += c.at(j);
rep(s, m) d.at(s) += a.at(j).at(s);
}
}
bool ok = true;
rep(j, m) if (d.at(j) < x) ok = false;
if (ok)
ans = min(ans, cost);
}
if (ans == 1001001001)
dunk("-1");
else
dunk(ans);
return 0;
}
| #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(v) v.begin(), v.end()
typedef long long ll;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<vector<int>> a(n, vector<int>(m));
vector<int> c(n);
rep(i, n) {
cin >> c.at(i);
rep(j, m) { cin >> a.at(i).at(j); }
}
int ans = 1001001001;
rep(i, 1 << n) {
int cost = 0;
vector<int> d(m);
rep(j, n) {
if (i >> j & 1) {
cost += c.at(j);
rep(s, m) d.at(s) += a.at(j).at(s);
}
}
bool ok = true;
rep(j, m) if (d.at(j) < x) ok = false;
if (ok)
ans = min(ans, cost);
}
if (ans == 1001001001)
dunk("-1");
else
dunk(ans);
return 0;
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p02683 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<int> c(n);
vector<vector<int>> a(n, vector<int>(n));
for (int i = 0; i < n; i++) {
cin >> c[i];
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
int ans = 1e9;
for (int i = 0; i < (1 << n); i++) {
int sum = 0;
bool flag = true;
vector<int> v(n, 0);
for (int j = 0; j < n; j++) {
if (i & (1 << j)) {
sum += c[j];
for (int k = 0; k < m; k++) {
v[k] += a[j][k];
}
}
}
for (int l = 0; l < m; l++) {
if (v[l] < x)
flag = false;
}
if (flag)
ans = min(ans, sum);
}
if (ans == 1e9)
cout << -1 << endl;
else
cout << ans << endl;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<int> c(n);
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n; i++) {
cin >> c[i];
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
int ans = 1e9;
for (int i = 0; i < (1 << n); i++) {
int sum = 0;
bool flag = true;
vector<int> v(n, 0);
for (int j = 0; j < n; j++) {
if (i & (1 << j)) {
sum += c[j];
for (int k = 0; k < m; k++) {
v[k] += a[j][k];
}
}
}
for (int l = 0; l < m; l++) {
if (v[l] < x)
flag = false;
}
if (flag)
ans = min(ans, sum);
}
if (ans == 1e9)
cout << -1 << endl;
else
cout << ans << endl;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p02683 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m, x, a, c, ans;
cin >> n >> m >> x;
vector<int> C;
vector<vector<int>> A;
for (int i = 0; i < n; i++) {
cin >> c;
C.push_back(c);
for (int j = 0; j < m; j++) {
cin >> a;
A[i][j] = a;
}
}
ans = 10000000;
int p, ok;
for (int i = 0; i < (1 << n); i++) {
p = 0;
ok = 0;
vector<int> skill(m);
for (int j = 0; j < n; j++) {
if (i & (1 << j)) {
p += C[j];
for (int k = 0; k < m; k++) {
skill[k] += A[j][k];
}
}
}
for (int l = 0; l < m; l++) {
if (skill[l] < x) {
ok = -1;
break;
}
}
if (ok == 0) {
if (p < ans) {
ans = p;
}
}
}
if (ans == 10000000) {
ans = -1;
cout << ans;
} else {
cout << ans;
}
}
| #include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m, x, a, c, ans;
cin >> n >> m >> x;
vector<int> C;
vector<vector<int>> A(n, vector<int>(m));
for (int i = 0; i < n; i++) {
cin >> c;
C.push_back(c);
for (int j = 0; j < m; j++) {
cin >> a;
A[i][j] = a;
}
}
ans = 10000000;
int p, ok;
for (int i = 0; i < (1 << n); i++) {
p = 0;
ok = 0;
vector<int> skill(m);
for (int j = 0; j < n; j++) {
if (i & (1 << j)) {
p += C[j];
for (int k = 0; k < m; k++) {
skill[k] += A[j][k];
}
}
}
for (int l = 0; l < m; l++) {
if (skill[l] < x) {
ok = -1;
break;
}
}
if (ok == 0) {
if (p < ans) {
ans = p;
}
}
}
if (ans == 10000000) {
ans = -1;
cout << ans;
} else {
cout << ans;
}
} | replace | 7 | 8 | 7 | 8 | -11 | |
p02683 | C++ | Time Limit Exceeded | #include <iostream>
#include <vector>
using namespace std;
int a[12][12];
const int INF = 1001001001;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<int> c(n);
for (int i = 0; i < n; i++) {
cin >> c[i];
for (int j = 0; j < m; j++)
cin >> a[i][j];
}
int ans = INF;
// 全ビット探索
for (int s = 0; s < n; 1 << n) {
// cost 今までの本の総額
// d 理解度
int cost = 0;
vector<int> d(m);
for (int i = 0; i < n; i++) {
// i番目の本を購入する場合
if (s >> i & 1) {
cost += c[i];
for (int j = 0; j < m; j++)
d[j] += a[i][j];
}
}
bool ok = true;
// アルゴリズムj番目の理解度がx未満なら判定を
// falseにする
for (int j = 0; j < m; j++)
if (d[j] < x)
ok = false;
if (ok)
ans = min(ans, cost);
}
if (ans == INF)
cout << -1 << endl;
else
cout << ans << endl;
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
int a[12][12];
const int INF = 1001001001;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<int> c(n);
for (int i = 0; i < n; i++) {
cin >> c[i];
for (int j = 0; j < m; j++)
cin >> a[i][j];
}
int ans = INF;
// 全ビット探索
for (int s = 0; s < 1 << n; s++) {
// cost 今までの本の総額
// d 理解度
int cost = 0;
vector<int> d(m);
for (int i = 0; i < n; i++) {
// i番目の本を購入する場合
if (s >> i & 1) {
cost += c[i];
for (int j = 0; j < m; j++)
d[j] += a[i][j];
}
}
bool ok = true;
// アルゴリズムj番目の理解度がx未満なら判定を
// falseにする
for (int j = 0; j < m; j++)
if (d[j] < x)
ok = false;
if (ok)
ans = min(ans, cost);
}
if (ans == INF)
cout << -1 << endl;
else
cout << ans << endl;
return 0;
} | replace | 19 | 20 | 19 | 20 | TLE | |
p02683 | Python | Runtime Error | n, m, x = map(int, input().split())
c = [0] * n
a = [0] * n
for i in range(n):
xs = list(map(int, input().split()))
c[i] = xs[0]
a[i] = xs[1:]
ans = 10**9
for i in range(2**n):
csum = 0
asum = [0] * n
for j in range(n):
if (i >> j) & 1:
csum += c[j]
for k in range(m):
asum[k] += a[j][k]
if len(list(filter(lambda v: v >= x, asum))) == m:
ans = min(ans, csum)
print(-1 if ans == 10**9 else ans)
| n, m, x = map(int, input().split())
c = [0] * n
a = [0] * n
for i in range(n):
xs = list(map(int, input().split()))
c[i] = xs[0]
a[i] = xs[1:]
ans = 10**9
for i in range(2**n):
csum = 0
asum = [0] * m
for j in range(n):
if (i >> j) & 1:
csum += c[j]
for k in range(m):
asum[k] += a[j][k]
if len(list(filter(lambda v: v >= x, asum))) == m:
ans = min(ans, csum)
print(-1 if ans == 10**9 else ans)
| replace | 10 | 11 | 10 | 11 | 0 | |
p02683 | C++ | Runtime Error | #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>;
const int INF = 1001001001;
int main() {
int n, m, x;
cin >> n >> m >> x;
int a[n][n];
vector<int> c(n);
rep(i, n) {
cin >> c[i];
rep(j, m) cin >> a[i][j];
}
int ans = INF;
rep(s, 1 << n) {
int cost = 0;
vector<int> d(m);
rep(i, n) {
if (s >> i & 1) {
cost += c[i];
rep(j, m) d[j] += a[i][j];
}
}
bool ok = true;
rep(j, m) if (d[j] < x) ok = false;
if (ok)
ans = min(ans, cost);
}
if (ans == INF)
cout << -1 << endl;
else
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;
using P = pair<int, int>;
const int INF = 1001001001;
int main() {
int n, m, x;
cin >> n >> m >> x;
int a[n][m];
vector<int> c(n);
rep(i, n) {
cin >> c[i];
rep(j, m) cin >> a[i][j];
}
int ans = INF;
rep(s, 1 << n) {
int cost = 0;
vector<int> d(m);
rep(i, n) {
if (s >> i & 1) {
cost += c[i];
rep(j, m) d[j] += a[i][j];
}
}
bool ok = true;
rep(j, m) if (d[j] < x) ok = false;
if (ok)
ans = min(ans, cost);
}
if (ans == INF)
cout << -1 << endl;
else
cout << ans << endl;
return 0;
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
#define repr(i, from, to) for (int(i) = (from); (i) < (to); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
// const bool debug=true;
const bool debug = false;
#define DEBUG if (debug == true)
#define all(x) begin((x)), end((x))
#define vprint(x) \
for (auto a : (x)) \
cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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;
}
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m, x;
cin >> n >> m >> x;
vector<vector<ll>> mat(n, vector<ll>(n));
vector<ll> c(n);
rep(i, n) {
cin >> c[i];
rep(j, m) { cin >> mat[i][j]; }
}
ll res = 1LL << 60;
rep(i, 1 << n) {
vector<ll> val(m, 0);
ll money = 0;
rep(j, n) {
if (i >> j & 1) {
money += c[j];
rep(k, m) { val[k] += mat[j][k]; }
}
}
// cout << i << endl;
// rep(j,n) {
// cout << val[i] << " ";
// }
// cout << endl;
// cout << "money " << money << endl;
bool flg = true;
rep(j, m) { flg &= val[j] >= x; }
if (flg) {
chmin(res, money);
}
}
cout << ((res == (1LL << 60)) ? -1 : res) << endl;
return 0;
}
| #include <bits/stdc++.h>
#define repr(i, from, to) for (int(i) = (from); (i) < (to); (i)++)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
// const bool debug=true;
const bool debug = false;
#define DEBUG if (debug == true)
#define all(x) begin((x)), end((x))
#define vprint(x) \
for (auto a : (x)) \
cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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;
}
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m, x;
cin >> n >> m >> x;
vector<vector<ll>> mat(n, vector<ll>(m));
vector<ll> c(n);
rep(i, n) {
cin >> c[i];
rep(j, m) { cin >> mat[i][j]; }
}
ll res = 1LL << 60;
rep(i, 1 << n) {
vector<ll> val(m, 0);
ll money = 0;
rep(j, n) {
if (i >> j & 1) {
money += c[j];
rep(k, m) { val[k] += mat[j][k]; }
}
}
// cout << i << endl;
// rep(j,n) {
// cout << val[i] << " ";
// }
// cout << endl;
// cout << "money " << money << endl;
bool flg = true;
rep(j, m) { flg &= val[j] >= x; }
if (flg) {
chmin(res, money);
}
}
cout << ((res == (1LL << 60)) ? -1 : res) << endl;
return 0;
}
| replace | 34 | 35 | 34 | 35 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int optimal = INT_MAX;
void call(vector<vector<int>> &v, int n, int m, int temp, int k, vector<int> tt,
int var, int cost[]) {
if (n == temp) {
int flag = 1;
for (int i = 0; i < m; i++) {
if (tt[i] < k) {
flag = 0;
break;
}
}
if (flag) {
optimal = min(optimal, var);
}
return;
}
call(v, n, m, temp + 1, k, tt, var, cost);
for (int i = 0; i < m; i++) {
tt[i] += v[temp][i];
}
call(v, n, m, temp + 1, k, tt, var + cost[temp], cost);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int n, m, k;
cin >> n >> m >> k;
vector<vector<int>> v(n, vector<int>(m));
int cost[m];
for (int i = 0; i < n; i++) {
cin >> cost[i];
for (int j = 0; j < m; j++) {
cin >> v[i][j];
}
}
vector<int> tt(m, 0);
int var = 0;
int temp = 0;
call(v, n, m, temp, k, tt, var, cost);
if (optimal == INT_MAX) {
cout << -1 << endl;
} else {
cout << optimal << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int optimal = INT_MAX;
void call(vector<vector<int>> &v, int n, int m, int temp, int k, vector<int> tt,
int var, int cost[]) {
if (n == temp) {
int flag = 1;
for (int i = 0; i < m; i++) {
if (tt[i] < k) {
flag = 0;
break;
}
}
if (flag) {
optimal = min(optimal, var);
}
return;
}
call(v, n, m, temp + 1, k, tt, var, cost);
for (int i = 0; i < m; i++) {
tt[i] += v[temp][i];
}
call(v, n, m, temp + 1, k, tt, var + cost[temp], cost);
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int n, m, k;
cin >> n >> m >> k;
vector<vector<int>> v(n, vector<int>(m));
int cost[n];
for (int i = 0; i < n; i++) {
cin >> cost[i];
for (int j = 0; j < m; j++) {
cin >> v[i][j];
}
}
vector<int> tt(m, 0);
int var = 0;
int temp = 0;
call(v, n, m, temp, k, tt, var, cost);
if (optimal == INT_MAX) {
cout << -1 << endl;
} else {
cout << optimal << endl;
}
return 0;
} | replace | 34 | 35 | 34 | 35 | -6 | terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
int main() {
int n, m, x;
cin >> n >> m >> x;
vi c(n);
vvi a(n, vi(m));
bitset<12> bb;
for (int ix = 0; ix < n; ix++) {
cin >> c.at(ix);
for (int ix2 = 0; ix2 < m; ix2++) {
cin >> a.at(ix).at(ix2);
}
}
int64_t purchase = 1000000007;
for (int ix = 0; ix < (1 << n); ix++) {
bb = ix;
bool can = true;
int64_t tmp = 0;
vi test(n, 0);
for (int ix2 = 0; ix2 < n; ix2++) {
if (bb.test(ix2)) {
tmp += c.at(ix2);
for (int ix3 = 0; ix3 < m; ix3++) {
test.at(ix3) += a.at(ix2).at(ix3);
}
}
}
for (int ix4 = 0; ix4 < m; ix4++)
if (test.at(ix4) < x)
can = false;
if (can)
purchase = min(purchase, tmp);
}
cout << (purchase != 1000000007 ? purchase : (int64_t)-1) << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
int main() {
int n, m, x;
cin >> n >> m >> x;
vi c(n);
vvi a(n, vi(m));
bitset<12> bb;
for (int ix = 0; ix < n; ix++) {
cin >> c.at(ix);
for (int ix2 = 0; ix2 < m; ix2++) {
cin >> a.at(ix).at(ix2);
}
}
int64_t purchase = 1000000007;
for (int ix = 0; ix < (1 << n); ix++) {
bb = ix;
bool can = true;
int64_t tmp = 0;
vi test(m, 0);
for (int ix2 = 0; ix2 < n; ix2++) {
if (bb.test(ix2)) {
tmp += c.at(ix2);
for (int ix3 = 0; ix3 < m; ix3++) {
test.at(ix3) += a.at(ix2).at(ix3);
}
}
}
for (int ix4 = 0; ix4 < m; ix4++)
if (test.at(ix4) < x)
can = false;
if (can)
purchase = min(purchase, tmp);
}
cout << (purchase != 1000000007 ? purchase : (int64_t)-1) << endl;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p02683 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int n, m, x;
int c[15];
int res = 1e9;
int a[15][15];
vector<int> ans;
void f(int i) {
// cout << i << endl;
if (i == n) {
vector<int> A(n, 0);
int sum = 0;
for (int j = 0; j < ans.size(); j++) {
sum += c[ans[j]];
for (int k = 0; k < m; k++) {
A[k] += a[ans[j]][k];
}
}
for (int j = 0; j < m; j++) {
if (A[j] < x) {
return;
}
}
res = min(res, sum);
return;
}
ans.push_back(i);
f(i + 1);
ans.pop_back();
f(i + 1);
return;
}
int main() {
cin >> n >> m >> x;
for (int i = 0; i < n; i++) {
cin >> c[i];
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
// cout << "Iji2" << endl;
f(0);
if (res == 1e9) {
cout << -1 << endl;
} else
cout << res << endl;
} | #include <iostream>
#include <vector>
using namespace std;
int n, m, x;
int c[15];
int res = 1e9;
int a[15][15];
vector<int> ans;
void f(int i) {
// cout << i << endl;
if (i == n) {
vector<int> A(m, 0);
int sum = 0;
for (int j = 0; j < ans.size(); j++) {
sum += c[ans[j]];
for (int k = 0; k < m; k++) {
A[k] += a[ans[j]][k];
}
}
for (int j = 0; j < m; j++) {
if (A[j] < x) {
return;
}
}
res = min(res, sum);
return;
}
ans.push_back(i);
f(i + 1);
ans.pop_back();
f(i + 1);
return;
}
int main() {
cin >> n >> m >> x;
for (int i = 0; i < n; i++) {
cin >> c[i];
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
// cout << "Iji2" << endl;
f(0);
if (res == 1e9) {
cout << -1 << endl;
} else
cout << res << endl;
} | replace | 14 | 15 | 14 | 15 | 0 | |
p02683 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 1000000007;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<int> c(n);
vector<vector<int>> a(n, vector<int>(m, 0));
for (int i = 0; i < n; i++) {
cin >> c[i];
for (int j = 0; j < m; j++)
cin >> a[i][j];
}
int ans = INF;
for (int bit = 1; bit << (1 << n); bit++) {
vector<int> u(m, 0);
int sum = 0;
for (int i = 0; i < n; i++) {
if ((bit >> i) & 1) {
sum += c[i];
for (int j = 0; j < m; j++)
u[j] += a[i][j];
}
}
bool f = true;
for (int j = 0; j < m; j++) {
if (u[j] < x)
f = false;
}
if (f)
ans = min(sum, ans);
}
if (ans == INF) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 1000000007;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<int> c(n);
vector<vector<int>> a(n, vector<int>(m, 0));
for (int i = 0; i < n; i++) {
cin >> c[i];
for (int j = 0; j < m; j++)
cin >> a[i][j];
}
int ans = INF;
for (int bit = 1; bit < (1 << n); bit++) {
vector<int> u(m, 0);
int sum = 0;
for (int i = 0; i < n; i++) {
if ((bit >> i) & 1) {
sum += c[i];
for (int j = 0; j < m; j++)
u[j] += a[i][j];
}
}
bool f = true;
for (int j = 0; j < m; j++) {
if (u[j] < x)
f = false;
}
if (f)
ans = min(sum, ans);
}
if (ans == INF) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
return 0;
} | replace | 17 | 18 | 17 | 18 | TLE | |
p02683 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int c[13], a[13][13];
int main() {
ios::sync_with_stdio(false);
int n, m, x, maxx = 10000000, k, sf = 0;
cin >> n >> m >> x;
for (int i = 1; i <= n; i++) {
cin >> c[i];
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
int book[n + 1], understand[m + 1], pd = 0, dj = 0;
for (int i = 1; i <= n; i++) {
book[i] = 0;
}
while (book[0] != 1) {
for (int i = 1; i <= m; i++) {
understand[i] = 0;
}
dj = 0;
pd = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (book[i] == 1)
understand[j] += a[i][j];
}
}
for (int i = 1; i <= m; i++) {
if (understand[i] < x)
pd = 1;
}
for (int i = 1; i <= n; i++)
if (book[i] == 1)
dj += c[i];
if (pd == 0 && dj <= maxx) {
maxx = dj;
sf = 1;
}
int k = n;
while (book[k] != 0) {
k--;
}
book[k] = 1;
for (int i = k + 1; i <= n; i++) {
book[i] == 0;
}
}
if (sf == 0)
cout << "-1";
else
cout << maxx;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int c[13], a[13][13];
int main() {
ios::sync_with_stdio(false);
int n, m, x, maxx = 10000000, k, sf = 0;
cin >> n >> m >> x;
for (int i = 1; i <= n; i++) {
cin >> c[i];
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
int book[n + 1], understand[m + 1], pd = 0, dj = 0;
for (int i = 1; i <= n; i++) {
book[i] = 0;
}
while (book[0] != 1) {
for (int i = 1; i <= m; i++) {
understand[i] = 0;
}
dj = 0;
pd = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (book[i] == 1)
understand[j] += a[i][j];
}
}
for (int i = 1; i <= m; i++) {
if (understand[i] < x)
pd = 1;
}
for (int i = 1; i <= n; i++)
if (book[i] == 1)
dj += c[i];
if (pd == 0 && dj <= maxx) {
maxx = dj;
sf = 1;
}
int k = n;
while (book[k] != 0) {
k--;
}
book[k] = 1;
for (int i = k + 1; i <= n; i++) {
book[i] = 0;
}
}
if (sf == 0)
cout << "-1";
else
cout << maxx;
return 0;
} | replace | 47 | 48 | 47 | 48 | TLE | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define F first
#define S second
using namespace std;
ll MOD = 1000000007;
int ans = INT_MAX;
int fd = -1;
int n, m, x;
void back(int cost, int ind, vector<vector<int>> &mp, vector<int> &c,
vector<int> vals) {
int f = 1;
for (int i = 0; i < m; i++) {
if (vals[i] < x) {
f = 0;
break;
}
}
// cout<<ind<<" "<<f<<endl;
if (f == 1) {
ans = min(ans, cost);
fd = 1;
}
if (ind == n)
return;
cost += c[ind];
for (int i = 0; i < m; i++) {
vals[i] += mp[ind][i];
}
back(cost, ind + 1, mp, c, vals);
cost -= c[ind];
for (int i = 0; i < m; i++) {
vals[i] -= mp[ind][i];
}
back(cost, ind + 1, mp, c, vals);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> x;
vector<int> c(n, 0);
vector<int> t(m, 0);
vector<vector<int>> mp(n, t);
for (int i = 0; i < n; i++) {
cin >> c[i];
for (int j = 0; j < m; j++)
cin >> mp[i][j];
}
vector<int> vals(n, 0);
back(0, 0, mp, c, vals);
if (fd == -1)
ans = -1;
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define F first
#define S second
using namespace std;
ll MOD = 1000000007;
int ans = INT_MAX;
int fd = -1;
int n, m, x;
void back(int cost, int ind, vector<vector<int>> &mp, vector<int> &c,
vector<int> vals) {
int f = 1;
for (int i = 0; i < m; i++) {
if (vals[i] < x) {
f = 0;
break;
}
}
// cout<<ind<<" "<<f<<endl;
if (f == 1) {
ans = min(ans, cost);
fd = 1;
}
if (ind == n)
return;
cost += c[ind];
for (int i = 0; i < m; i++) {
vals[i] += mp[ind][i];
}
back(cost, ind + 1, mp, c, vals);
cost -= c[ind];
for (int i = 0; i < m; i++) {
vals[i] -= mp[ind][i];
}
back(cost, ind + 1, mp, c, vals);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> x;
vector<int> c(n, 0);
vector<int> t(m, 0);
vector<vector<int>> mp(n, t);
for (int i = 0; i < n; i++) {
cin >> c[i];
for (int j = 0; j < m; j++)
cin >> mp[i][j];
}
vector<int> vals(m, 0);
back(0, 0, mp, c, vals);
if (fd == -1)
ans = -1;
cout << ans << endl;
return 0;
} | replace | 51 | 52 | 51 | 52 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
#define trav(container, it) \
for (typeof(container.begin()) it = container.begin(); \
it != container.end(); it++)
const int MOD = 1000000007;
const char nl = '\n';
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, x;
cin >> n >> m >> x;
vvi v(n);
vi c(n);
int temp;
FOR(i, 0, n) {
cin >> c[i];
FOR(j, 0, m) {
cin >> temp;
v[j].pb(temp);
}
}
ll count, sum, res = INT_MAX;
bool flag;
FOR(mask, 1, pow(2, n)) {
count = 0;
sum = 0;
flag = true;
FOR(j, 0, n) {
if (mask & (1 << j))
count += v[0][j], sum += c[j];
}
if (count >= x) {
FOR(l, 1, m) {
count = 0;
FOR(j, 0, n) {
if (mask & (1 << j)) {
count += v[l][j];
}
}
if (count < x) {
flag = false;
break;
}
}
if (flag)
res = min(res, sum);
}
}
if (res == INT_MAX)
cout << -1;
else
cout << res;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
#define trav(container, it) \
for (typeof(container.begin()) it = container.begin(); \
it != container.end(); it++)
const int MOD = 1000000007;
const char nl = '\n';
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, x;
cin >> n >> m >> x;
vvi v;
if (n > m)
v.resize(n);
else
v.resize(m);
vi c(n);
int temp;
FOR(i, 0, n) {
cin >> c[i];
FOR(j, 0, m) {
cin >> temp;
v[j].pb(temp);
}
}
ll count, sum, res = INT_MAX;
bool flag;
FOR(mask, 1, pow(2, n)) {
count = 0;
sum = 0;
flag = true;
FOR(j, 0, n) {
if (mask & (1 << j))
count += v[0][j], sum += c[j];
}
if (count >= x) {
FOR(l, 1, m) {
count = 0;
FOR(j, 0, n) {
if (mask & (1 << j)) {
count += v[l][j];
}
}
if (count < x) {
flag = false;
break;
}
}
if (flag)
res = min(res, sum);
}
}
if (res == INT_MAX)
cout << -1;
else
cout << res;
}
| replace | 44 | 45 | 44 | 50 | 0 | |
p02683 | C++ | Runtime Error | // include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
// typedef
//------------------------------------------
typedef long long LL;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef vector<VI> VVI;
typedef vector<VB> VVB;
typedef vector<VS> VVS;
typedef vector<VLL> VVLL;
typedef vector<VVI> VVVI;
typedef vector<VVLL> VVVLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, string> PIS;
typedef pair<string, int> PSI;
typedef pair<string, string> PSS;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<VPII> VVPII;
typedef vector<VPLL> VVPLL;
typedef vector<VS> VVS;
typedef map<int, int> MII;
typedef map<LL, LL> MLL;
typedef map<string, int> MSI;
typedef map<int, string> MIS;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define EACH(i, arr) \
for (typeof((arr).begin()) i = (arr).begin(); i != (arr).end(); ++i)
#define EXIST(str, e) ((str).find(e) != (str).end())
#define COUNT(arr, v) count((arr).begin(), (arr).end(), v)
#define SEARCH(v, w) search((v).begin(), (v).end(), (w).begin(), (w).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define ROTATE_LEFT(arr, c) \
rotate((arr).begin(), (arr).begin() + (c), (arr).end())
#define ROTATE_RIGHT(arr, c) \
rotate((arr).rbegin(), (arr).rbegin() + (c), (arr).rend())
#define SUMI(arr) accumulate((arr).begin(), (arr).end(), 0)
#define SUMD(arr) accumulate((arr).begin(), (arr).end(), 0.)
#define SUMLL(arr) accumulate((arr).begin(), (arr).end(), 0LL)
#define MULD(arr) \
accumulate((arr).begin(), (arr).end(), 1., multiplies<double>())
#define UB(arr, n) upper_bound((arr).begin(), (arr).end(), n)
#define LB(arr, n) lower_bound((arr).begin(), (arr).end(), n)
#define PB push_back
#define MP make_pair
#define ft first
#define sd second
// input output
//------------------------------------------
#define GL(s) getline(cin, (s))
#define INIT() \
std::ios::sync_with_stdio(false); \
std::cin.tie(0)
#define OUT(d) std::cout << (d)
#define OUT_L(d) std::cout << (d) << endl
#define FOUT(n, data) std::cout << std::fixed << std::setprecision(n) << (data)
#define FOUT_L(n, data) \
std::cout << std::fixed << std::setprecision(n) << (data) << "\n"
#define EL() printf("\n")
#define SHOW_VECTOR(v) \
{ \
std::cerr << #v << "\t:"; \
for (const auto &xxx : v) { \
std::cerr << xxx << " "; \
} \
std::cerr << "\n"; \
}
#define SHOW_MAP(v) \
{ \
std::cerr << #v << endl; \
for (const auto &xxx : v) { \
std::cerr << xxx.first << " " << xxx.second << "\n"; \
} \
}
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yay() printf("Yay!\n")
#define Nnn() printf(":(\n")
#define CE(x, y) ((x + y - 1) / (y))
template <typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
}
template <typename T> istream &operator>>(istream &in, vector<T> &v) {
for (auto &x : v)
in >> x;
return in;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]"
<< "\n";
return out;
}
template <class T1, class T2> inline bool chmin(T1 &a, T2 b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T1, class T2> inline bool chmax(T1 &a, T2 b) {
if (a < b) {
a = b;
return true;
}
return false;
}
// repetition
//------------------------------------------
#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(i, 0, n)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FORLL(i, a, b) for (LL i = LL(a); i < LL(b); ++i)
#define RFORLL(i, a, b) for (LL i = LL(b) - 1; i >= LL(a); --i)
#define REPLL(i, n) for (LL i = 0; i < LL(n); ++i)
#define RREPLL(i, n) for (LL i = LL(n) - 1; i >= 0; --i)
#define FOREACH(x, arr) for (auto &(x) : (arr))
// Option + Control + K Terminal
// Command + Control + K Run
// Command + b EOF
//------------------------------------------
//------------------------------------------
int main() {
LL N, M, X;
cin >> N >> M >> X;
vector<LL> C(N);
VVLL A(N, VLL(N));
REP(i, N) {
cin >> C[i];
REP(j, M) cin >> A[i][j];
}
LL ans = LLONG_MAX;
for (LL bit = 0; bit < (1 << N); bit++) {
vector<LL> skills(M, 0);
LL cost = 0;
for (LL i = 0; i < N; i++) {
if (bit & (1LL << i)) {
cost += C[i];
for (LL j = 0; j < M; j++) {
skills[j] += A[i][j];
}
}
}
bool good = true;
for (int i = 0; i < M; i++)
if (skills[i] < X)
good = false;
if (good)
chmin(ans, cost);
}
if (ans == LLONG_MAX)
cout << -1 << endl;
else
cout << ans << endl;
}
| // include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
// typedef
//------------------------------------------
typedef long long LL;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef vector<VI> VVI;
typedef vector<VB> VVB;
typedef vector<VS> VVS;
typedef vector<VLL> VVLL;
typedef vector<VVI> VVVI;
typedef vector<VVLL> VVVLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, string> PIS;
typedef pair<string, int> PSI;
typedef pair<string, string> PSS;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<VPII> VVPII;
typedef vector<VPLL> VVPLL;
typedef vector<VS> VVS;
typedef map<int, int> MII;
typedef map<LL, LL> MLL;
typedef map<string, int> MSI;
typedef map<int, string> MIS;
// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define EACH(i, arr) \
for (typeof((arr).begin()) i = (arr).begin(); i != (arr).end(); ++i)
#define EXIST(str, e) ((str).find(e) != (str).end())
#define COUNT(arr, v) count((arr).begin(), (arr).end(), v)
#define SEARCH(v, w) search((v).begin(), (v).end(), (w).begin(), (w).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define ROTATE_LEFT(arr, c) \
rotate((arr).begin(), (arr).begin() + (c), (arr).end())
#define ROTATE_RIGHT(arr, c) \
rotate((arr).rbegin(), (arr).rbegin() + (c), (arr).rend())
#define SUMI(arr) accumulate((arr).begin(), (arr).end(), 0)
#define SUMD(arr) accumulate((arr).begin(), (arr).end(), 0.)
#define SUMLL(arr) accumulate((arr).begin(), (arr).end(), 0LL)
#define MULD(arr) \
accumulate((arr).begin(), (arr).end(), 1., multiplies<double>())
#define UB(arr, n) upper_bound((arr).begin(), (arr).end(), n)
#define LB(arr, n) lower_bound((arr).begin(), (arr).end(), n)
#define PB push_back
#define MP make_pair
#define ft first
#define sd second
// input output
//------------------------------------------
#define GL(s) getline(cin, (s))
#define INIT() \
std::ios::sync_with_stdio(false); \
std::cin.tie(0)
#define OUT(d) std::cout << (d)
#define OUT_L(d) std::cout << (d) << endl
#define FOUT(n, data) std::cout << std::fixed << std::setprecision(n) << (data)
#define FOUT_L(n, data) \
std::cout << std::fixed << std::setprecision(n) << (data) << "\n"
#define EL() printf("\n")
#define SHOW_VECTOR(v) \
{ \
std::cerr << #v << "\t:"; \
for (const auto &xxx : v) { \
std::cerr << xxx << " "; \
} \
std::cerr << "\n"; \
}
#define SHOW_MAP(v) \
{ \
std::cerr << #v << endl; \
for (const auto &xxx : v) { \
std::cerr << xxx.first << " " << xxx.second << "\n"; \
} \
}
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yay() printf("Yay!\n")
#define Nnn() printf(":(\n")
#define CE(x, y) ((x + y - 1) / (y))
template <typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
}
template <typename T> istream &operator>>(istream &in, vector<T> &v) {
for (auto &x : v)
in >> x;
return in;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]"
<< "\n";
return out;
}
template <class T1, class T2> inline bool chmin(T1 &a, T2 b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T1, class T2> inline bool chmax(T1 &a, T2 b) {
if (a < b) {
a = b;
return true;
}
return false;
}
// repetition
//------------------------------------------
#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(i, 0, n)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FORLL(i, a, b) for (LL i = LL(a); i < LL(b); ++i)
#define RFORLL(i, a, b) for (LL i = LL(b) - 1; i >= LL(a); --i)
#define REPLL(i, n) for (LL i = 0; i < LL(n); ++i)
#define RREPLL(i, n) for (LL i = LL(n) - 1; i >= 0; --i)
#define FOREACH(x, arr) for (auto &(x) : (arr))
// Option + Control + K Terminal
// Command + Control + K Run
// Command + b EOF
//------------------------------------------
//------------------------------------------
int main() {
LL N, M, X;
cin >> N >> M >> X;
vector<LL> C(N);
VVLL A(N, VLL(M));
REP(i, N) {
cin >> C[i];
REP(j, M) cin >> A[i][j];
}
LL ans = LLONG_MAX;
for (LL bit = 0; bit < (1 << N); bit++) {
vector<LL> skills(M, 0);
LL cost = 0;
for (LL i = 0; i < N; i++) {
if (bit & (1LL << i)) {
cost += C[i];
for (LL j = 0; j < M; j++) {
skills[j] += A[i][j];
}
}
}
bool good = true;
for (int i = 0; i < M; i++)
if (skills[i] < X)
good = false;
if (good)
chmin(ans, cost);
}
if (ans == LLONG_MAX)
cout << -1 << endl;
else
cout << ans << endl;
}
| replace | 191 | 192 | 191 | 192 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
// #define ll long long
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int(i) = (int)(n)-1; (i) >= 0; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define all(x) (x).begin(), (x).end()
ll t1, t2, t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
ll n, m, x;
vector<vector<ll>> vec(12, vector<ll>(12, 0));
vector<ll> c(12);
ll ans = INFLONG;
void dfs(ll num, ll cost, vector<ll> arr) {
// cout << num << endl;
if (num == n) {
bool can = true;
rep(i, m) {
if (arr[i] < x) {
can = false;
}
}
if (can) {
chmin(ans, cost);
}
return;
}
dfs(num + 1, cost, arr);
rep(i, m) { arr[i] += vec[num][i]; }
dfs(num + 1, cost + c[num], arr);
}
int main() {
cin >> n >> m >> x;
rep(i, n) {
cin >> c[i];
rep(j, m) { cin >> vec[i][j]; }
}
vector<ll> arr(n, 0);
dfs(0, 0, arr);
if (ans == INFLONG) {
ans = -1;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
// #define ll long long
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int(i) = (int)(n)-1; (i) >= 0; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define all(x) (x).begin(), (x).end()
ll t1, t2, t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
ll n, m, x;
vector<vector<ll>> vec(12, vector<ll>(12, 0));
vector<ll> c(12);
ll ans = INFLONG;
void dfs(ll num, ll cost, vector<ll> arr) {
// cout << num << endl;
if (num == n) {
bool can = true;
rep(i, m) {
if (arr[i] < x) {
can = false;
}
}
if (can) {
chmin(ans, cost);
}
return;
}
dfs(num + 1, cost, arr);
rep(i, m) { arr[i] += vec[num][i]; }
dfs(num + 1, cost + c[num], arr);
}
int main() {
cin >> n >> m >> x;
rep(i, n) {
cin >> c[i];
rep(j, m) { cin >> vec[i][j]; }
}
vector<ll> arr(m, 0);
dfs(0, 0, arr);
if (ans == INFLONG) {
ans = -1;
}
cout << ans << endl;
} | replace | 60 | 61 | 60 | 61 | 0 | |
p02683 | C++ | Runtime Error | #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 n, m, x;
cin >> n >> m >> x;
vector<int> C(12);
vector<vector<int>> pa(n, vector<int>(m));
rep(i, n) {
cin >> C.at(i);
rep(j, m) { cin >> pa.at(i).at(j); }
}
int ans = 100100100;
int count = 0;
for (int tmp = 0; tmp < (1 << 12); tmp++) {
bitset<12> s(tmp);
// (ビット列sに対する処理)
count = 0;
vector<int> Ans(n);
rep(i, n) {
if (s.test(i)) {
count += C.at(i);
rep(j, m) { Ans.at(j) += pa.at(i).at(j); }
}
}
bool can = true;
rep(i, m) {
if (Ans.at(i) < x) {
can = false;
}
}
if (can) {
ans = min(count, ans);
}
}
if (ans == 100100100) {
cout << -1 << endl;
} else
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 n, m, x;
cin >> n >> m >> x;
vector<int> C(12);
vector<vector<int>> pa(n, vector<int>(m));
rep(i, n) {
cin >> C.at(i);
rep(j, m) { cin >> pa.at(i).at(j); }
}
int ans = 100100100;
int count = 0;
for (int tmp = 0; tmp < (1 << 12); tmp++) {
bitset<12> s(tmp);
// (ビット列sに対する処理)
count = 0;
vector<int> Ans(m);
rep(i, n) {
if (s.test(i)) {
count += C.at(i);
rep(j, m) { Ans.at(j) += pa.at(i).at(j); }
}
}
bool can = true;
rep(i, m) {
if (Ans.at(i) < x) {
can = false;
}
}
if (can) {
ans = min(count, ans);
}
}
if (ans == 100100100) {
cout << -1 << endl;
} else
cout << ans << endl;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p02683 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<int> c(n);
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n; ++i) {
cin >> c.at(i);
for (int j = 0; j < m; ++j) {
cin >> a.at(i).at(j);
}
}
int ans = 1000000000;
for (int i = 0; i <= (1 << n) - 1; ++i) {
int sum_c = 0;
vector<int> sum_a(n, 0);
for (int j = 0; j < n; ++j) {
if (i >> j & 1) {
sum_c += c.at(j);
for (int k = 0; k < m; ++k) {
sum_a.at(k) += a.at(j).at(k);
}
}
}
bool f = true;
for (int k = 0; k < m; ++k) {
if (sum_a.at(k) < x) {
f = false;
break;
}
}
if (f && sum_c < ans) {
ans = sum_c;
}
}
if (ans == 1000000000) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
return 0;
}
| #include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<int> c(n);
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n; ++i) {
cin >> c.at(i);
for (int j = 0; j < m; ++j) {
cin >> a.at(i).at(j);
}
}
int ans = 1000000000;
for (int i = 0; i <= (1 << n) - 1; ++i) {
int sum_c = 0;
vector<int> sum_a(m, 0);
for (int j = 0; j < n; ++j) {
if (i >> j & 1) {
sum_c += c.at(j);
for (int k = 0; k < m; ++k) {
sum_a.at(k) += a.at(j).at(k);
}
}
}
bool f = true;
for (int k = 0; k < m; ++k) {
if (sum_a.at(k) < x) {
f = false;
break;
}
}
if (f && sum_c < ans) {
ans = sum_c;
}
}
if (ans == 1000000000) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
return 0;
}
| replace | 20 | 21 | 20 | 21 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<vector<ll>> a(n);
vector<ll> c(n);
ll ans = (1 << 29);
for (int i = 0; i < n; i++) {
cin >> c.at(i);
a.at(i).resize(m);
for (int j = 0; j < m; j++) {
cin >> a.at(i).at(j);
}
}
for (int i = 0; i < (1 << n); i++) {
ll sum = 0;
vector<ll> d(n);
for (int j = 0; j < n; j++) {
if ((i >> j) & 1) {
for (int k = 0; k < m; k++) {
d.at(k) += a.at(j).at(k);
}
sum += c.at(j);
}
}
bool flg = true;
for (int k = 0; k < m; k++) {
if (d.at(k) < x) {
flg = false;
}
}
if (flg) {
ans = min(ans, sum);
}
}
if (ans == (1 << 29)) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<vector<ll>> a(n);
vector<ll> c(n);
ll ans = (1 << 29);
for (int i = 0; i < n; i++) {
cin >> c.at(i);
a.at(i).resize(m);
for (int j = 0; j < m; j++) {
cin >> a.at(i).at(j);
}
}
for (int i = 0; i < (1 << n); i++) {
ll sum = 0;
vector<ll> d(m);
for (int j = 0; j < n; j++) {
if ((i >> j) & 1) {
for (int k = 0; k < m; k++) {
d.at(k) += a.at(j).at(k);
}
sum += c.at(j);
}
}
bool flg = true;
for (int k = 0; k < m; k++) {
if (d.at(k) < x) {
flg = false;
}
}
if (flg) {
ans = min(ans, sum);
}
}
if (ans == (1 << 29)) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
return 0;
} | replace | 20 | 21 | 20 | 21 | 0 | |
p02683 | C++ | Time Limit Exceeded | /*
Mbak Sana Dong
Mbak Chaeyoung Dong
*/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
vector<int> vi[105];
int cost[105];
int main() {
int n, i, j, k, x, y, ans, curr, temp, m;
int tc;
cin >> n >> m >> x;
for (i = 1; i <= n; i++) {
cin >> cost[i];
for (j = 1; j <= m; j++) {
cin >> curr;
vi[i].push_back(curr);
}
}
int chaeng = 1e9;
int maxi = 1 << n;
for (i = 0; i < maxi; i++) {
curr = 0;
int master[n + 5];
memset(master, 0, sizeof(master));
for (j = 0; j < n; j++) {
if (i & (1 << j)) {
curr += cost[j + 1];
for (k = 0; k < m; k++) {
master[k] += vi[j + 1][k];
}
}
}
int mini = 1e9;
for (j = 0; j < m; j++) {
mini = min(mini, master[j]);
}
if (mini >= x) {
chaeng = min(chaeng, curr);
}
}
if (chaeng == 1e9)
cout << "-1";
else
cout << chaeng;
cout << endl;
return 0;
}
| /*
Mbak Sana Dong
Mbak Chaeyoung Dong
*/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
vector<int> vi[105];
int cost[105];
int main() {
int n, i, j, k, x, y, ans, curr, temp, m;
int tc;
cin >> n >> m >> x;
for (i = 1; i <= n; i++) {
cin >> cost[i];
for (j = 1; j <= m; j++) {
cin >> curr;
vi[i].push_back(curr);
}
}
int chaeng = 1e9;
int maxi = 1 << n;
for (i = 0; i < maxi; i++) {
curr = 0;
int master[m + 2];
memset(master, 0, sizeof(master));
for (j = 0; j < n; j++) {
if (i & (1 << j)) {
curr += cost[j + 1];
for (k = 0; k < m; k++) {
master[k] += vi[j + 1][k];
}
}
}
int mini = 1e9;
for (j = 0; j < m; j++) {
mini = min(mini, master[j]);
}
if (mini >= x) {
chaeng = min(chaeng, curr);
}
}
if (chaeng == 1e9)
cout << "-1";
else
cout << chaeng;
cout << endl;
return 0;
}
| replace | 24 | 25 | 24 | 25 | TLE | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long n, t, a, b, c, m, x, mi, aux;
cin >> n >> m >> x;
deque<long> A[n];
long R[n];
long au[n];
for (int i = 0; i < n; i++) {
cin >> R[i];
for (int l = 0; l < m; l++) {
cin >> a;
A[i].push_back(a);
}
}
mi = 10000000;
for (int i = 0; i < (1 << n); i++) {
memset(au, 0, sizeof(au));
c = 0;
aux = 0;
for (int j = 0; j < n; j++) {
if (i & (1 << j)) {
aux = aux + R[j];
for (int l = 0; l < m; l++) {
if (au[l] != -1)
au[l] = au[l] + A[j][l];
if (au[l] >= x) {
au[l] = -1;
c++;
}
}
}
}
if (c == m)
mi = min(mi, aux);
}
if (mi == 10000000)
cout << "-1" << endl;
else
cout << mi << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long n, t, a, b, c, m, x, mi, aux;
cin >> n >> m >> x;
deque<long> A[n];
long R[n];
long au[m];
for (int i = 0; i < n; i++) {
cin >> R[i];
for (int l = 0; l < m; l++) {
cin >> a;
A[i].push_back(a);
}
}
mi = 10000000;
for (int i = 0; i < (1 << n); i++) {
memset(au, 0, sizeof(au));
c = 0;
aux = 0;
for (int j = 0; j < n; j++) {
if (i & (1 << j)) {
aux = aux + R[j];
for (int l = 0; l < m; l++) {
if (au[l] != -1)
au[l] = au[l] + A[j][l];
if (au[l] >= x) {
au[l] = -1;
c++;
}
}
}
}
if (c == m)
mi = min(mi, aux);
}
if (mi == 10000000)
cout << "-1" << endl;
else
cout << mi << endl;
return 0;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p02683 | C++ | Runtime Error | /**
* @copyright (c) 2020 Daisuke Hashimoto
*/
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;
int32_t N, M, X;
int32_t book_cost[12];
int32_t A[12][12];
int32_t minimum_cost;
int32_t look_up[1 << 11];
int32_t Decode(const int32_t tried_book, vector<bool> book_studied) {
book_studied[tried_book] = true;
int32_t decoded = 0;
for (int32_t i = 0; i < N; ++i) {
decoded += (book_studied[i] ? 1 : 0);
decoded *= 2;
}
return decoded;
}
void Dfs(const int32_t target_book, const int32_t cost_so_far,
vector<int32_t> rikaido, vector<bool> book_studied) {
for (int32_t j = 0; j < M; ++j) {
rikaido[j] += A[target_book][j];
}
book_studied[target_book] = true;
bool done = true;
for (const int32_t r : rikaido) {
done = done && (r >= X);
}
const int32_t c_cost = cost_so_far + book_cost[target_book];
if (done) {
if (c_cost < minimum_cost) {
minimum_cost = c_cost;
}
return;
}
for (int32_t i = 0; i < N; ++i) {
if (!book_studied[i] && (c_cost + book_cost[i] < minimum_cost)) {
int32_t decoded = Decode(i, book_studied);
if (look_up[decoded] == 0) {
look_up[decoded] = 1;
Dfs(i, c_cost, rikaido, book_studied);
}
}
}
}
int main() {
minimum_cost = INT32_MAX;
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cin >> N >> M >> X;
for (int32_t i = 0; i < N; ++i) {
cin >> book_cost[i];
for (int32_t j = 0; j < M; ++j) {
cin >> A[i][j];
}
}
vector<int32_t> rikaido(M, 0);
vector<bool> book_studied(N, false);
for (int32_t i = 0; i < N; ++i) {
Dfs(i, 0, rikaido, book_studied);
}
if (minimum_cost != INT32_MAX) {
cout << minimum_cost << endl;
} else {
cout << -1 << endl;
}
return 0;
}
| /**
* @copyright (c) 2020 Daisuke Hashimoto
*/
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;
int32_t N, M, X;
int32_t book_cost[12];
int32_t A[12][12];
int32_t minimum_cost;
int32_t look_up[1 << 13];
int32_t Decode(const int32_t tried_book, vector<bool> book_studied) {
book_studied[tried_book] = true;
int32_t decoded = 0;
for (int32_t i = 0; i < N; ++i) {
decoded += (book_studied[i] ? 1 : 0);
decoded *= 2;
}
return decoded;
}
void Dfs(const int32_t target_book, const int32_t cost_so_far,
vector<int32_t> rikaido, vector<bool> book_studied) {
for (int32_t j = 0; j < M; ++j) {
rikaido[j] += A[target_book][j];
}
book_studied[target_book] = true;
bool done = true;
for (const int32_t r : rikaido) {
done = done && (r >= X);
}
const int32_t c_cost = cost_so_far + book_cost[target_book];
if (done) {
if (c_cost < minimum_cost) {
minimum_cost = c_cost;
}
return;
}
for (int32_t i = 0; i < N; ++i) {
if (!book_studied[i] && (c_cost + book_cost[i] < minimum_cost)) {
int32_t decoded = Decode(i, book_studied);
if (look_up[decoded] == 0) {
look_up[decoded] = 1;
Dfs(i, c_cost, rikaido, book_studied);
}
}
}
}
int main() {
minimum_cost = INT32_MAX;
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cin >> N >> M >> X;
for (int32_t i = 0; i < N; ++i) {
cin >> book_cost[i];
for (int32_t j = 0; j < M; ++j) {
cin >> A[i][j];
}
}
vector<int32_t> rikaido(M, 0);
vector<bool> book_studied(N, false);
for (int32_t i = 0; i < N; ++i) {
Dfs(i, 0, rikaido, book_studied);
}
if (minimum_cost != INT32_MAX) {
cout << minimum_cost << endl;
} else {
cout << -1 << endl;
}
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02683 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const double INT_MAX = 2147483647;
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rrep(i, n) RREP(i, 0, n)
#define RREP(i, x, n) for (int i = (int)(n)-1 - (int)(x); i >= 0; i--)
void printv(vector<int> v) {
for (auto it = v.begin(); it != v.end(); it++) {
cout << *it << ",";
}
cout << endl;
}
int N, M, X;
vector<int> c(13);
vector<vector<int>> a(13, vector<int>(13));
int res = INT_MAX;
void rec(vector<int> s, int d, int sum) {
// cout<<"d:"<<d<<" sum:"<<sum<<endl;
// printv(s);
if (d == N + 1)
return;
bool r = true;
rep(i, M) {
if (s[i] < X)
r = false;
}
if (r && res > sum)
res = sum;
// dばんめを選ばない場合
rec(s, d + 1, sum);
// 選ぶ場合
if (r)
return;
rep(i, M) { s[i] += a[d][i]; }
rec(s, d + 1, sum + c[d]);
}
int main(void) {
// Your code here!
cin >> N >> M >> X;
rep(i, N) {
cin >> c[i];
rep(j, M) { cin >> a[i][j]; }
}
vector<int> s(N);
rec(s, 0, 0);
if (res == INT_MAX)
cout << "-1";
else
cout << res;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const double INT_MAX = 2147483647;
#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rrep(i, n) RREP(i, 0, n)
#define RREP(i, x, n) for (int i = (int)(n)-1 - (int)(x); i >= 0; i--)
void printv(vector<int> v) {
for (auto it = v.begin(); it != v.end(); it++) {
cout << *it << ",";
}
cout << endl;
}
int N, M, X;
vector<int> c(13);
vector<vector<int>> a(13, vector<int>(13));
int res = INT_MAX;
void rec(vector<int> s, int d, int sum) {
// cout<<"d:"<<d<<" sum:"<<sum<<endl;
// printv(s);
if (d == N + 1)
return;
bool r = true;
rep(i, M) {
if (s[i] < X)
r = false;
}
if (r && res > sum)
res = sum;
// dばんめを選ばない場合
rec(s, d + 1, sum);
// 選ぶ場合
if (r)
return;
rep(i, M) { s[i] += a[d][i]; }
rec(s, d + 1, sum + c[d]);
}
int main(void) {
// Your code here!
cin >> N >> M >> X;
rep(i, N) {
cin >> c[i];
rep(j, M) { cin >> a[i][j]; }
}
vector<int> s(M);
rec(s, 0, 0);
if (res == INT_MAX)
cout << "-1";
else
cout << res;
}
| replace | 74 | 75 | 74 | 75 | 0 | |
p02683 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
ll n, m, x;
cin >> n >> m >> x;
vector<int> C(n);
vector<vector<ll>> A(n, vector<ll>(m));
for (int i = 0; i < n; i++) {
cin >> C[i];
for (int j = 0; j < m; j++) {
cin >> A[i][j];
}
}
for (int i = 1; i < m; i++) {
if (std::accumulate(A[i].begin(), A[i].end(), 0) < x) {
cout << -1;
return 0;
}
}
ll ans = 1e8;
for (int i = 0; i < 1 << n; i++) {
ll cost = 0;
vector<int> d(m);
for (int j = 0; j < n; j++) {
if (i >> j & 1) {
cost += C[j];
for (int k = 0; k < m; k++)
d[k] += A[j][k];
}
}
bool flag = true;
for (int j = 0; j < m; j++) {
if (d[j] < x) {
flag = false;
}
}
if (flag)
ans = std::min(ans, cost);
}
if (ans == 1e8)
cout << -1 << endl;
else
cout << ans;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
ll n, m, x;
cin >> n >> m >> x;
vector<int> C(n);
vector<vector<ll>> A(n, vector<ll>(m));
for (int i = 0; i < n; i++) {
cin >> C[i];
for (int j = 0; j < m; j++) {
cin >> A[i][j];
}
}
/*for (int i = 1; i < m; i++) {
if (std::accumulate(A[i].begin(), A[i].end(), 0) < x) {
cout << -1;
return 0;
}
}*/
ll ans = 1e8;
for (int i = 0; i < 1 << n; i++) {
ll cost = 0;
vector<int> d(m);
for (int j = 0; j < n; j++) {
if (i >> j & 1) {
cost += C[j];
for (int k = 0; k < m; k++)
d[k] += A[j][k];
}
}
bool flag = true;
for (int j = 0; j < m; j++) {
if (d[j] < x) {
flag = false;
}
}
if (flag)
ans = std::min(ans, cost);
}
if (ans == 1e8)
cout << -1 << endl;
else
cout << ans;
return 0;
}
| replace | 22 | 28 | 22 | 28 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M, X; // N冊の参考書、M個のアルゴリズム、理解度X
cin >> N >> M >> X;
vector<vector<int>> A(N, vector<int>(M));
vector<int> kingaku(N);
for (int i = 0; i < N; i++) {
cin >> kingaku[i];
for (int j = 0; j < M; j++) {
cin >> A.at(i).at(j);
}
}
int resultSmall = -1;
for (int tmp = 0; tmp < (1 << 12); tmp++) {
bitset<12> s(tmp);
int count = 0;
vector<int> rikaido(M, 0);
if (s.test(N))
break;
for (int i = 0; i < N; i++) {
if (s.test(i)) {
count += kingaku[i];
for (int j = 0; j < M; j++) {
rikaido[j] += A.at(i).at(j);
}
}
}
bool flag = true;
for (int i = 0; i < M; i++) {
if (rikaido[i] < X) {
flag = false;
break;
}
}
if (flag) {
if (resultSmall == -1) {
resultSmall = count;
} else {
resultSmall = min(resultSmall, count);
}
}
}
cout << resultSmall << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M, X; // N冊の参考書、M個のアルゴリズム、理解度X
cin >> N >> M >> X;
vector<vector<int>> A(N, vector<int>(M));
vector<int> kingaku(N);
for (int i = 0; i < N; i++) {
cin >> kingaku[i];
for (int j = 0; j < M; j++) {
cin >> A.at(i).at(j);
}
}
int resultSmall = -1;
for (int tmp = 0; tmp < (1 << 12); tmp++) {
bitset<12> s(tmp);
int count = 0;
vector<int> rikaido(M, 0);
// if (s.test(N)) break;
for (int i = 0; i < N; i++) {
if (s.test(i)) {
count += kingaku[i];
for (int j = 0; j < M; j++) {
rikaido[j] += A.at(i).at(j);
}
}
}
bool flag = true;
for (int i = 0; i < M; i++) {
if (rikaido[i] < X) {
flag = false;
break;
}
}
if (flag) {
if (resultSmall == -1) {
resultSmall = count;
} else {
resultSmall = min(resultSmall, count);
}
}
}
cout << resultSmall << endl;
} | replace | 19 | 21 | 19 | 20 | 0 | |
p02683 | C++ | Runtime Error | // God put a smile upon your face <3
#include <bits/stdc++.h>`
#define slld(longvalue) scanf("%lld", &longvalue)
#define ll long long
#define ull unsigned long long
#define pll pair<long long, long long>
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define pb push_back
#define bug printf("BUG\n")
#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX
#define mxd 2e8
#define mnd -2e8
#define pi 3.14159265359
#define mod 958585860497
#define base 2001487
using namespace std;
bool check(ll n, ll pos) { return n & (1LL << pos); }
ll Set(ll n, ll pos) { return n = n | (1LL << pos); }
ll mat[20][20];
ll cost[20];
ll n, m, x;
int main() {
ll i, j, k, l, o, r, q;
ll testcase;
ll input, flag, tag, ans;
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
while (cin >> n >> m >> x) {
for (i = 0; i < n; i++) {
slld(cost[i]);
for (j = 0; j < m; j++)
slld(mat[i][j]);
}
ans = mxlld;
for (i = 0; i < (1 << n); i++) {
ll arr[n + 1];
memset(arr, 0, sizeof arr);
ll cst = 0;
for (j = 0; j < n; j++) {
if (check(i, j)) {
cst += cost[j];
for (k = 0; k < m; k++) {
arr[k] += mat[j][k];
}
}
}
for (j = 0; j < m; j++) {
if (arr[j] < x)
break;
}
if (j == m)
ans = min(ans, cst);
}
if (ans == mxlld)
ans = -1;
cout << ans << '\n';
}
}
| // God put a smile upon your face <3
#include <bits/stdc++.h>`
#define slld(longvalue) scanf("%lld", &longvalue)
#define ll long long
#define ull unsigned long long
#define pll pair<long long, long long>
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define pb push_back
#define bug printf("BUG\n")
#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX
#define mxd 2e8
#define mnd -2e8
#define pi 3.14159265359
#define mod 958585860497
#define base 2001487
using namespace std;
bool check(ll n, ll pos) { return n & (1LL << pos); }
ll Set(ll n, ll pos) { return n = n | (1LL << pos); }
ll mat[20][20];
ll cost[20];
ll n, m, x;
int main() {
ll i, j, k, l, o, r, q;
ll testcase;
ll input, flag, tag, ans;
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
while (cin >> n >> m >> x) {
for (i = 0; i < n; i++) {
slld(cost[i]);
for (j = 0; j < m; j++)
slld(mat[i][j]);
}
ans = mxlld;
for (i = 0; i < (1 << n); i++) {
ll arr[m + 1];
memset(arr, 0, sizeof arr);
ll cst = 0;
for (j = 0; j < n; j++) {
if (check(i, j)) {
cst += cost[j];
for (k = 0; k < m; k++) {
arr[k] += mat[j][k];
}
}
}
for (j = 0; j < m; j++) {
if (arr[j] < x)
break;
}
if (j == m)
ans = min(ans, cst);
}
if (ans == mxlld)
ans = -1;
cout << ans << '\n';
}
}
| replace | 60 | 61 | 60 | 61 | 0 | |
p02683 | C++ | Runtime Error | // SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (__typeof(a) i = (a); i < (b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359
int n, m, x, ans = INF;
vi cost, vals[13], cur;
bool valid() {
for (auto u : cur) {
if (u < x)
return false;
}
return true;
}
void dp(int at, int spent) {
if (valid()) {
ans = min(ans, spent);
return;
}
if (at == n)
return;
for (int i = 0; i < m; i++) {
cur[i] += vals[at][i];
}
dp(at + 1, spent + cost[at]);
for (int i = 0; i < m; i++) {
cur[i] -= vals[at][i];
}
dp(at + 1, spent);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> x;
cost.resize(m);
cur.resize(m, 0);
for (int i = 0; i < n; i++) {
cin >> cost[i];
for (int j = 0; j < m; j++) {
int in;
cin >> in;
vals[i].PB(in);
}
}
dp(0, 0);
cout << (ans == INF ? -1 : ans) << endl;
return 0;
} | // SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020 Bjarni Dagur Thor Karason
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (__typeof(a) i = (a); i < (b); i++)
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define PI 3.14159265359
int n, m, x, ans = INF;
vi cost, vals[13], cur;
bool valid() {
for (auto u : cur) {
if (u < x)
return false;
}
return true;
}
void dp(int at, int spent) {
if (valid()) {
ans = min(ans, spent);
return;
}
if (at == n)
return;
for (int i = 0; i < m; i++) {
cur[i] += vals[at][i];
}
dp(at + 1, spent + cost[at]);
for (int i = 0; i < m; i++) {
cur[i] -= vals[at][i];
}
dp(at + 1, spent);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> x;
cost.resize(n);
cur.resize(m, 0);
for (int i = 0; i < n; i++) {
cin >> cost[i];
for (int j = 0; j < m; j++) {
int in;
cin >> in;
vals[i].PB(in);
}
}
dp(0, 0);
cout << (ans == INF ? -1 : ans) << endl;
return 0;
} | replace | 49 | 50 | 49 | 50 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
#define lint long long
using namespace std;
int main() {
lint N, M, X;
cin >> N >> M >> X;
vector<lint> C(N);
vector<vector<lint>> A(N, vector<lint>(M));
vector<vector<lint>> rikai(pow(2, N), vector<lint>(M));
vector<lint> price(pow(2, N));
vector<bool> able(pow(2, N), false);
for (lint i = 0; i < N; i++) {
cin >> C[i];
for (lint j = 0; j < M; j++) {
cin >> A[i][j];
}
}
// priceとrikaiを計算
for (lint i = 1; i <= pow(2, N); i++) {
lint tmp = i;
for (lint j = 0; j < N; j++) {
price[i - 1] += (tmp % 2) * C[j];
for (lint k = 0; k < M; k++) {
rikai[i - 1][k] += (tmp % 2) * A[j][k];
}
tmp = tmp / 2;
}
}
// able判定
for (lint i = 0; i < pow(2, N); i++) {
sort(rikai[i].begin(), rikai[i].end());
if (rikai[i][0] >= X)
able[i] = true;
}
vector<lint> price_sort(0);
for (int i = 0; i < pow(2, N); i++) {
if (able[i])
price_sort.push_back(price[i]);
}
if (price_sort.size() == 0)
cout << -1 << endl;
sort(price_sort.begin(), price_sort.end());
cout << price_sort[0] << endl;
}
| #include <bits/stdc++.h>
#define lint long long
using namespace std;
int main() {
lint N, M, X;
cin >> N >> M >> X;
vector<lint> C(N);
vector<vector<lint>> A(N, vector<lint>(M));
vector<vector<lint>> rikai(pow(2, N), vector<lint>(M));
vector<lint> price(pow(2, N));
vector<bool> able(pow(2, N), false);
for (lint i = 0; i < N; i++) {
cin >> C[i];
for (lint j = 0; j < M; j++) {
cin >> A[i][j];
}
}
// priceとrikaiを計算
for (lint i = 1; i <= pow(2, N); i++) {
lint tmp = i;
for (lint j = 0; j < N; j++) {
price[i - 1] += (tmp % 2) * C[j];
for (lint k = 0; k < M; k++) {
rikai[i - 1][k] += (tmp % 2) * A[j][k];
}
tmp = tmp / 2;
}
}
// able判定
for (lint i = 0; i < pow(2, N); i++) {
sort(rikai[i].begin(), rikai[i].end());
if (rikai[i][0] >= X)
able[i] = true;
}
vector<lint> price_sort(0);
for (int i = 0; i < pow(2, N); i++) {
if (able[i])
price_sort.push_back(price[i]);
}
if (price_sort.size() == 0)
cout << "-1" << endl;
else {
sort(price_sort.begin(), price_sort.end());
cout << price_sort[0] << endl;
}
}
| replace | 52 | 57 | 52 | 57 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define VI vector<int>
#define VL vector<ll>
#define PII pair<int, int>
#define VII vector<PII>
#define mp make_pair
#define pb push_back
#define vt vector
#define PI acos(-1)
#define ld long double
#define endl "\n"
#define all(c) (c).begin(), (c).end()
#define ft first
#define sd second
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define F0R(i, b) for (int i = 0; i < b; ++i)
#define RF0R(i, b) for (int i = b; i >= 0; --i)
const ll inf = 1e18;
const int MxN = 100001;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, x;
cin >> n >> m >> x;
vt<int> c(n);
vt<vt<int>> A(n, vt<int>(m));
F0R(i, n) {
cin >> c[i];
F0R(j, n)
cin >> A[i][j];
}
int ans = INT_MAX;
F0R(i, (1 << n)) {
int cost = 0;
vt<int> skills(m);
F0R(j, n) {
if ((i >> j) & 1) {
// cout << 1 ;
F0R(k, m)
skills[k] += A[j][k];
cost += c[j];
}
// cout <<0;
}
// cout << endl ;
bool ok = true;
F0R(j, m) {
if (skills[j] < x) {
ok = false;
break;
}
}
if (ok) {
ans = min(ans, cost);
}
}
if (ans == INT_MAX)
cout << -1;
else
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define VI vector<int>
#define VL vector<ll>
#define PII pair<int, int>
#define VII vector<PII>
#define mp make_pair
#define pb push_back
#define vt vector
#define PI acos(-1)
#define ld long double
#define endl "\n"
#define all(c) (c).begin(), (c).end()
#define ft first
#define sd second
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define F0R(i, b) for (int i = 0; i < b; ++i)
#define RF0R(i, b) for (int i = b; i >= 0; --i)
const ll inf = 1e18;
const int MxN = 100001;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, x;
cin >> n >> m >> x;
vt<int> c(n);
vt<vt<int>> A(n, vt<int>(m));
F0R(i, n) {
cin >> c[i];
F0R(j, m)
cin >> A[i][j];
}
int ans = INT_MAX;
F0R(i, (1 << n)) {
int cost = 0;
vt<int> skills(m);
F0R(j, n) {
if ((i >> j) & 1) {
// cout << 1 ;
F0R(k, m)
skills[k] += A[j][k];
cost += c[j];
}
// cout <<0;
}
// cout << endl ;
bool ok = true;
F0R(j, m) {
if (skills[j] < x) {
ok = false;
break;
}
}
if (ok) {
ans = min(ans, cost);
}
}
if (ans == INT_MAX)
cout << -1;
else
cout << ans;
return 0;
}
| replace | 34 | 35 | 34 | 35 | 0 | |
p02683 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;
int n, m, x;
vector<vector<int>> vec;
ll smallest = 1000000000000;
void dfs(vector<int> v, vector<bool> flag, int length) {
if (v.size() == length) {
vector<int> xVec(m, 0);
ll sum = 0;
rep(i, v.size()) {
rep(j, m + 1) {
if (j == 0) {
sum += vec[v[i]][j];
} else {
xVec[j - 1] += vec[v[i]][j];
}
}
}
bool overX = true;
rep(i, m) {
if (xVec[i] < x)
overX = false;
}
if (overX) {
smallest = min(smallest, sum);
}
} else {
rep(i, n) {
if (!flag[i]) {
v.push_back(i);
flag[i] = true;
dfs(v, flag, length);
v.pop_back();
flag[i] = false;
}
}
}
}
int main() {
cin >> n >> m >> x;
rep(i, n) {
vector<int> tmp;
int c;
cin >> c;
tmp.push_back(c);
rep(j, m) {
int num;
cin >> num;
tmp.push_back(num);
}
vec.push_back(tmp);
}
for (int i = 1; i <= n; i++) {
rep(j, n) {
vector<int> tmp;
vector<bool> flagVec(n, false);
tmp.push_back(j);
flagVec[j] = true;
dfs(tmp, flagVec, i);
tmp.pop_back();
flagVec[j] = false;
}
}
if (smallest == 1000000000000)
cout << -1 << endl;
else
cout << smallest << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;
int n, m, x;
vector<vector<int>> vec;
ll smallest = 1000000000000;
void dfs(vector<int> v, vector<bool> flag, int length) {
if (v.size() == length) {
vector<int> xVec(m, 0);
ll sum = 0;
rep(i, v.size()) {
rep(j, m + 1) {
if (j == 0) {
sum += vec[v[i]][j];
} else {
xVec[j - 1] += vec[v[i]][j];
}
}
}
bool overX = true;
rep(i, m) {
if (xVec[i] < x)
overX = false;
}
if (overX) {
smallest = min(smallest, sum);
}
} else {
for (int i = v.back() + 1; i < n; i++) {
if (!flag[i]) {
v.push_back(i);
flag[i] = true;
dfs(v, flag, length);
v.pop_back();
flag[i] = false;
}
}
}
}
int main() {
cin >> n >> m >> x;
rep(i, n) {
vector<int> tmp;
int c;
cin >> c;
tmp.push_back(c);
rep(j, m) {
int num;
cin >> num;
tmp.push_back(num);
}
vec.push_back(tmp);
}
for (int i = 1; i <= n; i++) {
rep(j, n) {
vector<int> tmp;
vector<bool> flagVec(n, false);
tmp.push_back(j);
flagVec[j] = true;
dfs(tmp, flagVec, i);
tmp.pop_back();
flagVec[j] = false;
}
}
if (smallest == 1000000000000)
cout << -1 << endl;
else
cout << smallest << endl;
return 0;
} | replace | 33 | 34 | 33 | 34 | TLE | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <typename type> type BaseChange(type num, type base, type digit) {
for (type i = 0; i < digit; i++) {
num /= base;
}
return num % base;
}
int main() {
// 基本データ入力
long long n, m, x;
cin >> n >> m >> x;
// コストとデータ入力
vector<long long> c(n);
vector<vector<long long>> a(n, vector<long long>(n));
for (int i = 0; i < n; i++) {
cin >> c[i];
for (long long j = 0; j < m; j++)
cin >> a[i][j];
}
long long ans = (1 << 30);
// ビット全探索
for (long long i = 1; i < (1 << n); i++) {
long long cost = 0;
vector<long long> state(m, 0);
for (long long j = 0; j < n; j++) {
// 検索文字がhit
// cout << BaseChange(i,2,j);
if (BaseChange(i, 2LL, j) == 1) {
cost += c[j];
for (long long k = 0; k < m; k++) {
state[k] += a[j][k];
}
}
}
// cout << endl;
// デバッグ用
// cout << " " << cost << " ";
// for(int j=0;j<m;j++) cout << state[j] << " ";
// cout << endl;
bool check = true;
for (long long j = 0; j < m; j++) {
if (state[j] < x)
check = false;
}
if (check)
ans = min(ans, cost);
}
if (ans == (1 << 30))
ans = -1;
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
template <typename type> type BaseChange(type num, type base, type digit) {
for (type i = 0; i < digit; i++) {
num /= base;
}
return num % base;
}
int main() {
// 基本データ入力
long long n, m, x;
cin >> n >> m >> x;
// コストとデータ入力
vector<long long> c(n);
vector<vector<long long>> a(n, vector<long long>(m));
for (int i = 0; i < n; i++) {
cin >> c[i];
for (long long j = 0; j < m; j++)
cin >> a[i][j];
}
long long ans = (1 << 30);
// ビット全探索
for (long long i = 1; i < (1 << n); i++) {
long long cost = 0;
vector<long long> state(m, 0);
for (long long j = 0; j < n; j++) {
// 検索文字がhit
// cout << BaseChange(i,2,j);
if (BaseChange(i, 2LL, j) == 1) {
cost += c[j];
for (long long k = 0; k < m; k++) {
state[k] += a[j][k];
}
}
}
// cout << endl;
// デバッグ用
// cout << " " << cost << " ";
// for(int j=0;j<m;j++) cout << state[j] << " ";
// cout << endl;
bool check = true;
for (long long j = 0; j < m; j++) {
if (state[j] < x)
check = false;
}
if (check)
ans = min(ans, cost);
}
if (ans == (1 << 30))
ans = -1;
cout << ans << endl;
} | replace | 18 | 19 | 18 | 19 | 0 | |
p02683 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
std::vector<int> res;
int n, m, x;
std::vector<std::vector<int>> vec;
std::vector<int> book_prices;
int main() {
std::cin >> n >> m >> x;
book_prices.assign(n, 0);
vec.assign(n, std::vector<int>(m, 0));
for (int i = 0; i < n; i++) {
std::cin >> book_prices[i];
for (int j = 0; j < m; j++) {
std::cin >> vec[i][j];
}
}
for (int i = 0; i < (2 << n); i++) {
std::vector<int> skill(n, 0);
int total_price = 0;
for (int j = 0; j < n; j++) {
if ((i >> j) & 1) {
total_price += book_prices[j];
for (int k = 0; k < m; k++) {
skill[k] += vec[j][k];
}
}
}
int min_skill = *std::min_element(skill.begin(), skill.end());
if (min_skill >= x) {
res.push_back(total_price);
}
}
if (res.size() > 0) {
std::cout << *std::min_element(res.begin(), res.end()) << std::endl;
return 0;
}
std::cout << -1 << std::endl;
} | #include <algorithm>
#include <iostream>
#include <vector>
std::vector<int> res;
int n, m, x;
std::vector<std::vector<int>> vec;
std::vector<int> book_prices;
int main() {
std::cin >> n >> m >> x;
book_prices.assign(n, 0);
vec.assign(n, std::vector<int>(m, 0));
for (int i = 0; i < n; i++) {
std::cin >> book_prices[i];
for (int j = 0; j < m; j++) {
std::cin >> vec[i][j];
}
}
for (int i = 0; i < (2 << n); i++) {
std::vector<int> skill(m, 0);
int total_price = 0;
for (int j = 0; j < n; j++) {
if ((i >> j) & 1) {
total_price += book_prices[j];
for (int k = 0; k < m; k++) {
skill[k] += vec[j][k];
}
}
}
int min_skill = *std::min_element(skill.begin(), skill.end());
if (min_skill >= x) {
res.push_back(total_price);
}
}
if (res.size() > 0) {
std::cout << *std::min_element(res.begin(), res.end()) << std::endl;
return 0;
}
std::cout << -1 << std::endl;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
const long long int INF = 1LL << 60;
const long long int mod = 1e9 + 7;
int main() {
int N, M, X;
cin >> N >> M >> X;
vector<int> C(N + 1);
vector<vector<int>> A(N + 1, vector<int>(N + 1, 0));
vector<long long> sum_a(M + 1, 0);
for (int i = 1; i <= N; i++) {
cin >> C[i];
for (int j = 1; j <= M; j++) {
cin >> A[i][j];
sum_a[j] += A[i][j];
}
}
bool possible = true;
for (int j = 1; j <= M; j++) {
if (sum_a[j] < X) {
possible = false;
break;
}
}
if (!possible) {
cout << -1 << endl;
return 0;
}
long long all_patterns = (long long)(pow(2, N + 1)) - 2;
vector<vector<long long>> state(all_patterns + 1,
vector<long long>(M + 1, 0));
vector<long long> cumulative_cost(all_patterns + 1);
vector<long long> ok(all_patterns + 1, false);
long long pattern = 2;
long long pos = 1;
for (int i = 1; i <= N; i++) {
long long prev_ref = pos - pattern / 2;
for (int j = 1; j <= pattern; j++) {
if (j % 2 == 0) {
for (long long k = 1; k <= M; k++) {
state[pos][k] = state[prev_ref][k];
state[pos][k] += A[i][k];
}
cumulative_cost[pos] = cumulative_cost[prev_ref] + C[i];
bool possible = true;
for (int k = 1; k <= M; k++) {
possible = possible && (state[pos][k] >= X);
}
ok[pos] = possible;
prev_ref++;
} else {
for (int k = 1; k <= M; k++) {
state[pos][k] = state[prev_ref][k];
}
cumulative_cost[pos] = cumulative_cost[prev_ref];
ok[pos] = ok[prev_ref];
}
pos++;
}
pattern *= 2;
}
long long ans = 1200000 + 1;
for (long long i = 1; i <= all_patterns; i++) {
if (ok[i]) {
ans = min(ans, cumulative_cost[i]);
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
const long long int INF = 1LL << 60;
const long long int mod = 1e9 + 7;
int main() {
int N, M, X;
cin >> N >> M >> X;
vector<int> C(N + 1);
vector<vector<int>> A(N + 1, vector<int>(M + 1, 0));
vector<long long> sum_a(M + 1, 0);
for (int i = 1; i <= N; i++) {
cin >> C[i];
for (int j = 1; j <= M; j++) {
cin >> A[i][j];
sum_a[j] += A[i][j];
}
}
bool possible = true;
for (int j = 1; j <= M; j++) {
if (sum_a[j] < X) {
possible = false;
break;
}
}
if (!possible) {
cout << -1 << endl;
return 0;
}
long long all_patterns = (long long)(pow(2, N + 1)) - 2;
vector<vector<long long>> state(all_patterns + 1,
vector<long long>(M + 1, 0));
vector<long long> cumulative_cost(all_patterns + 1);
vector<long long> ok(all_patterns + 1, false);
long long pattern = 2;
long long pos = 1;
for (int i = 1; i <= N; i++) {
long long prev_ref = pos - pattern / 2;
for (int j = 1; j <= pattern; j++) {
if (j % 2 == 0) {
for (long long k = 1; k <= M; k++) {
state[pos][k] = state[prev_ref][k];
state[pos][k] += A[i][k];
}
cumulative_cost[pos] = cumulative_cost[prev_ref] + C[i];
bool possible = true;
for (int k = 1; k <= M; k++) {
possible = possible && (state[pos][k] >= X);
}
ok[pos] = possible;
prev_ref++;
} else {
for (int k = 1; k <= M; k++) {
state[pos][k] = state[prev_ref][k];
}
cumulative_cost[pos] = cumulative_cost[prev_ref];
ok[pos] = ok[prev_ref];
}
pos++;
}
pattern *= 2;
}
long long ans = 1200000 + 1;
for (long long i = 1; i <= all_patterns; i++) {
if (ok[i]) {
ans = min(ans, cumulative_cost[i]);
}
}
cout << ans << endl;
return 0;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p02683 | C++ | Runtime Error | // Template //
#include <bits/stdc++.h>
using namespace std;
// マクロ //
#define rep(i, N) for (int i = 0; i < (int)(N); i++)
#define req(i, f, N) for (int i = f; i < (int)(N); i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)
#define db(i) cout << #i << " = " << i;
// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using plili = pair<lint, lint>;
using vplili = vector<plili>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvli = vector<vli>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vvs = vector<vs>;
using mii = map<int, int>;
using mili = map<int, lint>;
using mci = map<char, int>;
using mcli = map<char, lint>;
using msi = map<string, int>;
using msli = map<string, lint>;
// 関数 //
template <class T, class Q> lint gcd_(T a, Q b) {
int t;
while (b != 0) {
t = a % b;
a = b;
b = t;
}
return a;
}
template <class T, class Q> lint lcm_(T a, Q b) { return a * b / gcd_(a, b); }
double distance(pii a, pii b) {
double dist;
dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
return dist;
}
lint perm(int a) {
lint perm = 1;
for (int i = a; i >= 1; i--) {
perm *= i;
}
return perm;
}
lint combination(int n, int m) {
long double c = 1;
for (int i = n, k = 1; i > m; i--, k++) {
c *= i;
c /= k;
}
return (lint)c;
}
template <class T, class Q> inline bool chmin(T &a, Q b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T, class Q> inline bool chmax(T &a, Q b) {
if (a < b) {
a = b;
return true;
}
return false;
}
// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int MOD = 998244353;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);
// キーワード //
#define elif else if
// End of Template //
vi operator+(vi &a, vi &b) {
rep(i, a.size()) { a[i] += b[i + 1]; }
return a;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
int N, M, X;
cin >> N >> M >> X;
vvi books(N);
rep(i, N) {
rep(j, M + 1) {
int k;
cin >> k;
books[i].push_back(k);
}
}
int money = inf;
vi argo(M, 0);
rep(i, N) argo = argo + books[i];
sort(argo);
if (argo[0] < X) {
cou(-1);
exit(0);
}
for (int tmp = 0; tmp < (1 << 10); tmp++) {
bitset<10> s(tmp);
vi para(M, 0);
int mon = 0;
rep(i, N) {
if (s.test(i)) {
para = para + books[i];
mon += books[i][0];
}
}
sort(para);
if (para[0] >= X)
chmin(money, mon);
para.assign(M, 0);
mon = 0;
}
cou(money);
} | // Template //
#include <bits/stdc++.h>
using namespace std;
// マクロ //
#define rep(i, N) for (int i = 0; i < (int)(N); i++)
#define req(i, f, N) for (int i = f; i < (int)(N); i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)
#define db(i) cout << #i << " = " << i;
// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using plili = pair<lint, lint>;
using vplili = vector<plili>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvli = vector<vli>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vvs = vector<vs>;
using mii = map<int, int>;
using mili = map<int, lint>;
using mci = map<char, int>;
using mcli = map<char, lint>;
using msi = map<string, int>;
using msli = map<string, lint>;
// 関数 //
template <class T, class Q> lint gcd_(T a, Q b) {
int t;
while (b != 0) {
t = a % b;
a = b;
b = t;
}
return a;
}
template <class T, class Q> lint lcm_(T a, Q b) { return a * b / gcd_(a, b); }
double distance(pii a, pii b) {
double dist;
dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
return dist;
}
lint perm(int a) {
lint perm = 1;
for (int i = a; i >= 1; i--) {
perm *= i;
}
return perm;
}
lint combination(int n, int m) {
long double c = 1;
for (int i = n, k = 1; i > m; i--, k++) {
c *= i;
c /= k;
}
return (lint)c;
}
template <class T, class Q> inline bool chmin(T &a, Q b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T, class Q> inline bool chmax(T &a, Q b) {
if (a < b) {
a = b;
return true;
}
return false;
}
// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int MOD = 998244353;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);
// キーワード //
#define elif else if
// End of Template //
vi operator+(vi &a, vi &b) {
rep(i, a.size()) { a[i] += b[i + 1]; }
return a;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
int N, M, X;
cin >> N >> M >> X;
vvi books(N);
rep(i, N) {
rep(j, M + 1) {
int k;
cin >> k;
books[i].push_back(k);
}
}
int money = inf;
vi argo(M, 0);
rep(i, N) argo = argo + books[i];
sort(argo);
if (argo[0] < X) {
cou(-1);
exit(0);
}
for (int tmp = 0; tmp < (1 << 12); tmp++) {
bitset<12> s(tmp);
vi para(M, 0);
int mon = 0;
rep(i, N) {
if (s.test(i)) {
para = para + books[i];
mon += books[i][0];
}
}
sort(para);
if (para[0] >= X)
chmin(money, mon);
para.assign(M, 0);
mon = 0;
}
cou(money);
} | replace | 139 | 141 | 139 | 141 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
int N, M, X;
cin >> N >> M >> X;
vector<int> C(N);
vector<vector<int>> A(N, vector<int>(M));
for (int i = 0; i < N; i++) {
cin >> C[i];
for (int j = 0; j < M; j++) {
cin >> A[i][j];
}
}
int sum0 = 1200000;
bool ans = false;
for (int tmp = 1; tmp < (1 << 12); tmp++) {
bitset<12> s(tmp);
if (s.count() != 12 && s.test(N))
break;
vector<int> Adash(M);
int sum1 = 0;
for (int i = 0; i < 12; i++) {
if (s.test(i)) {
sum1 += C[i];
for (int j = 0; j < M; j++) {
Adash[j] += A[i][j];
}
}
}
bool ans1 = true;
for (int j = 0; j < M; j++) {
if (Adash[j] < X)
ans1 = false;
}
if (ans1) {
sum0 = min(sum0, sum1);
ans = true;
}
}
if (ans)
cout << sum0 << endl;
else
cout << -1 << endl;
}
| #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
int N, M, X;
cin >> N >> M >> X;
vector<int> C(N);
vector<vector<int>> A(N, vector<int>(M));
for (int i = 0; i < N; i++) {
cin >> C[i];
for (int j = 0; j < M; j++) {
cin >> A[i][j];
}
}
int sum0 = 1200000;
bool ans = false;
for (int tmp = 1; tmp < (1 << 12); tmp++) {
bitset<12> s(tmp);
if (N != 12) {
if (s.test(N))
break;
}
vector<int> Adash(M);
int sum1 = 0;
for (int i = 0; i < 12; i++) {
if (s.test(i)) {
sum1 += C[i];
for (int j = 0; j < M; j++) {
Adash[j] += A[i][j];
}
}
}
bool ans1 = true;
for (int j = 0; j < M; j++) {
if (Adash[j] < X)
ans1 = false;
}
if (ans1) {
sum0 = min(sum0, sum1);
ans = true;
}
}
if (ans)
cout << sum0 << endl;
else
cout << -1 << endl;
}
| replace | 19 | 21 | 19 | 23 | 0 | |
p02683 | Python | Runtime Error | n, m, x = map(int, input().split())
prace = []
know = []
for i in range(n):
acc = list(map(int, input().split()))
prace.append(acc[0])
know.append(acc[1:])
ans = 10**10
for i in range(2**n):
und = [0 for i in range(m)]
f = "{:b}".format(i)
s = f.zfill(m)
mm = 0
for j in range(len(s)):
if s[j] == "1":
for k in range(m):
und[k] += know[j][k]
mm += prace[j]
for j in range(m):
if und[j] < x:
break
else:
ans = min(ans, mm)
if ans == 10**10:
print(-1)
else:
print(ans)
| n, m, x = map(int, input().split())
prace = []
know = []
for i in range(n):
acc = list(map(int, input().split()))
prace.append(acc[0])
know.append(acc[1:])
ans = 10**10
for i in range(2**n):
und = [0 for i in range(m)]
f = "{:b}".format(i)
s = f.zfill(n)
mm = 0
for j in range(len(s)):
if s[j] == "1":
for k in range(m):
und[k] += know[j][k]
mm += prace[j]
for j in range(m):
if und[j] < x:
break
else:
ans = min(ans, mm)
if ans == 10**10:
print(-1)
else:
print(ans)
| replace | 12 | 13 | 12 | 13 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 1010001000;
const ll INF = 1001000100010001000;
const int mod = (int)1e9 + 7;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<int> c(n);
vector<vector<int>> a(n, vector<int>(m));
int ans = inf;
rep(i, 0, n) {
cin >> c.at(i);
rep(j, 0, m) { cin >> a.at(i).at(j); }
}
for (int bit = 0; bit < (1 << n); bit++) {
vector<int> s(n, 0);
int cost = 0;
for (int i = 0; i < n; i++) {
if (bit & (1 << i)) {
cost += c.at(i);
rep(j, 0, m) { s.at(j) += a.at(i).at(j); }
}
}
bool ch = true;
rep(j, 0, m) {
if (s.at(j) < x)
ch = false;
}
if (ch)
ans = min(ans, cost);
}
if (ans == inf) {
cout << "-1" << endl;
return 0;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 1010001000;
const ll INF = 1001000100010001000;
const int mod = (int)1e9 + 7;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<int> c(n);
vector<vector<int>> a(n, vector<int>(m));
int ans = inf;
rep(i, 0, n) {
cin >> c.at(i);
rep(j, 0, m) { cin >> a.at(i).at(j); }
}
for (int bit = 0; bit < (1 << n); bit++) {
vector<int> s(m, 0);
int cost = 0;
for (int i = 0; i < n; i++) {
if (bit & (1 << i)) {
cost += c.at(i);
rep(j, 0, m) { s.at(j) += a.at(i).at(j); }
}
}
bool ch = true;
rep(j, 0, m) {
if (s.at(j) < x)
ch = false;
}
if (ch)
ans = min(ans, cost);
}
if (ans == inf) {
cout << "-1" << endl;
return 0;
}
cout << ans << endl;
return 0;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M, X;
cin >> N >> M >> X;
vector<int> price(12, 0);
vector<vector<int>> add(N, vector<int>(M));
for (int i = 0; i < N; i++) {
cin >> price.at(i);
for (int j = 0; j < M; j++) {
cin >> add.at(i).at(j);
}
}
int m = 0;
for (int i = 0; i < N; i++) {
m += price.at(i);
}
bool c = false;
for (int k = 0; k < (1 << N); k++) {
vector<int> sum(M, 0);
bitset<12> buy(k << (12 - N));
int total = 0;
for (int l = 0; l < 12; l++) {
if (buy.test(l)) {
total += price.at(l);
for (int i = 0; i < M; i++) {
sum.at(i) += add.at(l).at(i);
}
}
}
bool a = true;
for (int i = 0; i < M; i++) {
if (sum.at(i) < X) {
a = false;
}
}
if (a) {
c = true;
if (total < m) {
m = total;
}
}
}
if (c) {
cout << m << endl;
} else {
cout << -1 << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M, X;
cin >> N >> M >> X;
vector<int> price(12, 0);
vector<vector<int>> add(N, vector<int>(M));
for (int i = 0; i < N; i++) {
cin >> price.at(i);
for (int j = 0; j < M; j++) {
cin >> add.at(i).at(j);
}
}
int m = 0;
for (int i = 0; i < N; i++) {
m += price.at(i);
}
bool c = false;
for (int k = 0; k < (1 << N); k++) {
vector<int> sum(M, 0);
bitset<12> buy(k);
int total = 0;
for (int l = 0; l < 12; l++) {
if (buy.test(l)) {
total += price.at(l);
for (int i = 0; i < M; i++) {
sum.at(i) += add.at(l).at(i);
}
}
}
bool a = true;
for (int i = 0; i < M; i++) {
if (sum.at(i) < X) {
a = false;
}
}
if (a) {
c = true;
if (total < m) {
m = total;
}
}
}
if (c) {
cout << m << endl;
} else {
cout << -1 << endl;
}
} | replace | 21 | 22 | 21 | 22 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 9) >= this->size() (which is 3)
|
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;
bool compPair(const pint &arg1, const pint &arg2) {
return arg1.first > arg2.first;
}
template <class T> void chmax(T &a, T b) {
if (a < b) {
a = b;
}
}
template <class T> void chmin(T &a, T b) {
if (a > b) {
a = b;
}
}
int main(void) {
int n, m, x;
cin >> n >> m >> x;
vector<vector<int>> a(n, vector<int>(n, 0));
vector<int> c(n);
for (int in = 0; in < n; in++) {
cin >> c.at(in);
for (int im = 0; im < m; im++) {
cin >> a.at(in).at(im);
}
}
bool flg;
int ans = 1e9, anstmp;
for (int ib = 0; ib < (1 << n); ib++) {
vector<int> algo(m);
anstmp = 0;
flg = true;
for (int in = 0; in < n; in++) {
if (((ib >> in) & 1)) {
for (int im = 0; im < m; im++) {
algo.at(im) += a.at(in).at(im);
}
anstmp += c.at(in);
}
}
for (int im = 0; im < m; im++) {
if (algo.at(im) < x) {
flg = false;
}
}
if (flg)
ans = min(ans, anstmp);
}
if (ans == 1e9)
ans = -1;
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;
bool compPair(const pint &arg1, const pint &arg2) {
return arg1.first > arg2.first;
}
template <class T> void chmax(T &a, T b) {
if (a < b) {
a = b;
}
}
template <class T> void chmin(T &a, T b) {
if (a > b) {
a = b;
}
}
int main(void) {
int n, m, x;
cin >> n >> m >> x;
vector<vector<int>> a(n, vector<int>(m, 0));
vector<int> c(n);
for (int in = 0; in < n; in++) {
cin >> c.at(in);
for (int im = 0; im < m; im++) {
cin >> a.at(in).at(im);
}
}
bool flg;
int ans = 1e9, anstmp;
for (int ib = 0; ib < (1 << n); ib++) {
vector<int> algo(m);
anstmp = 0;
flg = true;
for (int in = 0; in < n; in++) {
if (((ib >> in) & 1)) {
for (int im = 0; im < m; im++) {
algo.at(im) += a.at(in).at(im);
}
anstmp += c.at(in);
}
}
for (int im = 0; im < m; im++) {
if (algo.at(im) < x) {
flg = false;
}
}
if (flg)
ans = min(ans, anstmp);
}
if (ans == 1e9)
ans = -1;
cout << ans << endl;
return 0;
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p02683 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
const int MAX = 1001001001;
int main() {
int N, M, X;
std::cin >> N >> M >> X;
std::vector<int> C(N);
std::vector<std::vector<int>> A(N, std::vector<int>(N));
for (int i = 0; i < N; i++) {
std::cin >> C[i];
for (int j = 0; j < M; j++) {
std::cin >> A[i][j];
}
}
int answer = MAX;
for (int i = 0; i < 1 << N; i++) {
int cost = 0;
std::vector<int> skill(M);
for (int j = 0; j < N; j++) {
if (i >> j & 1) {
cost += C[j];
for (int k = 0; k < M; k++)
skill[k] += A[j][k];
}
}
int count_error = 0;
for (int j = 0; j < M; j++) {
if (skill[j] < X)
count_error = 1;
}
if (count_error == 0)
answer = std::min(cost, answer);
}
if (answer == MAX)
std::cout << -1 << std::endl;
else
std::cout << answer << std::endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
const int MAX = 1001001001;
int main() {
int N, M, X;
std::cin >> N >> M >> X;
std::vector<int> C(N);
std::vector<std::vector<int>> A(N, std::vector<int>(M));
for (int i = 0; i < N; i++) {
std::cin >> C[i];
for (int j = 0; j < M; j++) {
std::cin >> A[i][j];
}
}
int answer = MAX;
for (int i = 0; i < 1 << N; i++) {
int cost = 0;
std::vector<int> skill(M);
for (int j = 0; j < N; j++) {
if (i >> j & 1) {
cost += C[j];
for (int k = 0; k < M; k++)
skill[k] += A[j][k];
}
}
int count_error = 0;
for (int j = 0; j < M; j++) {
if (skill[j] < X)
count_error = 1;
}
if (count_error == 0)
answer = std::min(cost, answer);
}
if (answer == MAX)
std::cout << -1 << std::endl;
else
std::cout << answer << std::endl;
return 0;
} | replace | 14 | 15 | 14 | 15 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M, X;
cin >> N >> M >> X;
vector<vector<int>> A(N, vector<int>(M));
vector<int> MAX(M, 0);
vector<int> c(N);
for (int i = 0; i < N; i++) {
cin >> c[i];
for (int j = 0; j < M; j++) {
cin >> A[i][j];
}
}
int ans = 2000000000;
for (int tmp = 0; tmp < (1 << 12); tmp++) {
bitset<12> s(tmp);
if (s.test(N) && N < 12)
break;
int cost = 0;
for (int i = 0; i < N; i++) {
if (s.test(i)) {
cost += c[i];
for (int j = 0; j < M; j++) {
MAX[j] += A[i][j];
}
}
}
bool b = true;
for (int i = 0; i < M; i++) {
if (MAX[i] < X)
b = false;
}
if (b)
ans = min(ans, cost);
MAX.assign(M, 0);
}
cout << (ans == 2000000000 ? -1 : ans) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, M, X;
cin >> N >> M >> X;
vector<vector<int>> A(N, vector<int>(M));
vector<int> MAX(M, 0);
vector<int> c(N);
for (int i = 0; i < N; i++) {
cin >> c[i];
for (int j = 0; j < M; j++) {
cin >> A[i][j];
}
}
int ans = 2000000000;
for (int tmp = 0; tmp < (1 << 12); tmp++) {
bitset<13> s(tmp);
if (s.test(N) && N < 12)
break;
int cost = 0;
for (int i = 0; i < N; i++) {
if (s.test(i)) {
cost += c[i];
for (int j = 0; j < M; j++) {
MAX[j] += A[i][j];
}
}
}
bool b = true;
for (int i = 0; i < M; i++) {
if (MAX[i] < X)
b = false;
}
if (b)
ans = min(ans, cost);
MAX.assign(M, 0);
}
cout << (ans == 2000000000 ? -1 : ans) << endl;
} | replace | 18 | 19 | 18 | 19 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using Graph = vector<vector<int>>;
int main() {
int N, M;
cin >> N >> M;
ll X;
cin >> X;
vector<vector<ll>> a(N, vector<ll>());
vector<ll> c;
rep(i, N) {
ll C;
cin >> C;
c.push_back(C);
rep(j, M) {
ll A;
cin >> A;
a[i].push_back(A);
}
}
ll ans = INF;
rep(i, pow(2, N)) {
ll total = 0;
vector<ll> tmp(N, 0);
rep(j, N) {
int bit = (i >> j);
if ((bit & 1) == 1) {
total += c[j];
rep(k, M) { tmp[k] += a[j][k]; }
}
}
bool isOK = true;
rep(j, M) {
if (tmp[j] < X)
isOK = false;
}
if (isOK) {
ans = min(ans, total);
}
}
if (ans == INF)
cout << -1 << endl;
else
cout << ans << endl;
} | #include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using Graph = vector<vector<int>>;
int main() {
int N, M;
cin >> N >> M;
ll X;
cin >> X;
vector<vector<ll>> a(N, vector<ll>());
vector<ll> c;
rep(i, N) {
ll C;
cin >> C;
c.push_back(C);
rep(j, M) {
ll A;
cin >> A;
a[i].push_back(A);
}
}
ll ans = INF;
rep(i, pow(2, N)) {
ll total = 0;
vector<ll> tmp(M, 0);
rep(j, N) {
int bit = (i >> j);
if ((bit & 1) == 1) {
total += c[j];
rep(k, M) { tmp[k] += a[j][k]; }
}
}
bool isOK = true;
rep(j, M) {
if (tmp[j] < X)
isOK = false;
}
if (isOK) {
ans = min(ans, total);
}
}
if (ans == INF)
cout << -1 << endl;
else
cout << ans << endl;
} | replace | 45 | 46 | 45 | 46 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
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;
}
const int INF = 1 << 30;
int n, m, x;
int min_ = INF;
int c[15];
int a[15][15];
void dfs(vector<int> &A) {
int len = A.size();
if (len == n) {
ll sum = 0;
vi f(n, 0);
bool flag = true;
rep(i, len) {
if (A.at(i) == 1) {
sum += c[i];
rep(j, m) f[j] += a[i][j];
}
}
rep(j, m) {
if (f[j] < x)
flag = false;
}
if (sum <= min_ && flag)
min_ = sum;
return;
}
for (int v = 0; v < 2; ++v) {
A.push_back(v);
dfs(A);
A.pop_back();
}
}
int main() {
cin >> n >> m >> x;
vi f(m, 0);
rep(i, n) {
cin >> c[i];
rep(j, m) {
cin >> a[i][j];
f[j] += a[i][j];
}
}
rep(i, m) {
if (f[i] < x) {
cout << -1 << endl;
return 0;
}
}
vector<int> A;
dfs(A);
cout << min_ << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
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;
}
const int INF = 1 << 30;
int n, m, x;
int min_ = INF;
int c[15];
int a[15][15];
void dfs(vector<int> &A) {
int len = A.size();
if (len == n) {
ll sum = 0;
vi f(m, 0);
bool flag = true;
rep(i, len) {
if (A.at(i) == 1) {
sum += c[i];
rep(j, m) f[j] += a[i][j];
}
}
rep(j, m) {
if (f[j] < x)
flag = false;
}
if (sum <= min_ && flag)
min_ = sum;
return;
}
for (int v = 0; v < 2; ++v) {
A.push_back(v);
dfs(A);
A.pop_back();
}
}
int main() {
cin >> n >> m >> x;
vi f(m, 0);
rep(i, n) {
cin >> c[i];
rep(j, m) {
cin >> a[i][j];
f[j] += a[i][j];
}
}
rep(i, m) {
if (f[i] < x) {
cout << -1 << endl;
return 0;
}
}
vector<int> A;
dfs(A);
cout << min_ << endl;
return 0;
} | replace | 36 | 37 | 36 | 37 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
bool provera(vector<long long> &niz, int &m, long long &x) {
for (int i = 0; i < m; i++)
if (niz[i] < x)
return false;
return true;
}
long long f(vector<vector<long long>> &v, vector<long long> &cene, int &n,
int &m, long long &x, vector<long long> niz, int index,
long long cena) {
if (index == n) {
if (provera(niz, m, x))
return cena;
else
return LLONG_MAX;
}
long long m1, m2;
m1 = f(v, cene, n, m, x, niz, index + 1, cena);
for (int i = 0; i < m; i++)
niz[i] += v[index][i];
cena += cene[index];
m2 = f(v, cene, n, m, x, niz, index + 1, cena);
return min(m1, m2);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
long long x, resenje;
cin >> n >> m >> x;
vector<long long> cena(n);
vector<vector<long long>> v(n, vector<long long>(m));
for (int i = 0; i < n; i++) {
cin >> cena[i];
for (int j = 0; j < m; j++)
cin >> v[i][j];
}
vector<long long> niz(n, 0);
resenje = f(v, cena, n, m, x, niz, 0, 0);
if (resenje == LLONG_MAX)
cout << -1;
else
cout << resenje;
}
| #include <bits/stdc++.h>
using namespace std;
bool provera(vector<long long> &niz, int &m, long long &x) {
for (int i = 0; i < m; i++)
if (niz[i] < x)
return false;
return true;
}
long long f(vector<vector<long long>> &v, vector<long long> &cene, int &n,
int &m, long long &x, vector<long long> niz, int index,
long long cena) {
if (index == n) {
if (provera(niz, m, x))
return cena;
else
return LLONG_MAX;
}
long long m1, m2;
m1 = f(v, cene, n, m, x, niz, index + 1, cena);
for (int i = 0; i < m; i++)
niz[i] += v[index][i];
cena += cene[index];
m2 = f(v, cene, n, m, x, niz, index + 1, cena);
return min(m1, m2);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
long long x, resenje;
cin >> n >> m >> x;
vector<long long> cena(n);
vector<vector<long long>> v(n, vector<long long>(m));
for (int i = 0; i < n; i++) {
cin >> cena[i];
for (int j = 0; j < m; j++)
cin >> v[i][j];
}
vector<long long> niz(m, 0);
resenje = f(v, cena, n, m, x, niz, 0, 0);
if (resenje == LLONG_MAX)
cout << -1;
else
cout << resenje;
}
| replace | 42 | 43 | 42 | 43 | 0 | |
p02683 | C++ | Runtime Error | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int x, int y) {
if (x < y)
swap(x, y);
int r = x % y;
if (r == 0) {
return y;
}
return gcd(y, r);
}
int main() {
int N, M, X;
cin >> N >> M >> X;
vector<int> C(N);
vector<vector<int>> A(N, vector<int>(M));
for (int i = 0; i < N; i++) {
cin >> C[i];
for (int j = 0; j < M; j++) {
cin >> A[i][j];
}
}
ll minSumC = 1e9;
bool bigFlag = false;
for (int tmp = 0; tmp < (1 << N); tmp++) {
bitset<12> book(tmp);
vector<ll> know(N);
ll sumC = 0;
bool flag = true;
for (int i = 0; i < N; i++) {
if (book.test(i)) {
sumC += C[i];
for (int j = 0; j < M; j++) {
know[j] += A[i][j];
}
}
}
for (int j = 0; j < M; j++) {
if (know[j] < X) {
flag = false;
break;
}
}
if (flag) {
minSumC = min(minSumC, sumC);
bigFlag = true;
}
}
if (bigFlag) {
cout << minSumC << endl;
} else {
cout << -1 << endl;
}
} | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int x, int y) {
if (x < y)
swap(x, y);
int r = x % y;
if (r == 0) {
return y;
}
return gcd(y, r);
}
int main() {
int N, M, X;
cin >> N >> M >> X;
vector<int> C(N);
vector<vector<int>> A(N, vector<int>(M));
for (int i = 0; i < N; i++) {
cin >> C[i];
for (int j = 0; j < M; j++) {
cin >> A[i][j];
}
}
ll minSumC = 1e9;
bool bigFlag = false;
for (int tmp = 0; tmp < (1 << N); tmp++) {
bitset<12> book(tmp);
vector<ll> know(M);
ll sumC = 0;
bool flag = true;
for (int i = 0; i < N; i++) {
if (book.test(i)) {
sumC += C[i];
for (int j = 0; j < M; j++) {
know[j] += A[i][j];
}
}
}
for (int j = 0; j < M; j++) {
if (know[j] < X) {
flag = false;
break;
}
}
if (flag) {
minSumC = min(minSumC, sumC);
bigFlag = true;
}
}
if (bigFlag) {
cout << minSumC << endl;
} else {
cout << -1 << endl;
}
} | replace | 30 | 31 | 30 | 31 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;
template <typename T> vector<T> make_v(size_t a, T b) {
return vector<T>(a, b);
}
template <typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<int> c(n);
vector<vector<int>> a(n, vector<int>(m));
rep(i, n) {
cin >> c[i];
rep(j, m) cin >> a[i][j];
}
int ans = numeric_limits<int>::max();
rep(b, (1 << n)) {
int t = 0;
vector<int> now(m, 0);
rep(i, n) {
if (b & (1 << i)) {
t += c[i];
rep(j, n) { now[j] += a[i][j]; }
}
}
bool f = all_of(now.begin(), now.end(), [&](int v) { return v >= x; });
if (f)
ans = min(ans, t);
}
if (ans == numeric_limits<int>::max())
ans = -1;
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;
template <typename T> vector<T> make_v(size_t a, T b) {
return vector<T>(a, b);
}
template <typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<int> c(n);
vector<vector<int>> a(n, vector<int>(m));
rep(i, n) {
cin >> c[i];
rep(j, m) cin >> a[i][j];
}
int ans = numeric_limits<int>::max();
rep(b, (1 << n)) {
int t = 0;
vector<int> now(m, 0);
rep(i, n) {
if (b & (1 << i)) {
t += c[i];
rep(j, m) { now[j] += a[i][j]; }
}
}
bool f = all_of(now.begin(), now.end(), [&](int v) { return v >= x; });
if (f)
ans = min(ans, t);
}
if (ans == numeric_limits<int>::max())
ans = -1;
cout << ans << endl;
return 0;
}
| replace | 33 | 34 | 33 | 34 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
#define two(a) (1 << (a))
#define LINF (1ll << 61)
#define EPS (1e-14)
#define Lshift(a, b) ((a) << (b))
#define Rshift(a, b) ((a) >> (b))
#define rep(a, b) for (a = 0; a < b; a++)
#define xrep(a, b, c) for (a = b; a < c; a++)
#define INF (1 << 29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a, b) ((a ^= b), (b ^= a), (a ^= b))
#define GET(x) (mark[x >> 5] >> (x & 31) & 1)
#define SET(x) (mark[x >> 5] |= 1 << (x & 31))
#define maxL (10000000 >> 5) + 1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;
int c[13];
int in[13][13];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, m, x;
cin >> n >> m >> x;
int i, j;
rep(i, n) {
cin >> c[i];
rep(j, m) { cin >> in[i][j]; }
}
ll s[n], k;
ll ans(LINF);
rep(i, two(n)) {
ll t(0);
memset(s, 0, sizeof(s));
rep(j, n) {
int tj = two(j);
if (tj & i) {
t += c[j];
rep(k, m) s[k] += in[j][k];
}
}
rep(j, m) {
if (s[j] < x)
break;
}
if (j == m) {
ans = min(ans, t);
}
}
if (ans == LINF)
ans = -1;
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define two(a) (1 << (a))
#define LINF (1ll << 61)
#define EPS (1e-14)
#define Lshift(a, b) ((a) << (b))
#define Rshift(a, b) ((a) >> (b))
#define rep(a, b) for (a = 0; a < b; a++)
#define xrep(a, b, c) for (a = b; a < c; a++)
#define INF (1 << 29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a, b) ((a ^= b), (b ^= a), (a ^= b))
#define GET(x) (mark[x >> 5] >> (x & 31) & 1)
#define SET(x) (mark[x >> 5] |= 1 << (x & 31))
#define maxL (10000000 >> 5) + 1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;
int c[13];
int in[13][13];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, m, x;
cin >> n >> m >> x;
int i, j;
rep(i, n) {
cin >> c[i];
rep(j, m) { cin >> in[i][j]; }
}
ll s[m], k;
ll ans(LINF);
rep(i, two(n)) {
ll t(0);
memset(s, 0, sizeof(s));
rep(j, n) {
int tj = two(j);
if (tj & i) {
t += c[j];
rep(k, m) s[k] += in[j][k];
}
}
rep(j, m) {
if (s[j] < x)
break;
}
if (j == m) {
ans = min(ans, t);
}
}
if (ans == LINF)
ans = -1;
cout << ans << endl;
}
| replace | 37 | 38 | 37 | 38 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.1415926535897932384626433832795028
#define INF (1 << 29)
#define LINF (1LL << 60)
using namespace std;
using INT = long long;
using P = pair<int, int>;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<vector<int>> c;
c.resize(n);
vector<int> ar(m, 0);
vector<int> cost(n);
rep(i, n) {
cin >> cost[i];
rep(j, m) {
int a;
cin >> a;
c[i].emplace_back(a);
}
}
int mini = INF;
rep(i, 1 << n) {
int cos = 0;
rep(j, n) {
if (i >> j & 1) {
rep(k, n) { ar[k] += c[j][k]; }
cos += cost[j];
}
}
rep(j, m) {
if (ar[j] < x) {
cos += INF;
break;
}
}
mini = min(mini, cos);
ar = vector<int>(m);
}
if (mini == INF)
cout << -1 << endl;
else
cout << mini << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.1415926535897932384626433832795028
#define INF (1 << 29)
#define LINF (1LL << 60)
using namespace std;
using INT = long long;
using P = pair<int, int>;
int main() {
int n, m, x;
cin >> n >> m >> x;
vector<vector<int>> c;
c.resize(n);
vector<int> ar(m, 0);
vector<int> cost(n);
rep(i, n) {
cin >> cost[i];
rep(j, m) {
int a;
cin >> a;
c[i].emplace_back(a);
}
}
int mini = INF;
rep(i, 1 << n) {
int cos = 0;
rep(j, n) {
if (i >> j & 1) {
rep(k, m) { ar[k] += c[j][k]; }
cos += cost[j];
}
}
rep(j, m) {
if (ar[j] < x) {
cos += INF;
break;
}
}
mini = min(mini, cos);
ar = vector<int>(m);
}
if (mini == INF)
cout << -1 << endl;
else
cout << mini << endl;
return 0;
}
| replace | 29 | 30 | 29 | 30 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pa pair<int, int>
#define pal pair<long long, long long>
#define pali pair<long long, int>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair
#define COUT(v) \
for (int64_t i = 0; i < (v).size(); ++i) { \
cout << v.at(i) << endl; \
}
#define REP(i, n) for (int64_t i = 0; i < n; ++i)
#define FOR(i, r, n) for (int64_t i = (r); i < n; ++i)
#define VIN(v) \
for (int64_t i = 0; i < (v).size(); ++i) { \
cin >> (v).at(i); \
}
typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pavec;
typedef vector<pali> palivec;
typedef vector<pal> palvec;
typedef vector<vector<bool>> bmat;
typedef vector<vector<int>> imat;
typedef vector<vector<long long>> lmat;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;
const ll MOD = 1000000007;
ll gcd(ll x, ll y) {
ll r = x % y;
if (r == 0)
return y;
else
return gcd(y, r);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }
lvec mfactor(ll n) {
bvec ip(n, true);
lvec mf(n, -1);
ip[0] = false;
ip[1] = false;
mf[0] = 0;
mf[1] = 1;
REP(i, n) {
if (ip[i]) {
mf[i] = i;
for (ll j = i * i; j < n; j += i) {
ip[j] = false;
if (mf[j] == -1)
mf[j] = i;
}
}
}
return mf;
}
palivec get_prime(ll n, const lvec &mf) {
palivec plist;
while (n != 1) {
int cnt = 0;
ll m = mf[n];
while (mf[n] == m) {
cnt++;
n /= m;
}
plist.pb(pali(m, cnt));
}
return plist;
}
void COMinit(int m, lvec &fac, lvec &finv) {
lvec inv(m);
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < m; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll pow_mod(ll a, ll n) {
ll x = 1;
while (n > 0) {
if (n & 1) {
x = x * a % MOD;
}
a = a * a % MOD;
n >>= 1;
}
return x;
}
ll pow_mod2(ll a, ll n) {
ll x = 1;
while (n > 0) {
if (n & 1) {
x = x * a;
}
a = a * a;
n >>= 1;
}
return x;
}
ll COM(int n, int k, const lvec &fac, const lvec &finv) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;
}
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;
}
// union by size + path having
class UnionFind {
public:
vector<ll> par;
vector<ll> siz;
// Constructor
UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
for (ll i = 0; i < sz_; ++i)
par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL);
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]];
}
return x;
}
// Union(Unite, Merge)
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
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)]; }
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m, x;
cin >> n >> m >> x;
lvec c(n);
lmat a(n, lvec(n));
for (int i = 0; i < n; i++) {
cin >> c[i];
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
ll inf = 1ll << 60;
ll ans = inf;
for (int i = 0; i < (1 << n); i++) {
lvec s(m, 0);
ll sc = 0;
for (int j = 0; j < n; j++) {
if ((i >> j) & 1) {
sc += c[j];
for (int k = 0; k < m; k++) {
s[k] += a[j][k];
}
}
}
bool flg = true;
for (int j = 0; j < m; j++) {
if (s[j] < x) {
flg = false;
break;
}
}
if (flg) {
ans = min(sc, ans);
}
}
if (ans == inf) {
cout << -1 << endl;
return 0;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pa pair<int, int>
#define pal pair<long long, long long>
#define pali pair<long long, int>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair
#define COUT(v) \
for (int64_t i = 0; i < (v).size(); ++i) { \
cout << v.at(i) << endl; \
}
#define REP(i, n) for (int64_t i = 0; i < n; ++i)
#define FOR(i, r, n) for (int64_t i = (r); i < n; ++i)
#define VIN(v) \
for (int64_t i = 0; i < (v).size(); ++i) { \
cin >> (v).at(i); \
}
typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pavec;
typedef vector<pali> palivec;
typedef vector<pal> palvec;
typedef vector<vector<bool>> bmat;
typedef vector<vector<int>> imat;
typedef vector<vector<long long>> lmat;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;
const ll MOD = 1000000007;
ll gcd(ll x, ll y) {
ll r = x % y;
if (r == 0)
return y;
else
return gcd(y, r);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }
lvec mfactor(ll n) {
bvec ip(n, true);
lvec mf(n, -1);
ip[0] = false;
ip[1] = false;
mf[0] = 0;
mf[1] = 1;
REP(i, n) {
if (ip[i]) {
mf[i] = i;
for (ll j = i * i; j < n; j += i) {
ip[j] = false;
if (mf[j] == -1)
mf[j] = i;
}
}
}
return mf;
}
palivec get_prime(ll n, const lvec &mf) {
palivec plist;
while (n != 1) {
int cnt = 0;
ll m = mf[n];
while (mf[n] == m) {
cnt++;
n /= m;
}
plist.pb(pali(m, cnt));
}
return plist;
}
void COMinit(int m, lvec &fac, lvec &finv) {
lvec inv(m);
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < m; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll pow_mod(ll a, ll n) {
ll x = 1;
while (n > 0) {
if (n & 1) {
x = x * a % MOD;
}
a = a * a % MOD;
n >>= 1;
}
return x;
}
ll pow_mod2(ll a, ll n) {
ll x = 1;
while (n > 0) {
if (n & 1) {
x = x * a;
}
a = a * a;
n >>= 1;
}
return x;
}
ll COM(int n, int k, const lvec &fac, const lvec &finv) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;
}
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;
}
// union by size + path having
class UnionFind {
public:
vector<ll> par;
vector<ll> siz;
// Constructor
UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
for (ll i = 0; i < sz_; ++i)
par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL);
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]];
}
return x;
}
// Union(Unite, Merge)
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
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)]; }
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m, x;
cin >> n >> m >> x;
lvec c(n);
lmat a(n, lvec(m));
for (int i = 0; i < n; i++) {
cin >> c[i];
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
ll inf = 1ll << 60;
ll ans = inf;
for (int i = 0; i < (1 << n); i++) {
lvec s(m, 0);
ll sc = 0;
for (int j = 0; j < n; j++) {
if ((i >> j) & 1) {
sc += c[j];
for (int k = 0; k < m; k++) {
s[k] += a[j][k];
}
}
}
bool flg = true;
for (int j = 0; j < m; j++) {
if (s[j] < x) {
flg = false;
break;
}
}
if (flg) {
ans = min(sc, ans);
}
}
if (ans == inf) {
cout << -1 << endl;
return 0;
}
cout << ans << endl;
} | replace | 193 | 194 | 193 | 194 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x;
cin >> n >> m >> x;
int c[50], a[50][50], sum[50], ans[50] = {0}, cnt = 0;
for (int i = 1; i <= n; i++) {
cin >> c[i];
for (int j = 1; j <= m; j++)
cin >> a[i][j];
}
for (int i = 0; i < (1 << n); i++) {
memset(sum, 0, sizeof(sum));
int cost = 0;
for (int j = 0; j < n; j++)
if (i & (1 << j)) {
cost += c[j + 1];
for (int k = 1; k <= m; k++)
sum[k] += a[j + 1][k];
}
bool bad = 0;
for (int j = 1; j <= m; j++)
if (sum[j] < x) {
bad = 1;
break;
}
if (!bad)
ans[++cnt] = cost;
}
sort(ans + 1, ans + cnt + 1);
if (ans[1] == 0)
cout << -1;
else
cout << ans[1];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x;
cin >> n >> m >> x;
int c[50], a[50][50], sum[50], ans[4097], cnt = 0;
memset(ans, 0, sizeof(ans));
for (int i = 1; i <= n; i++) {
cin >> c[i];
for (int j = 1; j <= m; j++)
cin >> a[i][j];
}
for (int i = 0; i < (1 << n); i++) {
memset(sum, 0, sizeof(sum));
int cost = 0;
for (int j = 0; j < n; j++)
if (i & (1 << j)) {
cost += c[j + 1];
for (int k = 1; k <= m; k++)
sum[k] += a[j + 1][k];
}
bool bad = 0;
for (int j = 1; j <= m; j++)
if (sum[j] < x) {
bad = 1;
break;
}
if (!bad)
ans[++cnt] = cost;
}
sort(ans + 1, ans + cnt + 1);
if (ans[1] == 0)
cout << -1;
else
cout << ans[1];
return 0;
} | replace | 5 | 6 | 5 | 7 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
int a[15][15];
int price[15];
int main() {
int n, m, x;
cin >> n >> m >> x;
rep(i, n) {
int c;
cin >> c;
price[i] = c;
rep(j, m) { cin >> a[i][j]; }
}
int ans = INF;
for (int bit = 0; bit < (1 << n); bit++) {
int understanding[n];
int sum_price = 0;
rep(i, m) understanding[i] = 0;
rep(i, n) {
if (bit & (1 << i)) {
sum_price += price[i];
rep(j, m) { understanding[j] += a[i][j]; }
}
}
bool ok = true;
rep(i, m) {
if (understanding[i] < x) {
ok = false;
break;
}
}
if (ok)
ans = min(ans, sum_price);
}
if (ans == INF) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
int a[15][15];
int price[15];
int main() {
int n, m, x;
cin >> n >> m >> x;
rep(i, n) {
int c;
cin >> c;
price[i] = c;
rep(j, m) { cin >> a[i][j]; }
}
int ans = INF;
for (int bit = 0; bit < (1 << n); bit++) {
int understanding[m];
int sum_price = 0;
rep(i, m) understanding[i] = 0;
rep(i, n) {
if (bit & (1 << i)) {
sum_price += price[i];
rep(j, m) { understanding[j] += a[i][j]; }
}
}
bool ok = true;
rep(i, m) {
if (understanding[i] < x) {
ok = false;
break;
}
}
if (ok)
ans = min(ans, sum_price);
}
if (ans == INF) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
}
| replace | 25 | 26 | 25 | 26 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int MIN_VAL = 1001001001;
int main(void) {
int N, M, X;
cin >> N >> M >> X;
vector<int> C(N);
int A[N][N];
for (int i = 0; i < N; i++) {
cin >> C[i];
for (int j = 0; j < M; j++) {
cin >> A[i][j];
}
}
long long int ans = MIN_VAL;
for (int b = 0; b < (1 << N); b++) {
long long int C_cktmp = 0;
vector<int> X_cktmp(M);
for (int i = 0; i < N; i++) {
if (b >> i & 1) {
C_cktmp += C[i];
for (int j = 0; j < M; j++) {
X_cktmp[j] += A[i][j];
}
}
}
bool flag = true;
for (int j = 0; j < M; j++) {
if (X_cktmp[j] < X)
flag = false;
}
if (flag)
ans = min(ans, C_cktmp);
}
if (ans == MIN_VAL)
cout << -1 << endl;
else
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int MIN_VAL = 1001001001;
int main(void) {
int N, M, X;
cin >> N >> M >> X;
vector<int> C(N);
int A[12][12];
for (int i = 0; i < N; i++) {
cin >> C[i];
for (int j = 0; j < M; j++) {
cin >> A[i][j];
}
}
long long int ans = MIN_VAL;
for (int b = 0; b < (1 << N); b++) {
long long int C_cktmp = 0;
vector<int> X_cktmp(M);
for (int i = 0; i < N; i++) {
if (b >> i & 1) {
C_cktmp += C[i];
for (int j = 0; j < M; j++) {
X_cktmp[j] += A[i][j];
}
}
}
bool flag = true;
for (int j = 0; j < M; j++) {
if (X_cktmp[j] < X)
flag = false;
}
if (flag)
ans = min(ans, C_cktmp);
}
if (ans == MIN_VAL)
cout << -1 << endl;
else
cout << ans << endl;
return 0;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p02683 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<ll>>;
int main() {
ll N, K, b;
cin >> N >> K >> b;
vector<vector<ll>> vec(N, vector<ll>(K + 1));
ll d = 0;
for (ll i = 0; i < N; i++) {
for (ll j = 0; j < K + 1; j++) {
cin >> vec.at(i).at(j);
}
d += vec.at(i).at(0);
}
d = d + 1;
ll re = d;
const ll n = N;
for (int tmp = 0; tmp < (1 << N); tmp++) {
bitset<8> s(tmp);
vector<ll> veco(K + 1, 0);
// ビット列を出力
for (ll i = 0; i < N; i++) {
for (ll k = 0; k < K + 1; k++) {
if (s.test(i)) {
veco.at(k) += vec.at(i).at(k);
}
}
}
for (ll i = 1; i < K + 1; i++) {
if (veco.at(i) < b)
break;
if (i == K) {
re = min(re, veco.at(0));
}
}
}
if (re == d) {
re = -1;
}
cout << re << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<ll>>;
int main() {
ll N, K, b;
cin >> N >> K >> b;
vector<vector<ll>> vec(N, vector<ll>(K + 1));
ll d = 0;
for (ll i = 0; i < N; i++) {
for (ll j = 0; j < K + 1; j++) {
cin >> vec.at(i).at(j);
}
d += vec.at(i).at(0);
}
d = d + 1;
ll re = d;
const ll n = N;
for (int tmp = 0; tmp < (1 << N); tmp++) {
bitset<12> s(tmp);
vector<ll> veco(K + 1, 0);
// ビット列を出力
for (ll i = 0; i < N; i++) {
for (ll k = 0; k < K + 1; k++) {
if (s.test(i)) {
veco.at(k) += vec.at(i).at(k);
}
}
}
for (ll i = 1; i < K + 1; i++) {
if (veco.at(i) < b)
break;
if (i == K) {
re = min(re, veco.at(0));
}
}
}
if (re == d) {
re = -1;
}
cout << re << endl;
return 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p02684 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <vector>
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
const int MAXN = 2e5 + 10;
const long long mod = 1e14;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x & (-x))
using namespace std;
// getline(cin,s);
// set<ll>::iterator it;
// map<int,int>::iterator it;
typedef long long ll;
typedef unsigned long long ull;
int vis[MAXN], a[MAXN], dist[MAXN];
int result[MAXN];
int main() {
int n, ans, need;
ull k;
scanf("%d %llu", &n, &k);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
queue<int> q;
q.push(1);
dist[1] = 0;
vis[1] = 1;
while (1) {
int now = q.front();
q.pop();
int ne = a[now];
vis[ne]++;
int d = dist[now] + 1;
if (vis[ne] == 2) {
ans = d - dist[ne];
need = ne;
break;
}
dist[ne] = d;
q.push(ne);
}
for (int i = 0; i < ans; i++) {
int now = need;
result[i] = now;
// printf("re: %d \n",result[i]);
need = a[now];
}
// printf("xunhuan: %d need: %d %d\n",ans,need,dist[need]);
if (k < dist[need]) {
int oo = 0, ans1;
queue<int> q1;
q1.push(1);
while (1) {
int now = q1.front();
q1.pop();
int ne = a[now];
oo++;
if (oo == k) {
ans1 = ne;
break;
}
q.push(ne);
}
printf("%d\n", ans1);
} else {
int m = (k - dist[need]) % ans;
// printf("%llu\n",m);
printf("%d\n", result[m]);
}
return 0;
} | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <vector>
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
const int MAXN = 2e5 + 10;
const long long mod = 1e14;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x & (-x))
using namespace std;
// getline(cin,s);
// set<ll>::iterator it;
// map<int,int>::iterator it;
typedef long long ll;
typedef unsigned long long ull;
int vis[MAXN], a[MAXN], dist[MAXN];
int result[MAXN];
int main() {
int n, ans, need;
ull k;
scanf("%d %llu", &n, &k);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
queue<int> q;
q.push(1);
dist[1] = 0;
vis[1] = 1;
while (1) {
int now = q.front();
q.pop();
int ne = a[now];
vis[ne]++;
int d = dist[now] + 1;
if (vis[ne] == 2) {
ans = d - dist[ne];
need = ne;
break;
}
dist[ne] = d;
q.push(ne);
}
for (int i = 0; i < ans; i++) {
int now = need;
result[i] = now;
// printf("re: %d \n",result[i]);
need = a[now];
}
// printf("xunhuan: %d need: %d %d\n",ans,need,dist[need]);
if (k < dist[need]) {
int oo = 0, ans1;
queue<int> q1;
q1.push(1);
while (1) {
int now = q1.front();
q1.pop();
int ne = a[now];
oo++;
if (oo == k) {
ans1 = ne;
break;
}
q1.push(ne);
}
printf("%d\n", ans1);
} else {
int m = (k - dist[need]) % ans;
// printf("%llu\n",m);
printf("%d\n", result[m]);
}
return 0;
} | replace | 75 | 76 | 75 | 76 | 0 | |
p02684 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
long long MOD = 1000000000 + 7;
int main() {
int N;
ll K;
cin >> N >> K;
int log_K = floor(log2(K));
cerr << N << " " << log_K << endl;
vector<vector<int>> next(log_K + 1, vector<int>(N));
for (int i = 0; i < N; i++) {
int tmp;
cin >> tmp;
cerr << i << " : " << tmp << endl;
next.at(0).at(i) = tmp - 1;
}
for (int k = 0; k < log_K; k++) {
for (int i = 0; i < N; i++) {
if (next[k][i] == -1) {
next[k + 1][i] = -1;
} else {
next[k + 1][i] = next[k][next[k][i]];
cerr << k + 1 << " " << i << " " << next[k + 1][i] << endl;
}
}
}
int ans = 0;
for (ll k = log_K; k >= 0; k--) {
if ((K >> k) & 1) {
ans = next[k][ans];
}
}
cout << ans + 1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
long long MOD = 1000000000 + 7;
int main() {
int N;
ll K;
cin >> N >> K;
int log_K = floor(log2(K));
cerr << N << " " << log_K << endl;
vector<vector<int>> next(log_K + 1, vector<int>(N));
for (int i = 0; i < N; i++) {
int tmp;
cin >> tmp;
cerr << i << " : " << tmp << endl;
next.at(0).at(i) = tmp - 1;
}
for (int k = 0; k < log_K; k++) {
for (int i = 0; i < N; i++) {
if (next[k][i] == -1) {
next[k + 1][i] = -1;
} else {
next[k + 1][i] = next[k][next[k][i]];
// cerr << k+1 << " " << i << " " << next[k+1][i] << endl;
}
}
}
int ans = 0;
for (ll k = log_K; k >= 0; k--) {
if ((K >> k) & 1) {
ans = next[k][ans];
}
}
cout << ans + 1 << endl;
} | replace | 29 | 30 | 29 | 30 | TLE | |
p02684 | C++ | Runtime Error | // 17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define MP make_pair
#define int long long
#define ll long long
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define ld long double
#define eb emplace_back
#define pii pair<int, int>
#define ull unsigned long long
#define all(v) v.begin(), v.end()
#define f(i, x, n) for (int i = x; i < n; i++)
#define fr(i, x, n) for (int i = x; i >= n; i--)
#define fastio ios::sync_with_stdio(false)
void IO() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
// IO();
fastio;
cin.tie(nullptr);
cout.tie(nullptr);
ll n, k;
cin >> n >> k;
vector<int> ar(n);
vector<int> C;
vector<bool> vis(200002, 0);
for (int i = 1; i <= n; i++) {
cin >> ar[i];
}
int pos = 1;
int stp = 0;
while (k && stp <= 100000000) {
pos = ar[pos];
++stp;
--k;
}
int st = pos;
while (1) {
vis[st] = true;
C.pb(st);
st = ar[st];
if (vis[st])
break;
}
cout << C[k % (C.size())] << endl;
return 0;
} | // 17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define MP make_pair
#define int long long
#define ll long long
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define ld long double
#define eb emplace_back
#define pii pair<int, int>
#define ull unsigned long long
#define all(v) v.begin(), v.end()
#define f(i, x, n) for (int i = x; i < n; i++)
#define fr(i, x, n) for (int i = x; i >= n; i--)
#define fastio ios::sync_with_stdio(false)
void IO() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
// IO();
fastio;
cin.tie(nullptr);
cout.tie(nullptr);
ll n, k;
cin >> n >> k;
vector<int> ar(200002);
vector<int> C;
vector<bool> vis(200002, 0);
for (int i = 1; i <= n; i++) {
cin >> ar[i];
}
int pos = 1;
int stp = 0;
while (k && stp <= 100000000) {
pos = ar[pos];
++stp;
--k;
}
int st = pos;
while (1) {
vis[st] = true;
C.pb(st);
st = ar[st];
if (vis[st])
break;
}
cout << C[k % (C.size())] << endl;
return 0;
} | replace | 34 | 35 | 34 | 35 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
#define loop(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void) {
ll n, k;
cin >> n >> k;
vector<int> a(n), s, done(n + 1, -1);
int c = 1, l = 0;
loop(i, n) {
cin >> a[i];
done[i] = false;
}
int v = 1;
while (done[v] == -1) {
done[v] = s.size();
s.emplace_back(v);
v = a[v - 1];
}
c = s.size() - done[v];
l = done[v];
if (k < l)
cout << s[k] << endl;
else {
k -= l;
k %= c;
cout << s[l + k] << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define loop(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void) {
ll n, k;
cin >> n >> k;
vector<int> a(n), s, done(n + 1, -1);
int c = 1, l = 0;
loop(i, n) { cin >> a[i]; }
int v = 1;
while (done[v] == -1) {
done[v] = s.size();
s.emplace_back(v);
v = a[v - 1];
}
c = s.size() - done[v];
l = done[v];
if (k < l)
cout << s[k] << endl;
else {
k -= l;
k %= c;
cout << s[l + k] << endl;
}
return 0;
} | replace | 12 | 16 | 12 | 13 | -8 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
int N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
A[i]--;
}
vector<int> G(0);
vector<int> kai(N, 0);
int now = 0, fin = 0, saki = 0, sta = 0;
G.push_back(0);
while (G.size() < N) {
G.push_back(A[now]);
if (kai[A[now]] == 0) {
kai[A[now]]++;
now = A[now];
continue;
} else {
fin = G.size();
saki = A[now];
G.erase(G.end() - 1);
for (int i = 0; i < fin - 1; i++) {
if (G[i] == saki) {
sta = i;
break;
}
}
fin -= 1;
break;
}
}
int ans;
if (K < fin)
ans = G[K];
else {
int mod = fin - sta;
ans = G[sta + (K - sta) % mod];
}
cout << ans + 1 << endl;
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
int N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
A[i]--;
}
vector<int> G(0);
vector<int> kai(N, 0);
int now = 0, fin = 0, saki = 0, sta = 0;
G.push_back(0);
while (G.size() <= N) {
G.push_back(A[now]);
if (kai[A[now]] == 0) {
kai[A[now]]++;
now = A[now];
continue;
} else {
fin = G.size();
saki = A[now];
G.erase(G.end() - 1);
for (int i = 0; i < fin - 1; i++) {
if (G[i] == saki) {
sta = i;
break;
}
}
fin -= 1;
break;
}
}
int ans;
if (K < fin)
ans = G[K];
else {
int mod = fin - sta;
ans = G[sta + (K - sta) % mod];
}
cout << ans + 1 << endl;
} | replace | 16 | 17 | 16 | 17 | -8 | |
p02684 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT \
cin.tie(0); \
ios::sync_with_stdio(false);
template <class T> inline bool chmax(T &a, T b) { return a = (a < b) ? b : a; }
template <class T> inline bool chmin(T &a, T b) { return a = (a > b) ? b : a; }
ll const INF = 1LL << 60;
ll const MOD = 1000000007;
ll const MAX_V = 200005;
// 辺に属性がある場合
// 頂点toへのコストcostの辺
struct edge {
ll to, cost;
};
vector<edge> G[MAX_V];
int main() {
INIT;
ll N, K;
cin >> N >> K;
vector<ll> A(N);
rep(i, N) cin >> A[i];
for (ll i = 0; i < N; i++) {
// sからtへの辺を張る
A[i]--;
edge et = {A[i], 1};
G[i].push_back(et);
// // 無向グラフの場合はさらにtにsへの辺を張る
// edge es = {i, 1};
// G[A[i]].push_back(es);
}
vector<ll> visited(N + 5, -1);
ll nv = 0;
ll first_visit = -1;
ll loop_visit, loop_v;
rep(i, K) {
if (visited[nv] > 0 && nv != 0) {
first_visit = visited[nv];
loop_visit = i - first_visit;
loop_v = nv;
break;
}
visited[nv] = i;
nv = G[nv][0].to;
}
if (first_visit == -1) {
cout << nv + 1 << endl;
return 0;
}
// rep(i, N) { cout << visited[i] << " "; }
// cout << endl;
rep(i, N) { visited[i] -= first_visit; }
// rep(i, N) { cout << visited[i] << " "; }
// cout << endl;
ll loop_num = (K - first_visit) / loop_visit;
ll last_k = loop_num * loop_visit + first_visit;
// cout << "loop_v: " << loop_v << ", loop_visit:" << loop_visit << ", "
// << K - last_k << endl;
rep(i, N) {
if (visited[i] == K - last_k) {
cout << i + 1 << endl;
return 0;
}
}
// nv = loop_v;
// reps(i, last_k, K) { nv = G[nv][0].to; }
// cout << nv + 1 << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT \
cin.tie(0); \
ios::sync_with_stdio(false);
template <class T> inline bool chmax(T &a, T b) { return a = (a < b) ? b : a; }
template <class T> inline bool chmin(T &a, T b) { return a = (a > b) ? b : a; }
ll const INF = 1LL << 60;
ll const MOD = 1000000007;
ll const MAX_V = 200005;
// 辺に属性がある場合
// 頂点toへのコストcostの辺
struct edge {
ll to, cost;
};
vector<edge> G[MAX_V];
int main() {
INIT;
ll N, K;
cin >> N >> K;
vector<ll> A(N);
rep(i, N) cin >> A[i];
for (ll i = 0; i < N; i++) {
// sからtへの辺を張る
A[i]--;
edge et = {A[i], 1};
G[i].push_back(et);
// // 無向グラフの場合はさらにtにsへの辺を張る
// edge es = {i, 1};
// G[A[i]].push_back(es);
}
vector<ll> visited(N + 5, -1);
ll nv = 0;
ll first_visit = -1;
ll loop_visit, loop_v;
rep(i, K) {
if (visited[nv] > 0) {
first_visit = visited[nv];
loop_visit = i - first_visit;
loop_v = nv;
break;
}
visited[nv] = i;
nv = G[nv][0].to;
}
if (first_visit == -1) {
cout << nv + 1 << endl;
return 0;
}
// rep(i, N) { cout << visited[i] << " "; }
// cout << endl;
rep(i, N) { visited[i] -= first_visit; }
// rep(i, N) { cout << visited[i] << " "; }
// cout << endl;
ll loop_num = (K - first_visit) / loop_visit;
ll last_k = loop_num * loop_visit + first_visit;
// cout << "loop_v: " << loop_v << ", loop_visit:" << loop_visit << ", "
// << K - last_k << endl;
rep(i, N) {
if (visited[i] == K - last_k) {
cout << i + 1 << endl;
return 0;
}
}
// nv = loop_v;
// reps(i, last_k, K) { nv = G[nv][0].to; }
// cout << nv + 1 << endl;
return 0;
} | replace | 68 | 69 | 68 | 69 | TLE | |
p02684 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;
#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) \
sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORL(i, a, b) for (LL i = (a); i < (b); ++i)
#define REPL(i, n) FORL(i, 0, n)
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
const double EPS = 1e-10;
const double PI = acos(-1.0);
// debug func
template <typename T> void vprint(vector<T> v) {
for (auto x : v) {
cerr << x << " ";
}
cerr << endl;
}
template <typename T> void vvprint(vector<vector<T>> vv) {
REP(i, SIZE(vv)) {
REP(j, SIZE(vv[i])) { cerr << vv[i][j] << " "; }
cerr << endl;
}
}
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k,
const Iterator last) {
/* Credits: Thomas Draper */
if ((first == last) || (first == k) || (last == k))
return false;
Iterator itr1 = first;
Iterator itr2 = last;
++itr1;
if (last == itr1)
return false;
itr1 = last;
--itr1;
itr1 = k;
--itr2;
while (first != itr1) {
if (*--itr1 < *itr2) {
Iterator j = k;
while (!(*itr1 < *j))
++j;
iter_swap(itr1, j);
++itr1;
++j;
itr2 = k;
rotate(itr1, j, last);
while (last != j) {
++j;
++itr2;
}
rotate(k, itr2, last);
return true;
}
}
rotate(first, k, last);
return false;
}
inline double get_time_sec(void) {
return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(
chrono::steady_clock::now().time_since_epoch())
.count()) /
1000000000;
}
template <typename T> T gcd(T a, T b) {
if (a > b)
swap(a, b);
if (a == 0)
return b;
else
return gcd(b % a, a);
}
template <typename T> T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
template <typename T> map<T, T> prime_list(T n) {
map<T, T> ret;
for (T i = 2; i * i <= n; i++) {
if (n % i == 0) {
ret[i] = 0;
while (n % i == 0) {
n /= i;
ret[i]++;
}
}
}
if (n != 1)
ret[n]++;
return ret;
}
#define MOD 1000000007
LL mypow(LL a, LL n) {
if (n == 1)
return a % MOD;
if (n % 2 == 1)
return (a * mypow(a, n - 1)) % MOD;
LL t = mypow(a, n / 2);
return (t * t) % MOD;
}
LL mycomb(LL n, LL k) {
if (n == 0 || n == k)
return 1;
LL x = 1, y = 1;
REP(i, k) {
x = x * (n - i) % MOD;
y = y * (i + 1) % MOD;
}
return x * mypow(y, MOD - 2) % MOD;
}
#define INF 1e8
int main(void) {
LL n, k;
cin >> n >> k;
VLL a(n);
REP(i, n) {
cin >> a[i];
a[i]--;
}
VLL p(1, 0);
VI done(n, 0);
int start;
FOR(i, 1, n) {
p.push_back(a[p[i - 1]]);
if (done[a[p[i - 1]]]) {
start = a[p[i - 1]];
break;
} else
done[a[p[i - 1]]] = 1;
}
// vprint(p);
// cout << start << endl;
int si;
while (start != p[si])
si++;
// cerr << si << endl;
VLL q;
FOR(i, si, p.size() - 1) q.push_back(p[i]);
// vprint(q);
k -= si;
LL idx = k % (LL)(q.size());
cout << q[idx] + 1 << endl;
} | #include "bits/stdc++.h"
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;
#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) \
sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORL(i, a, b) for (LL i = (a); i < (b); ++i)
#define REPL(i, n) FORL(i, 0, n)
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
const double EPS = 1e-10;
const double PI = acos(-1.0);
// debug func
template <typename T> void vprint(vector<T> v) {
for (auto x : v) {
cerr << x << " ";
}
cerr << endl;
}
template <typename T> void vvprint(vector<vector<T>> vv) {
REP(i, SIZE(vv)) {
REP(j, SIZE(vv[i])) { cerr << vv[i][j] << " "; }
cerr << endl;
}
}
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k,
const Iterator last) {
/* Credits: Thomas Draper */
if ((first == last) || (first == k) || (last == k))
return false;
Iterator itr1 = first;
Iterator itr2 = last;
++itr1;
if (last == itr1)
return false;
itr1 = last;
--itr1;
itr1 = k;
--itr2;
while (first != itr1) {
if (*--itr1 < *itr2) {
Iterator j = k;
while (!(*itr1 < *j))
++j;
iter_swap(itr1, j);
++itr1;
++j;
itr2 = k;
rotate(itr1, j, last);
while (last != j) {
++j;
++itr2;
}
rotate(k, itr2, last);
return true;
}
}
rotate(first, k, last);
return false;
}
inline double get_time_sec(void) {
return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(
chrono::steady_clock::now().time_since_epoch())
.count()) /
1000000000;
}
template <typename T> T gcd(T a, T b) {
if (a > b)
swap(a, b);
if (a == 0)
return b;
else
return gcd(b % a, a);
}
template <typename T> T lcm(T a, T b) { return (a / gcd(a, b)) * b; }
template <typename T> map<T, T> prime_list(T n) {
map<T, T> ret;
for (T i = 2; i * i <= n; i++) {
if (n % i == 0) {
ret[i] = 0;
while (n % i == 0) {
n /= i;
ret[i]++;
}
}
}
if (n != 1)
ret[n]++;
return ret;
}
#define MOD 1000000007
LL mypow(LL a, LL n) {
if (n == 1)
return a % MOD;
if (n % 2 == 1)
return (a * mypow(a, n - 1)) % MOD;
LL t = mypow(a, n / 2);
return (t * t) % MOD;
}
LL mycomb(LL n, LL k) {
if (n == 0 || n == k)
return 1;
LL x = 1, y = 1;
REP(i, k) {
x = x * (n - i) % MOD;
y = y * (i + 1) % MOD;
}
return x * mypow(y, MOD - 2) % MOD;
}
#define INF 1e8
int main(void) {
LL n, k;
cin >> n >> k;
VLL a(n);
REP(i, n) {
cin >> a[i];
a[i]--;
}
VLL p(1, 0);
VI done(n, 0);
int start;
FOR(i, 1, n) {
p.push_back(a[p[i - 1]]);
if (done[a[p[i - 1]]]) {
start = a[p[i - 1]];
break;
} else
done[a[p[i - 1]]] = 1;
}
// vprint(p);
// cout << start << endl;
int si;
while (start != p[si])
si++;
// cerr << si << endl;
VLL q;
FOR(i, si, p.size() - 1) q.push_back(p[i]);
// vprint(q);
if (k < si) {
cout << p[k] + 1 << endl;
} else {
k -= si;
k += q.size();
LL idx = k % (LL)(q.size());
cout << q[idx] + 1 << endl;
}
} | replace | 170 | 173 | 170 | 178 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
/* 大文字を小文字に変換 */
char tolower(char c) { return (c + 0x20); }
/* 小文字を大文字に変換 */
char toupr(char c) { return (c - 0x20); }
// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';
/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
// イテレータ要素のインデックス
distance(A.begin(), itr);
*/
const int MAX_N = 100100;
int P[65][MAX_N]; // 10**18 == 2*60だから
int main() {
ll N, K;
cin >> N >> K;
int A[N];
rep(i, N) {
cin >> A[i];
A[i]--;
}
rep(i, 65) {
if (i == 0) {
rep(j, N) P[i][j] = A[j];
} else {
rep(j, N) P[i][j] = P[i - 1][P[i - 1][j]];
}
}
bitset<65> Kbit(K);
int cur = 0;
for (int i = 64; i >= 0; i--) {
if (Kbit.test(i)) {
cur = P[i][cur];
}
}
cur++;
cout << cur << endl;
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
/* 大文字を小文字に変換 */
char tolower(char c) { return (c + 0x20); }
/* 小文字を大文字に変換 */
char toupr(char c) { return (c - 0x20); }
// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';
/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
// イテレータ要素のインデックス
distance(A.begin(), itr);
*/
const int MAX_N = 200100;
int P[65][MAX_N]; // 10**18 == 2*60だから
int main() {
ll N, K;
cin >> N >> K;
int A[N];
rep(i, N) {
cin >> A[i];
A[i]--;
}
rep(i, 65) {
if (i == 0) {
rep(j, N) P[i][j] = A[j];
} else {
rep(j, N) P[i][j] = P[i - 1][P[i - 1][j]];
}
}
bitset<65> Kbit(K);
int cur = 0;
for (int i = 64; i >= 0; i--) {
if (Kbit.test(i)) {
cur = P[i][cur];
}
}
cur++;
cout << cur << endl;
} | replace | 23 | 24 | 23 | 24 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using lli = long long;
using pii = pair<int, int>;
#define rep(i, k, n) for (int i = (k); i != int(n); ++i)
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define dbg(x) cout << #x << '=' << x << '\n'
#define dbg2(x, y) cout << #x << '=' << x << ' ' << #y << '=' << y << '\n'
#define input() (*istream_iterator<lli>(cin))
#define strin() (*istream_iterator<string>(cin))
#define output(x) cout << x << '\n'
const int mxn = 2e5 + 10;
lli arr[mxn];
bool is_visit[mxn];
int find_loop(int cur = 1) {
is_visit[cur] = true;
int nx = arr[cur];
if (is_visit[nx])
return nx;
find_loop(nx);
}
int main() {
ios::sync_with_stdio(false);
lli n = input(), k = input();
vector<int> cycle;
int cur = 1, dist = 0;
for (int i = 1; i <= n; ++i)
arr[i] = input();
int loop_town = find_loop();
// dbg(loop_town);
while (cur != loop_town) {
cur = arr[cur];
dist++;
if (dist == k) {
cout << cur;
return 0;
}
}
// dbg(dist);
k -= dist;
cur = arr[loop_town];
cycle.push_back(loop_town);
while (cur != loop_town) {
cycle.push_back(cur);
cur = arr[cur];
}
// for(int cur: cycle) cout << cur;
k %= cycle.size();
cout << cycle[k];
} | #include <bits/stdc++.h>
using namespace std;
using lli = long long;
using pii = pair<int, int>;
#define rep(i, k, n) for (int i = (k); i != int(n); ++i)
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define dbg(x) cout << #x << '=' << x << '\n'
#define dbg2(x, y) cout << #x << '=' << x << ' ' << #y << '=' << y << '\n'
#define input() (*istream_iterator<lli>(cin))
#define strin() (*istream_iterator<string>(cin))
#define output(x) cout << x << '\n'
const int mxn = 2e5 + 10;
lli arr[mxn];
bool is_visit[mxn];
int find_loop(int cur = 1) {
is_visit[cur] = true;
int nx = arr[cur];
if (is_visit[nx])
return nx;
return find_loop(nx);
}
int main() {
ios::sync_with_stdio(false);
lli n = input(), k = input();
vector<int> cycle;
int cur = 1, dist = 0;
for (int i = 1; i <= n; ++i)
arr[i] = input();
int loop_town = find_loop();
// dbg(loop_town);
while (cur != loop_town) {
cur = arr[cur];
dist++;
if (dist == k) {
cout << cur;
return 0;
}
}
// dbg(dist);
k -= dist;
cur = arr[loop_town];
cycle.push_back(loop_town);
while (cur != loop_town) {
cycle.push_back(cur);
cur = arr[cur];
}
// for(int cur: cycle) cout << cur;
k %= cycle.size();
cout << cycle[k];
} | replace | 24 | 25 | 24 | 25 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
}
if (k <= 200000) {
int q = 0;
while (k) {
q = a[q];
k--;
}
cout << q + 1 << endl;
return 0;
}
vector<int> visited(n, -1);
vector<int> last(n, -1);
int p = 0, c = 0;
for (int i = 0; i < last.size(); i++) {
visited[p]++;
if (visited[p] == 2) {
c = i - last[p];
break;
}
last[p] = i;
p = a[p];
}
// cout << c << endl;
k -= last[p];
k %= c;
while (k) {
p = a[p];
k--;
}
cout << p + 1 << endl;
} | #include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
}
if (k <= 200000) {
int q = 0;
while (k) {
q = a[q];
k--;
}
cout << q + 1 << endl;
return 0;
}
vector<int> visited(n, 0);
vector<int> last(n, 0);
int p = 0, c = 0;
for (int i = 0; i < last.size(); i++) {
visited[p]++;
if (visited[p] == 2) {
c = i - last[p];
break;
}
last[p] = i;
p = a[p];
}
// cout << c << endl;
k -= last[p];
k %= c;
while (k) {
p = a[p];
k--;
}
cout << p + 1 << endl;
} | replace | 22 | 24 | 22 | 24 | 0 | |
p02684 | C++ | Runtime Error | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
map<ll, ll> mp;
ll point = 1;
ll loop, start;
vector<ll> vec;
for (int i = 0; i <= n + 3; i++) {
if (mp.count(point)) {
start = mp[point];
loop = i - start;
break;
}
// cout << point << endl;
vec.push_back(point);
mp[point] = i;
point = a[point];
}
// cout << a[6] << endl;
// for (ll x : vec) cout << x << endl;
if (k < start) {
cout << vec[k] << endl;
return 0;
}
// cout << loop << endl;
// cout << start << endl;
k -= start;
ll p = k % loop;
ll ans = vec[start + p];
cout << ans << endl;
return 0;
} | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
map<ll, ll> mp;
ll point = 1;
ll loop, start;
vector<ll> vec;
for (int i = 0; i <= n + 3; i++) {
if (mp.count(point)) {
start = mp[point];
loop = i - start;
break;
}
// cout << point << endl;
vec.push_back(point);
mp[point] = i;
point = a[point];
}
// cout << a[6] << endl;
// for (ll x : vec) cout << x << endl;
if (k < start) {
cout << vec[k] << endl;
return 0;
}
// cout << loop << endl;
// cout << start << endl;
k -= start;
ll p = k % loop;
ll ans = vec[start + p];
cout << ans << endl;
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02684 | C++ | Runtime Error | /***************************************** START OF TEMPLATE
* *********************************************/
#include <bits/stdc++.h>
using namespace std;
#define SPEED \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0); \
cout << fixed; \
cout << setprecision(10);
#define randomINIT \
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define foo(i, a, n) for (ll i = (a); i <= n; i++)
#define frr(i, a, n) for (ll i = (a); i >= n; i--)
#define fo(i, n) for (ll i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define mset(x, val) memset(x, val, sizeof(x))
#define newl cout << "\n"
#define f first
#define s second
#define pb push_back
#define INPa(a, n) foo(i, 1, n) cin >> a[i];
#define deb2d(a, n, m) \
foo(i, 1, n) { \
foo(j, 1, m) { cout << a[i][j] << " "; } \
newl; \
}
#define deb1d(a, n) \
foo(i, 1, n) cout << a[i] << " "; \
newl;
#define debv(a) \
for (auto it : a) \
cout << it << " "; \
newl;
#define deb1(a) \
cout << a << " "; \
newl;
#define deb2(a, b) \
cout << a << " " << b << " "; \
newl;
#define deb3(a, b, c) \
cout << a << " " << b << " " << c << " "; \
newl;
#define deb4(a, b, c, d) \
cout << a << " " << b << " " << c << " " << d; \
newl;
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
const ll MOD = 1e+9 + 7;
const ll INF = LLONG_MAX;
const int INFi = INT_MAX;
const ll N = 2e+5 + 8;
vll adj[N];
ll vis[N];
ll dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};
ll test_cases = 1;
randomINIT;
/*********************************************************************************************************/
/***************************************** VARIABLE DECLARATIONS
* *****************************************/
ll n, k, u, v, a[N], mark = 0;
stack<ll> sk;
vll path;
/***************************************** FUNCTION IMPLEMENTATIONS
* **************************************/
void dfs(ll v, ll p, ll d) {
vis[v] = 1;
sk.push(v);
if (d == k) {
cout << v;
exit(0);
}
for (auto to : adj[v]) {
if (to == p)
continue;
if (vis[to] == 1) {
mark = d + 1;
while (sk.top() != to) {
path.pb(sk.top());
sk.pop();
}
path.pb(sk.top());
sk.pop();
reverse(all(path));
}
if (mark > 0)
return;
if (vis[to] == 0)
dfs(to, v, d + 1);
}
vis[v] = 2;
}
/***************************************** START OF MAIN FUNCTION
* ****************************************/
void MAIN(ll tc) {
cin >> n >> k;
foo(i, 1, n) cin >> a[i];
foo(i, 1, n) adj[i].pb(a[i]);
dfs(1, -1, 0);
ll sz = path.size();
k -= mark;
cout << path[k % sz];
}
int main() {
SPEED;
// cin>>test_cases;
foo(i, 1, test_cases) { MAIN(i); }
} | /***************************************** START OF TEMPLATE
* *********************************************/
#include <bits/stdc++.h>
using namespace std;
#define SPEED \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0); \
cout << fixed; \
cout << setprecision(10);
#define randomINIT \
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define foo(i, a, n) for (ll i = (a); i <= n; i++)
#define frr(i, a, n) for (ll i = (a); i >= n; i--)
#define fo(i, n) for (ll i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define mset(x, val) memset(x, val, sizeof(x))
#define newl cout << "\n"
#define f first
#define s second
#define pb push_back
#define INPa(a, n) foo(i, 1, n) cin >> a[i];
#define deb2d(a, n, m) \
foo(i, 1, n) { \
foo(j, 1, m) { cout << a[i][j] << " "; } \
newl; \
}
#define deb1d(a, n) \
foo(i, 1, n) cout << a[i] << " "; \
newl;
#define debv(a) \
for (auto it : a) \
cout << it << " "; \
newl;
#define deb1(a) \
cout << a << " "; \
newl;
#define deb2(a, b) \
cout << a << " " << b << " "; \
newl;
#define deb3(a, b, c) \
cout << a << " " << b << " " << c << " "; \
newl;
#define deb4(a, b, c, d) \
cout << a << " " << b << " " << c << " " << d; \
newl;
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
const ll MOD = 1e+9 + 7;
const ll INF = LLONG_MAX;
const int INFi = INT_MAX;
const ll N = 2e+5 + 8;
vll adj[N];
ll vis[N];
ll dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};
ll test_cases = 1;
randomINIT;
/*********************************************************************************************************/
/***************************************** VARIABLE DECLARATIONS
* *****************************************/
ll n, k, u, v, a[N], mark = 0;
stack<ll> sk;
vll path;
/***************************************** FUNCTION IMPLEMENTATIONS
* **************************************/
void dfs(ll v, ll p, ll d) {
vis[v] = 1;
sk.push(v);
if (d == k) {
cout << v;
exit(0);
}
for (auto to : adj[v]) {
if (vis[to] == 1) {
mark = d + 1;
while (sk.top() != to) {
path.pb(sk.top());
sk.pop();
}
path.pb(sk.top());
sk.pop();
reverse(all(path));
}
if (mark > 0)
return;
if (vis[to] == 0)
dfs(to, v, d + 1);
}
vis[v] = 2;
}
/***************************************** START OF MAIN FUNCTION
* ****************************************/
void MAIN(ll tc) {
cin >> n >> k;
foo(i, 1, n) cin >> a[i];
foo(i, 1, n) adj[i].pb(a[i]);
dfs(1, -1, 0);
ll sz = path.size();
k -= mark;
cout << path[k % sz];
}
int main() {
SPEED;
// cin>>test_cases;
foo(i, 1, test_cases) { MAIN(i); }
} | delete | 83 | 85 | 83 | 83 | 0 | |
p02684 | C++ | Runtime Error | // #pragma GCC optimize(3,"Ofast","inline")
// #pragma GCC optimize(2)
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
// #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21,
// stdin), p1 == p2) ? EOF : *p1++) char buf[(1 << 21) + 1], * p1 = buf, * p2 =
// buf; #define int long long
#define lowbit(x) (x & (-x))
#define lson root << 1, l, mid
#define rson root << 1 | 1, mid + 1, r
#define pb push_back
typedef unsigned long long ull;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> VI;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define SZ(x) ((int)((x).size()))
#define bug puts("BUG")
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-6;
template <class T> inline void read(T &x) {
int sign = 1;
char c = getchar();
x = 0;
while (c > '9' || c < '0') {
if (c == '-')
sign = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
x *= sign;
}
#ifdef LOCAL
FILE *_INPUT = freopen("input.txt", "r", stdin);
// FILE* _OUTPUT=freopen("output.txt", "w", stdout);
#endif
using namespace std;
const int maxn = 1e5 + 10;
const int DEG = 64;
ll des[maxn][DEG];
int main() {
ll n, v, k;
read(n), read(k);
for (int i = 1; i <= n; ++i) {
read(des[i][0]);
}
for (int i = 1; i < DEG; ++i) {
for (int j = 1; j <= n; ++j) {
des[j][i] = des[des[j][i - 1]][i - 1];
}
}
int cur = 1;
for (int i = 0; k; k >>= 1, ++i) {
if (k & 1)
cur = des[cur][i];
}
printf("%lld\n", cur);
} | // #pragma GCC optimize(3,"Ofast","inline")
// #pragma GCC optimize(2)
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
// #define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21,
// stdin), p1 == p2) ? EOF : *p1++) char buf[(1 << 21) + 1], * p1 = buf, * p2 =
// buf; #define int long long
#define lowbit(x) (x & (-x))
#define lson root << 1, l, mid
#define rson root << 1 | 1, mid + 1, r
#define pb push_back
typedef unsigned long long ull;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> VI;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define SZ(x) ((int)((x).size()))
#define bug puts("BUG")
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-6;
template <class T> inline void read(T &x) {
int sign = 1;
char c = getchar();
x = 0;
while (c > '9' || c < '0') {
if (c == '-')
sign = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
x *= sign;
}
#ifdef LOCAL
FILE *_INPUT = freopen("input.txt", "r", stdin);
// FILE* _OUTPUT=freopen("output.txt", "w", stdout);
#endif
using namespace std;
const int maxn = 2e5 + 10;
const int DEG = 64;
ll des[maxn][DEG];
int main() {
ll n, v, k;
read(n), read(k);
for (int i = 1; i <= n; ++i) {
read(des[i][0]);
}
for (int i = 1; i < DEG; ++i) {
for (int j = 1; j <= n; ++j) {
des[j][i] = des[des[j][i - 1]][i - 1];
}
}
int cur = 1;
for (int i = 0; k; k >>= 1, ++i) {
if (k & 1)
cur = des[cur][i];
}
printf("%lld\n", cur);
} | replace | 58 | 59 | 58 | 59 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
ll n, k;
vector<ll> v(10000), c(10000);
cin >> n >> k;
for (ll i = 0; i < n; i++) {
cin >> v[i];
v[i]--;
}
ll now = 0;
bool can = true;
for (ll i = 1; i <= k; i++) {
if (c[now] && can) {
can = false;
ll tmp = abs(c[now] - i);
i += tmp * ((k - i) / tmp);
}
c[now] = i;
now = v[now];
}
cout << now + 1 << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
ll n, k;
vector<ll> v(1000000), c(1000000);
cin >> n >> k;
for (ll i = 0; i < n; i++) {
cin >> v[i];
v[i]--;
}
ll now = 0;
bool can = true;
for (ll i = 1; i <= k; i++) {
if (c[now] && can) {
can = false;
ll tmp = abs(c[now] - i);
i += tmp * ((k - i) / tmp);
}
c[now] = i;
now = v[now];
}
cout << now + 1 << endl;
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define REPA(i, a) \
for (ll i = 0; i < (ll)(a.size()); i++) \
;
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i, a) \
for (ll i = 0; i < (ll)(a.size()); i++) { \
cout << (a)[i] << " "; \
} \
cout << endl;
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000
const double PI = 3.14159265358979323846; // or M_PI
void Main() {
ll n, k, d, count = 0, roop = 0, roop_start = 0, in_a;
ifstream in("sub1_22.txt");
cin.rdbuf(in.rdbuf());
cin >> n >> k;
vector<ll> a;
vector<ll> dest;
vector<ll> ikeru_check(n + 1, -1);
a.push_back(0);
REP(i, n) {
cin >> in_a;
a.push_back(in_a);
}
// COUTA(i, a);
d = 1;
REP(i, k) {
if (ikeru_check[d] != -1) {
roop_start = ikeru_check[d];
roop = count - ikeru_check[d];
// COUT(roop);
break;
}
ikeru_check[d] = count;
dest.push_back(d);
d = a[d];
count++;
}
dest.push_back(d);
// COUT(count);
// COUT(k);
// COUT(dest.size());
vector<ll> l(dest.begin() + roop_start, dest.end());
// COUTA(i, dest);
// COUTA(i, l);
if (k <= count) {
COUT(dest[k]);
} else {
COUT(l[((k - roop_start) % roop)]);
}
// COUT(count);
// COUTA(i, a);
// COUTA(i, dest);
// COUTA(i, ikeru_check);
// COUT(roop);
// COUT(roop_start);
// COUT(k % roop);
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
}
| #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define REPA(i, a) \
for (ll i = 0; i < (ll)(a.size()); i++) \
;
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i, a) \
for (ll i = 0; i < (ll)(a.size()); i++) { \
cout << (a)[i] << " "; \
} \
cout << endl;
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000
const double PI = 3.14159265358979323846; // or M_PI
void Main() {
ll n, k, d, count = 0, roop = 0, roop_start = 0, in_a;
// ifstream in("sub1_22.txt");
// cin.rdbuf(in.rdbuf());
cin >> n >> k;
vector<ll> a;
vector<ll> dest;
vector<ll> ikeru_check(n + 1, -1);
a.push_back(0);
REP(i, n) {
cin >> in_a;
a.push_back(in_a);
}
// COUTA(i, a);
d = 1;
REP(i, k) {
if (ikeru_check[d] != -1) {
roop_start = ikeru_check[d];
roop = count - ikeru_check[d];
// COUT(roop);
break;
}
ikeru_check[d] = count;
dest.push_back(d);
d = a[d];
count++;
}
dest.push_back(d);
// COUT(count);
// COUT(k);
// COUT(dest.size());
vector<ll> l(dest.begin() + roop_start, dest.end());
// COUTA(i, dest);
// COUTA(i, l);
if (k <= count) {
COUT(dest[k]);
} else {
COUT(l[((k - roop_start) % roop)]);
}
// COUT(count);
// COUTA(i, a);
// COUTA(i, dest);
// COUTA(i, ikeru_check);
// COUT(roop);
// COUT(roop_start);
// COUT(k % roop);
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
}
| replace | 40 | 42 | 40 | 42 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02684 | C++ | Runtime Error | #include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const int D = 60; // 2の60乗まででダブリングの表が足りるので60.
const int MAX_N = 200010;
int to[D][MAX_N];
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
long long k;
cin >> n >> k;
REP(i, n) {
cin >> to[0][i];
to[0][i]--;
}
// ダブリングの表をセットする
REP(i, D - 1) REP(j, n) { to[i + 1][j] = to[i][to[j][i]]; }
// k を2の指数表記で分解して,
// 指数の大きい方から辿っていく.
int v = 0;
for (int i = D - 1; i >= 0; i--) {
long long l = 1ll << i;
if (l <= k) {
v = to[i][v];
k -= l;
}
}
cout << v + 1 << '\n';
return 0;
} | #include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const int D = 60; // 2の60乗まででダブリングの表が足りるので60.
const int MAX_N = 200010;
int to[D][MAX_N];
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
long long k;
cin >> n >> k;
REP(i, n) {
cin >> to[0][i];
to[0][i]--;
}
// ダブリングの表をセットする
REP(i, D - 1) REP(j, n) { to[i + 1][j] = to[i][to[i][j]]; }
// k を2の指数表記で分解して,
// 指数の大きい方から辿っていく.
int v = 0;
for (int i = D - 1; i >= 0; i--) {
long long l = 1ll << i;
if (l <= k) {
v = to[i][v];
k -= l;
}
}
cout << v + 1 << '\n';
return 0;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
bool b[200001];
int a[200001];
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
b[i] = false;
}
int c = 0;
int p = 1;
while (b[p] == false) {
b[p] = true;
p = a[p];
c++;
}
// cout << p << endl;
int x = 1;
int c0 = 1;
if (p != 1) {
while (a[x] != p) {
x = a[x];
c0++;
}
}
// cout << c0 << endl;
// cout << c << endl;
if (k <= c) {
} else {
k = ((k - c0) % (c - c0)) + c0;
}
p = 1;
while (k > 0) {
p = a[p];
k--;
}
cout << p << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
bool b[200001];
int a[200001];
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
b[i] = false;
}
int c = 0;
int p = 1;
while (b[p] == false) {
b[p] = true;
p = a[p];
c++;
}
// cout << p << endl;
int x = 1;
int c0 = 0;
while (x != p) {
x = a[x];
c0++;
}
// cout << c0 << endl;
// cout << c << endl;
if (k <= c) {
} else {
k = ((k - c0) % (c - c0)) + c0;
}
p = 1;
while (k > 0) {
p = a[p];
k--;
}
cout << p << endl;
return 0;
}
| replace | 23 | 29 | 23 | 27 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long A[200005], C[200005];
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
long long N, K;
cin >> N >> K;
for (long long i = 1; i <= N; ++i) {
cin >> A[i];
}
long long curr = 1, move = 1, len, moves;
vector<long long> cycle;
C[curr] = move;
while (1) {
move++;
curr = A[curr];
if (C[curr] > 0) {
len = move - C[curr];
break;
}
C[curr] = move;
}
long long shift = C[curr] - C[1];
for (long long i = 0; i < len; ++i) {
cycle.push_back(curr);
curr = A[curr];
}
moves = (K - shift) % len;
long long town = cycle[moves];
cout << town << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long A[200005], C[200005];
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
long long N, K;
cin >> N >> K;
for (long long i = 1; i <= N; ++i) {
cin >> A[i];
}
long long curr = 1, move = 1, len, moves;
if (K <= N) {
while (K--)
curr = A[curr];
cout << curr << '\n';
return 0;
}
vector<long long> cycle;
C[curr] = move;
while (1) {
move++;
curr = A[curr];
if (C[curr] > 0) {
len = move - C[curr];
break;
}
C[curr] = move;
}
long long shift = C[curr] - C[1];
for (long long i = 0; i < len; ++i) {
cycle.push_back(curr);
curr = A[curr];
}
moves = (K - shift) % len;
long long town = cycle[moves];
cout << town << '\n';
return 0;
} | insert | 17 | 17 | 17 | 23 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define mod 1e9 + 7;
#define INF 1e9 + 9;
#define ps(x, y) fixed << setprecision(y) << x
typedef long long ll;
typedef unsigned long long ull;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
ll n, k;
cin >> n >> k;
ll a[n + 1];
for (ll i = 1; i < n + 1; i++)
cin >> a[i];
vector<ll> v;
unordered_set<ll> us;
v.push_back(1);
us.insert(1);
int i = 0, t = 10, req;
while (t--) {
// cout<<a[v[i]]<<" ";
if (us.count(a[v[i]]) == 0) {
v.push_back(a[v[i]]);
us.insert(a[v[i]]);
} else {
req = a[v[i]];
break;
}
i++;
}
ll nn = v.size();
ll bc, ac;
for (int i = 0; i < nn; i++) {
if (v[i] == req) {
bc = i;
ac = nn - i;
break;
}
}
// cout<<bc<<" "<<ac<<endl;
if (k < bc) {
cout << v[k] << endl;
} else {
k = k - bc;
ll need = k % ac;
cout << v[need + bc] << endl;
}
/*for(ll x :v)
cout<<x<<" ";
cout<<endl;*/
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define mod 1e9 + 7;
#define INF 1e9 + 9;
#define ps(x, y) fixed << setprecision(y) << x
typedef long long ll;
typedef unsigned long long ull;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
ll n, k;
cin >> n >> k;
ll a[n + 1];
for (ll i = 1; i < n + 1; i++)
cin >> a[i];
vector<ll> v;
unordered_set<ll> us;
v.push_back(1);
us.insert(1);
int i = 0, req;
while (1) {
// cout<<a[v[i]]<<" ";
if (us.count(a[v[i]]) == 0) {
v.push_back(a[v[i]]);
us.insert(a[v[i]]);
} else {
req = a[v[i]];
break;
}
i++;
}
ll nn = v.size();
ll bc, ac;
for (int i = 0; i < nn; i++) {
if (v[i] == req) {
bc = i;
ac = nn - i;
break;
}
}
// cout<<bc<<" "<<ac<<endl;
if (k < bc) {
cout << v[k] << endl;
} else {
k = k - bc;
ll need = k % ac;
cout << v[need + bc] << endl;
}
/*for(ll x :v)
cout<<x<<" ";
cout<<endl;*/
return 0;
} | replace | 25 | 27 | 25 | 27 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define watch(x) \
; \
cout << #x << "=" << x << endl;
#define watch2(x, y) \
; \
cout << #x << "=" << x << " " << #y << "=" << y << endl;
#define endl "\n"
#define int long long
using namespace std;
int n, k;
vector<int> adj[200005];
vector<char> color;
vector<int> parent;
int cycle_start, cycle_end;
bool dfs(int v) {
color[v] = 1;
for (int u : adj[v]) {
if (color[u] == 0) {
parent[u] = v;
if (dfs(u))
return true;
} else if (color[u] == 1) {
cycle_end = v;
cycle_start = u;
return true;
}
}
color[v] = 2;
return false;
}
vector<int> arr;
void find_cycle() {
color.assign(n, 0);
parent.assign(n, -1);
cycle_start = -1;
for (int v = 0; v < n; v++) {
if (color[v] == 0 && dfs(v))
break;
}
if (cycle_start == -1) {
cout << "Acyclic" << endl;
} else {
vector<int> cycle;
// cycle.push_back(cycle_start);
for (int v = cycle_end; v != cycle_start; v = parent[v])
cycle.push_back(v);
cycle.push_back(cycle_start);
reverse(cycle.begin(), cycle.end());
int cnt = 0;
int i = 1;
int start = cycle[0];
vector<int> path;
while (i != start) {
i = arr[i];
path.push_back(i);
cnt++;
}
// for(auto it:path)cout<<it<<" ";
// cout<<endl;
// watch(cnt);
// cout << "Cycle found: ";
// for (int v : cycle)
// cout << v << " ";
// cout << endl;
if (k <= cnt) {
cout << path[k - 1];
} else {
k -= cnt;
int cyclesize = cycle.size();
// watch(cyclesize);
// cout<<k<<endl;
k = (k % cyclesize);
// cout<<k<<endl;
cout << cycle[k];
}
}
}
int32_t main() {
fast
// int n,k;
cin >>
n >> k;
arr.resize(n + 1);
for (int i = 1; i <= n; i++) {
cin >> arr[i];
adj[i].push_back(arr[i]);
}
find_cycle();
return 0;
}
| #include <bits/stdc++.h>
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define watch(x) \
; \
cout << #x << "=" << x << endl;
#define watch2(x, y) \
; \
cout << #x << "=" << x << " " << #y << "=" << y << endl;
#define endl "\n"
#define int long long
using namespace std;
int n, k;
vector<int> adj[200005];
vector<char> color;
vector<int> parent;
int cycle_start, cycle_end;
bool dfs(int v) {
color[v] = 1;
for (int u : adj[v]) {
if (color[u] == 0) {
parent[u] = v;
if (dfs(u))
return true;
} else if (color[u] == 1) {
cycle_end = v;
cycle_start = u;
return true;
}
}
color[v] = 2;
return false;
}
vector<int> arr;
void find_cycle() {
color.assign(n + 1, 0);
parent.assign(n + 1, -1);
cycle_start = -1;
for (int v = 0; v < n; v++) {
if (color[v] == 0 && dfs(v))
break;
}
if (cycle_start == -1) {
cout << "Acyclic" << endl;
} else {
vector<int> cycle;
// cycle.push_back(cycle_start);
for (int v = cycle_end; v != cycle_start; v = parent[v])
cycle.push_back(v);
cycle.push_back(cycle_start);
reverse(cycle.begin(), cycle.end());
int cnt = 0;
int i = 1;
int start = cycle[0];
vector<int> path;
while (i != start) {
i = arr[i];
path.push_back(i);
cnt++;
}
// for(auto it:path)cout<<it<<" ";
// cout<<endl;
// watch(cnt);
// cout << "Cycle found: ";
// for (int v : cycle)
// cout << v << " ";
// cout << endl;
if (k <= cnt) {
cout << path[k - 1];
} else {
k -= cnt;
int cyclesize = cycle.size();
// watch(cyclesize);
// cout<<k<<endl;
k = (k % cyclesize);
// cout<<k<<endl;
cout << cycle[k];
}
}
}
int32_t main() {
fast
// int n,k;
cin >>
n >> k;
arr.resize(n + 1);
for (int i = 1; i <= n; i++) {
cin >> arr[i];
adj[i].push_back(arr[i]);
}
find_cycle();
return 0;
}
| replace | 39 | 41 | 39 | 41 | 0 | |
p02684 | C++ | Runtime Error | /*
Created by Ezio112
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define inf ll(10e16)
#define mod ll(10e8 + 7)
#define ff first
#define ss second
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t;
// cin>>t;
t = 1;
while (t--) {
ll n, k;
cin >> n >> k;
vector<ll> ar(n + 1);
for (ll i = 1; i <= n; ++i)
cin >> ar[i];
unordered_map<ll, ll> appeared;
ll start = 1, jumps = 1, loop_size = 0;
while (k--) {
appeared[start] = jumps++;
start = ar[start];
if (appeared.count(start)) {
loop_size = jumps - appeared[start];
break;
}
}
k %= loop_size;
while (k--) {
start = ar[start];
}
cout << start;
}
return 0;
}
| /*
Created by Ezio112
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define inf ll(10e16)
#define mod ll(10e8 + 7)
#define ff first
#define ss second
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t;
// cin>>t;
t = 1;
while (t--) {
ll n, k;
cin >> n >> k;
vector<ll> ar(n + 1);
for (ll i = 1; i <= n; ++i)
cin >> ar[i];
unordered_map<ll, ll> appeared;
ll start = 1, jumps = 1, loop_size = 1;
while (k--) {
appeared[start] = jumps++;
start = ar[start];
if (appeared.count(start)) {
loop_size = jumps - appeared[start];
break;
}
}
k %= loop_size;
while (k--) {
start = ar[start];
}
cout << start;
}
return 0;
}
| replace | 28 | 29 | 28 | 29 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int INF = 0x7f7f7f7f;
int A[MAXN];
int L[MAXN];
int Re[MAXN];
bool Vis[MAXN];
int main() {
int N;
long long K;
cin >> N >> K;
for (int i = 1; i <= N; ++i)
cin >> A[i];
int r = 0, pos = 1;
Vis[1] = true;
L[0] = 1;
Re[1] = 0;
while (1) {
pos = A[pos];
L[++r] = pos;
if (Vis[pos])
break;
Re[pos] = r;
Vis[pos] = true;
}
K = min(K, 1ll * Re[pos]) + max(0ll, K - Re[pos]) % (r - Re[pos]);
cout << L[K] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const int INF = 0x7f7f7f7f;
int A[MAXN];
int L[MAXN];
int Re[MAXN];
bool Vis[MAXN];
int main() {
int N;
long long K;
cin >> N >> K;
for (int i = 1; i <= N; ++i)
cin >> A[i];
int r = 0, pos = 1;
Vis[1] = true;
L[0] = 1;
Re[1] = 0;
while (1) {
pos = A[pos];
L[++r] = pos;
if (Vis[pos])
break;
Re[pos] = r;
Vis[pos] = true;
}
K = min(K, 1ll * Re[pos]) + max(0ll, K - Re[pos]) % (r - Re[pos]);
cout << L[K] << endl;
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02684 | C++ | Runtime Error | #include <iostream>
using namespace std;
typedef long long ll;
int main() {
const int MAX_N = 1e5 + 10;
ll N, K;
int A[MAX_N], B[MAX_N];
cin >> N >> K;
for (int i = 0; i < N; ++i) {
int a;
cin >> a;
A[i] = a - 1;
B[i] = -1;
}
B[0] = 0;
int v = 0, cost = 0;
while (B[A[v]] == -1) {
B[A[v]] = ++cost;
v = A[v];
}
int offset = B[A[v]];
int mod = ++cost - offset;
int step = K <= offset ? K : (K - offset) % mod + offset;
int res = 0;
for (int i = 0; i < step; ++i) {
res = A[res];
}
cout << res + 1 << endl;
return 0;
} | #include <iostream>
using namespace std;
typedef long long ll;
int main() {
const int MAX_N = 2e5 + 10;
ll N, K;
int A[MAX_N], B[MAX_N];
cin >> N >> K;
for (int i = 0; i < N; ++i) {
int a;
cin >> a;
A[i] = a - 1;
B[i] = -1;
}
B[0] = 0;
int v = 0, cost = 0;
while (B[A[v]] == -1) {
B[A[v]] = ++cost;
v = A[v];
}
int offset = B[A[v]];
int mod = ++cost - offset;
int step = K <= offset ? K : (K - offset) % mod + offset;
int res = 0;
for (int i = 0; i < step; ++i) {
res = A[res];
}
cout << res + 1 << endl;
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02684 | C++ | Runtime Error | #include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int64_t N, K;
cin >> N >> K;
int32_t Ai[100001];
int64_t Aiused[100001];
int32_t realstate[100000];
for (int i = 1; i <= N; ++i) {
cin >> Ai[i];
Aiused[i] = -1;
realstate[i - 1] = 0;
}
int64_t mod = K + 1;
int64_t offset = 0;
Aiused[1] = 0;
realstate[0] = 1;
int32_t jump = Ai[1];
int64_t i;
for (i = 1; i <= K; i++) {
if (Aiused[jump] < 0) {
Aiused[jump] = i;
realstate[i] = jump; /*current city*/
jump = Ai[jump]; /*next city*/
} else {
offset = Aiused[jump];
mod = i - offset;
break;
}
// cout<<i<<"city"<<realstate[i]<<"next"<<jump<<endl;
}
/*
cout<<Ai[jump]<<endl;
cout<<i<<endl;
cout<<mod<<endl;
cout<<offset<<endl;
*/
uint64_t valnum = offset + ((K - offset) % mod);
cout << realstate[valnum] << endl;
}
| #include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int64_t N, K;
cin >> N >> K;
int32_t Ai[200001];
int64_t Aiused[200001];
int32_t realstate[200000];
for (int i = 1; i <= N; ++i) {
cin >> Ai[i];
Aiused[i] = -1;
realstate[i - 1] = 0;
}
int64_t mod = K + 1;
int64_t offset = 0;
Aiused[1] = 0;
realstate[0] = 1;
int32_t jump = Ai[1];
int64_t i;
for (i = 1; i <= K; i++) {
if (Aiused[jump] < 0) {
Aiused[jump] = i;
realstate[i] = jump; /*current city*/
jump = Ai[jump]; /*next city*/
} else {
offset = Aiused[jump];
mod = i - offset;
break;
}
// cout<<i<<"city"<<realstate[i]<<"next"<<jump<<endl;
}
/*
cout<<Ai[jump]<<endl;
cout<<i<<endl;
cout<<mod<<endl;
cout<<offset<<endl;
*/
uint64_t valnum = offset + ((K - offset) % mod);
cout << realstate[valnum] << endl;
}
| replace | 9 | 12 | 9 | 12 | 0 | |
p02684 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n) \
cerr << __LINE__ << ": " << #x << " = {"; \
for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
cerr << ((hoge) ? "," : "") << x[hoge]; \
cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long N, K;
cin >> N >> K;
int A[N];
for (int i = 0; i < N; i++)
cin >> A[i], A[i]--;
map<pair<int, long long>, int> memo;
function<int(int, long long)> rec = [&](int v, long long k) {
if (memo.count(make_pair(v, k)))
return memo[make_pair(v, k)];
if (k == 1)
return A[v];
int u = rec(v, k / 2);
if (k & 1)
u = A[u];
return memo[make_pair(v, k)] = rec(u, k / 2);
};
cout << rec(0, K) + 1 << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n) \
cerr << __LINE__ << ": " << #x << " = {"; \
for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
cerr << ((hoge) ? "," : "") << x[hoge]; \
cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long N, K;
cin >> N >> K;
int A[N];
for (int i = 0; i < N; i++)
cin >> A[i], A[i]--;
int to[80][N];
for (int i = 0; i < N; i++)
to[0][i] = A[i];
for (int k = 1; k < 80; k++) {
for (int i = 0; i < N; i++) {
to[k][i] = to[k - 1][to[k - 1][i]];
}
}
int ans = 0;
for (int j = 63; j >= 0; j--) {
if ((K >> j) & 1)
ans = to[j][ans];
}
cout << ans + 1 << endl;
return 0;
}
| replace | 27 | 39 | 27 | 41 | TLE | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define int long long
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }
typedef pair<int, int> pii;
typedef long long ll;
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;
int N, a;
string k;
int G[100010];
bool used[100010];
bool comp(string a, string b) {
if (a.length() != b.length())
return a.length() > b.length();
else
return a > b;
}
signed main() {
cin >> N >> k;
a = 0;
rep(i, 0, N) {
int to;
cin >> to;
G[i] = to - 1;
}
vector<int> v;
int C = 0, T = 0;
while (1) {
used[a] = true;
v.push_back(a);
a = G[a];
if (used[a])
break;
}
T = find(v.begin(), v.end(), a) - v.begin();
C = v.size() - T;
if (comp(k, to_string(T))) {
int mo = 0;
rep(i, 0, k.length()) { mo = (mo * 10 + k[i] - '0') % C; }
mo = (mo - (T % C) + C) % C;
cout << v[T + mo] + 1 << endl;
} else {
int step = atoi(k.c_str());
cout << v[step] + 1 << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define repr(i, a, n) for (int(i) = (a); (i) >= (n); (i)--)
#define int long long
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }
typedef pair<int, int> pii;
typedef long long ll;
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;
int N, a;
string k;
int G[300010];
bool used[300010];
bool comp(string a, string b) {
if (a.length() != b.length())
return a.length() > b.length();
else
return a > b;
}
signed main() {
cin >> N >> k;
a = 0;
rep(i, 0, N) {
int to;
cin >> to;
G[i] = to - 1;
}
vector<int> v;
int C = 0, T = 0;
while (1) {
used[a] = true;
v.push_back(a);
a = G[a];
if (used[a])
break;
}
T = find(v.begin(), v.end(), a) - v.begin();
C = v.size() - T;
if (comp(k, to_string(T))) {
int mo = 0;
rep(i, 0, k.length()) { mo = (mo * 10 + k[i] - '0') % C; }
mo = (mo - (T % C) + C) % C;
cout << v[T + mo] + 1 << endl;
} else {
int step = atoi(k.c_str());
cout << v[step] + 1 << endl;
}
return 0;
}
| replace | 16 | 18 | 16 | 18 | 0 | |
p02684 | C++ | Runtime Error | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif
#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define f(i, x, n) for (int i = x; i <= n; i++)
#define fr(i, x, n) for (int i = x; i >= n; i--)
struct _ {
ios_base::Init i;
_() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); }
} _;
int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
long long n, k;
long long st = 0;
vector<long long> a(maxn, 0);
vector<bool> vis(maxn, false);
vector<long long> path;
void dfs(long long curr) {
if (vis[curr] == true) {
st = curr;
return;
}
vis[curr] = true;
path.push_back(curr);
dfs(a[curr]);
}
int main() {
cin >> n >> k;
for (long long i = 1; i <= n; i++)
cin >> a[i];
dfs(1);
debug(path);
vector<long long> new_path;
for (auto i : path) {
if (new_path.empty() == false)
new_path.push_back(i);
else if (i == st)
new_path.push_back(i);
}
debug(new_path);
long long x = (long long)path.size() - (long long)new_path.size();
k -= x;
k %= ((long long)new_path.size());
cout << new_path[k];
return 0;
} | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif
#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define f(i, x, n) for (int i = x; i <= n; i++)
#define fr(i, x, n) for (int i = x; i >= n; i--)
struct _ {
ios_base::Init i;
_() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); }
} _;
int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
long long n, k;
long long st = 0;
vector<long long> a(maxn, 0);
vector<bool> vis(maxn, false);
vector<long long> path;
void dfs(long long curr) {
if (vis[curr] == true) {
st = curr;
return;
}
vis[curr] = true;
path.push_back(curr);
dfs(a[curr]);
}
int main() {
cin >> n >> k;
for (long long i = 1; i <= n; i++)
cin >> a[i];
dfs(1);
debug(path);
vector<long long> new_path;
for (auto i : path) {
if (new_path.empty() == false)
new_path.push_back(i);
else if (i == st)
new_path.push_back(i);
}
debug(new_path);
long long x = (long long)path.size() - (long long)new_path.size();
if (k < x) {
cout << path[k];
exit(0);
}
k -= x;
k %= ((long long)new_path.size());
cout << new_path[k];
return 0;
} | insert | 120 | 120 | 120 | 126 | 0 | |
p02684 | C++ | Runtime Error | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
const int MAX = 2000;
const int X = 64;
int main() {
unsigned long long N, K;
int A[MAX][X];
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> A[i][0];
A[i][0]--;
}
for (int i = 1; i < X; i++) {
for (int j = 0; j < N; j++) {
A[j][i] = A[A[j][i - 1]][i - 1];
}
}
int ans = 0;
int cnt = X - 1;
while (K) {
while (K >= (1ULL << cnt)) {
ans = A[ans][cnt];
K -= (1ULL << cnt);
}
cnt--;
}
cout << ans + 1 << endl;
return 0;
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
const int MAX = 200000;
const int X = 64;
int main() {
unsigned long long N, K;
int A[MAX][X];
cin >> N >> K;
for (int i = 0; i < N; i++) {
cin >> A[i][0];
A[i][0]--;
}
for (int i = 1; i < X; i++) {
for (int j = 0; j < N; j++) {
A[j][i] = A[A[j][i - 1]][i - 1];
}
}
int ans = 0;
int cnt = X - 1;
while (K) {
while (K >= (1ULL << cnt)) {
ans = A[ans][cnt];
K -= (1ULL << cnt);
}
cnt--;
}
cout << ans + 1 << endl;
return 0;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define MAX 20000005
#define fastcin \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
using namespace std;
ll vis[MAX], cycle[MAX];
map<ll, ll> ttime;
map<ll, ll> inverstime;
void solve() {
ll n, k;
cin >> n >> k;
ll v[n + 1];
for (int i = 1; i <= n; i++)
cin >> v[i];
ll j = 1, t = 0;
while (vis[j] == 0) {
ttime[t] = j;
inverstime[j] = t;
vis[j] = 1;
j = v[j];
t++;
}
if (k < t) {
cout << ttime[k] << endl;
return;
}
ll init = j, d = t - inverstime[j];
cycle[0] = init;
j = v[init];
for (int i = 1;; i++) {
if (j == init)
break;
cycle[i] = j;
j = v[j];
}
k -= ttime[init];
cout << cycle[k % d] << endl;
}
int main() {
fastcin solve();
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define MAX 20000005
#define fastcin \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
using namespace std;
ll vis[MAX], cycle[MAX];
map<ll, ll> ttime;
map<ll, ll> inverstime;
void solve() {
ll n, k;
cin >> n >> k;
ll v[n + 1];
for (int i = 1; i <= n; i++)
cin >> v[i];
ll j = 1, t = 0;
while (vis[j] == 0) {
ttime[t] = j;
inverstime[j] = t;
vis[j] = 1;
j = v[j];
t++;
}
if (k < t) {
cout << ttime[k] << endl;
return;
}
ll init = j, d = t - inverstime[j];
cycle[0] = init;
j = v[init];
for (int i = 1;; i++) {
if (j == init)
break;
cycle[i] = j;
j = v[j];
}
k -= t - d;
cout << cycle[k % d] << endl;
}
int main() {
fastcin solve();
return 0;
}
| replace | 47 | 48 | 47 | 49 | -11 | |
p02684 | C++ | Runtime Error | // AtCoder template
// 最近sabaがかまってくれないからキレて暴れてる
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// 入力
int n;
ll k;
cin >> n >> k;
vector<int> a(n);
rep(i, n) {
cin >> a[i];
a[i]--;
}
// サイクル検出
vector<bool> visited(n, false);
int now = 0;
int start;
while (true) {
if (visited[now]) {
start = now;
break;
}
visited[now] = true;
now = a[now];
}
// サイクル長を求める
ll cycle_d = 0;
now = start;
visited.assign(n, false);
vector<int> cycle;
while (true) {
if (visited[now]) {
break;
}
cycle.push_back(now);
visited[now] = true;
now = a[now];
cycle_d++;
}
// 0からサイクル始点までの距離を求める
ll dist = 0;
now = 0;
while (true) {
if (now == start) {
break;
}
now = a[now];
dist++;
}
// 計算
// 出力
cout << cycle[(k - dist) % cycle_d] + 1 << endl;
} | // AtCoder template
// 最近sabaがかまってくれないからキレて暴れてる
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// 入力
int n;
ll k;
cin >> n >> k;
vector<int> a(n);
rep(i, n) {
cin >> a[i];
a[i]--;
}
// サイクル検出
vector<bool> visited(n, false);
int now = 0;
int start;
while (true) {
if (visited[now]) {
start = now;
break;
}
visited[now] = true;
now = a[now];
}
// サイクル長を求める
ll cycle_d = 0;
now = start;
visited.assign(n, false);
vector<int> cycle;
while (true) {
if (visited[now]) {
break;
}
cycle.push_back(now);
visited[now] = true;
now = a[now];
cycle_d++;
}
// 0からサイクル始点までの距離を求める
ll dist = 0;
now = 0;
while (true) {
if (now == start) {
break;
}
now = a[now];
dist++;
}
// 計算
// 出力
if (k >= dist)
cout << cycle[(k - dist) % cycle_d] + 1 << endl;
else {
now = 0;
while (k) {
now = a[now];
k--;
}
cout << now + 1 << endl;
}
} | replace | 63 | 64 | 63 | 73 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> Vl;
typedef pair<int, int> pii;
typedef vector<pii> Vll;
typedef vector<pair<int, pair<int, int>>> Vlll;
#define S second
#define F first
#define mp make_pair
#define ms(x, y) memset(x, y, sizeof(x))
#define pb push_back
#define sl(n) cin >> n
#define pl(n) cout << n << " "
const int Nx = 1e5 + 2;
const int inf = (int)(1e9 + 10LL);
void solve() {
int n, k;
sl(n);
sl(k);
Vl arr(n + 1);
for (int i = 1; i <= n; i++)
sl(arr[i]);
unordered_map<int, int> freq;
int i = 1;
int pivot, start = 1;
freq[1] = 0;
int value;
for (i = 1; i <= k; i++) {
start = arr[start];
if (freq[start] > 0) {
pivot = i - freq[start];
value = start;
break;
}
freq[start] = i;
// cout<<start<<" ";
}
k = (k - freq[value]) % pivot;
start = value;
for (int i = 1; i <= k; i++) {
start = arr[start];
}
cout << start << endl;
}
signed main() {
int test = 1;
// sl(test);
while (test--) {
solve();
}
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> Vl;
typedef pair<int, int> pii;
typedef vector<pii> Vll;
typedef vector<pair<int, pair<int, int>>> Vlll;
#define S second
#define F first
#define mp make_pair
#define ms(x, y) memset(x, y, sizeof(x))
#define pb push_back
#define sl(n) cin >> n
#define pl(n) cout << n << " "
const int Nx = 1e5 + 2;
const int inf = (int)(1e9 + 10LL);
void solve() {
int n, k;
sl(n);
sl(k);
Vl arr(n + 1);
for (int i = 1; i <= n; i++)
sl(arr[i]);
unordered_map<int, int> freq;
int i = 1;
int pivot, start = 1;
freq[1] = 0;
int value;
for (i = 1; i <= k; i++) {
start = arr[start];
if (freq[start] > 0) {
pivot = i - freq[start];
value = start;
break;
}
freq[start] = i;
// cout<<start<<" ";
}
if (i >= k) {
cout << start << endl;
return;
}
k = (k - freq[value]) % pivot;
start = value;
for (int i = 1; i <= k; i++) {
start = arr[start];
}
cout << start << endl;
}
signed main() {
int test = 1;
// sl(test);
while (test--) {
solve();
}
} | insert | 38 | 38 | 38 | 43 | 0 | |
p02684 | C++ | Runtime Error | /*"Success isn't permanent, failure isn't fatal,
it's the courage to continue that counts"*/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> ordered_set;
#define ll long long
#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define lpri(n) printf("%lld", n)
#define pri(n) printf("%d", n)
#define pln() printf("\n")
#define priln(n) printf("%d\n", n)
#define lpriln(n) printf("%lld\n", n)
#define rep(i, init, n) for (int i = init; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod = 1e9 + 7;
const int N = 1e5 + 4;
const int lim = 61;
int dp[N][64];
int main() {
int n;
ll k;
scn(n);
lscn(k);
rep(i, 1, n + 1) scn(dp[i][0]);
rep(i, 1, lim) {
rep(node, 1, n + 1) dp[node][i] = dp[dp[node][i - 1]][i - 1];
}
int cur = 1;
rep(i, 0, lim) if (k & (1LL << i)) cur = dp[cur][i];
pri(cur);
return 0;
}
| /*"Success isn't permanent, failure isn't fatal,
it's the courage to continue that counts"*/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> ordered_set;
#define ll long long
#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define lpri(n) printf("%lld", n)
#define pri(n) printf("%d", n)
#define pln() printf("\n")
#define priln(n) printf("%d\n", n)
#define lpriln(n) printf("%lld\n", n)
#define rep(i, init, n) for (int i = init; i < n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod = 1e9 + 7;
const int N = 2e5 + 4;
const int lim = 61;
int dp[N][64];
int main() {
int n;
ll k;
scn(n);
lscn(k);
rep(i, 1, n + 1) scn(dp[i][0]);
rep(i, 1, lim) {
rep(node, 1, n + 1) dp[node][i] = dp[dp[node][i - 1]][i - 1];
}
int cur = 1;
rep(i, 0, lim) if (k & (1LL << i)) cur = dp[cur][i];
pri(cur);
return 0;
}
| replace | 26 | 27 | 26 | 27 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
int main() {
lint N, K;
cin >> N >> K;
vector<lint> A(N);
for (auto &elem : A)
cin >> elem;
for (auto &elem : A)
elem--;
if (K <= N + N) {
lint idx = 0;
for (lint i = 0; i < K; i++) {
idx = A[idx];
}
cout << ++idx << endl;
return 0;
}
vector<lint> v;
map<lint, lint> prev;
lint idx = 0, loop;
for (lint i = 0;; i++) {
if (prev.count(idx)) {
loop = i - prev[idx];
break;
}
prev[idx] = i;
v.push_back(idx);
idx = A[idx];
}
K -= (v.size() - loop);
vector<lint> vec(v.end() - loop, v.end());
cout << ++vec[K % v.size()] << endl;
} | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
int main() {
lint N, K;
cin >> N >> K;
vector<lint> A(N);
for (auto &elem : A)
cin >> elem;
for (auto &elem : A)
elem--;
if (K <= N + N) {
lint idx = 0;
for (lint i = 0; i < K; i++) {
idx = A[idx];
}
cout << ++idx << endl;
return 0;
}
vector<lint> v;
map<lint, lint> prev;
lint idx = 0, loop;
for (lint i = 0;; i++) {
if (prev.count(idx)) {
loop = i - prev[idx];
break;
}
prev[idx] = i;
v.push_back(idx);
idx = A[idx];
}
K -= (v.size() - loop);
vector<lint> vec(v.end() - loop, v.end());
cout << ++vec[K % vec.size()] << endl;
} | replace | 37 | 38 | 37 | 38 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5;
int n, m, tot, now, ans, sum;
int a[N], b[N], c[N], f[N];
signed main() {
scanf("%lld%lld", &n, &m);
for (register int i = 1; i <= n; ++i)
scanf("%lld", &a[i]);
if (m <= n) {
now = 1;
for (register int i = 1; i <= m; ++i)
now = a[now];
printf("%lld\n", now);
return 0;
}
m++;
now = 1;
tot = 1;
f[1] = tot;
b[tot] = 1;
while (true) {
if (f[a[now]]) {
m -= f[a[now]] - 1;
for (register int i = 1; i <= tot - f[a[now]] + 1; ++i)
c[i] = b[i + f[a[now]] - 1];
break;
}
tot++;
f[a[now]] = tot;
b[tot] = a[now];
now = a[now];
}
// for (register int i=1; i<=tot-f[a[now]]+1; ++i) printf("%lld ",c[i]);
//puts("");
sum = tot - f[a[now]] + 1;
if (m % sum == 0)
ans = sum;
else
ans = m % sum;
printf("%lld\n", c[ans]);
return 0;
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5;
int n, m, tot, now, ans, sum;
int a[N], b[N], c[N], f[N];
signed main() {
scanf("%lld%lld", &n, &m);
for (register int i = 1; i <= n; ++i)
scanf("%lld", &a[i]);
if (m <= n) {
now = 1;
for (register int i = 1; i <= m; ++i)
now = a[now];
printf("%lld\n", now);
return 0;
}
m++;
now = 1;
tot = 1;
f[1] = tot;
b[tot] = 1;
while (true) {
if (f[a[now]]) {
m -= f[a[now]] - 1;
for (register int i = 1; i <= tot - f[a[now]] + 1; ++i)
c[i] = b[i + f[a[now]] - 1];
break;
}
tot++;
f[a[now]] = tot;
b[tot] = a[now];
now = a[now];
}
// for (register int i=1; i<=tot-f[a[now]]+1; ++i) printf("%lld ",c[i]);
//puts("");
sum = tot - f[a[now]] + 1;
if (m % sum == 0)
ans = sum;
else
ans = m % sum;
printf("%lld\n", c[ans]);
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
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;
}
int vector_finder(std::vector<ll> vec, int number) {
auto itr = std::find(vec.begin(), vec.end(), number);
size_t index = std::distance(vec.begin(), itr);
if (index != vec.size()) { // 発見できたとき
return 1;
} else { // 発見できなかったとき
return 0;
}
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A(N);
REP(i, N) cin >> A[i];
vector<ll> vec(N + 1);
REP(i, N + 1) vec[i] = 0;
vector<ll> path;
ll tmp = 1;
vec[0] = 1;
ll ans = 0;
path.push_back(vec[0]);
ll cnt = 0;
for (ll i = 0; i < K; ++i) {
if (vec[tmp] == 0) {
vec[tmp] = A[tmp - 1];
tmp = A[tmp - 1];
path.push_back(tmp);
cnt++;
} else if (vec[tmp] != 0) {
// なんらかの処理
ans = tmp;
break;
}
}
vector<ll> b;
bool flag = false;
REP(i, path.size()) {
if (path[i] == ans)
flag = !flag;
if (flag == true)
b.push_back(path[i]);
}
cout << b[(K - (cnt - b.size())) % b.size()] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
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;
}
int vector_finder(std::vector<ll> vec, int number) {
auto itr = std::find(vec.begin(), vec.end(), number);
size_t index = std::distance(vec.begin(), itr);
if (index != vec.size()) { // 発見できたとき
return 1;
} else { // 発見できなかったとき
return 0;
}
}
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A(N);
REP(i, N) cin >> A[i];
vector<ll> vec(N + 1);
REP(i, N + 1) vec[i] = 0;
vector<ll> path;
ll tmp = 1;
vec[0] = 1;
ll ans = 0;
path.push_back(vec[0]);
ll cnt = 0;
for (ll i = 0; i < K; ++i) {
if (vec[tmp] == 0) {
vec[tmp] = A[tmp - 1];
tmp = A[tmp - 1];
path.push_back(tmp);
cnt++;
} else if (vec[tmp] != 0) {
// なんらかの処理
ans = tmp;
break;
}
}
vector<ll> b;
bool flag = false;
REP(i, path.size()) {
if (path[i] == ans)
flag = !flag;
if (flag == true)
b.push_back(path[i]);
}
if (K - (cnt - b.size()) <= 0) {
cout << path[K] << endl;
} else {
ll c = (K - (cnt - b.size())) % b.size();
cout << b[c] << endl;
}
}
| replace | 66 | 67 | 66 | 73 | 0 | |
p02684 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define x first
#define y second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end() // Forward traversal
#define rall(x) (x).rbegin, (x).rend() // reverse traversal
#define ll long long
#define ld long double
const ld EPS = 10e-9;
const int INF = 1e9 + 5;
const long long INFLL = (ll)INF * (ll)INF;
const ll MOD = 1e9 + 7;
const ld PI = 3.14159265358979323846;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[";
for (int i = 0; i < (int)v.size(); ++i) {
os << v[i];
if (i != (int)v.size() - 1)
os << ", ";
}
os << "]\n";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "{";
for (const auto &it : v) {
os << it;
if (it != *v.rbegin())
os << ", ";
}
os << "}\n";
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &v) {
os << "{";
for (const auto &it : v) {
os << it;
if (it != *v.rbegin())
os << ", ";
}
os << "}\n";
return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const map<T, S> &v) {
os << "{";
for (const auto &it : v) {
os << it.first << " : " << it.second;
if (it != *v.rbegin())
os << ", ";
}
os << "}\n";
return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const unordered_map<T, S> &v) {
os << "{";
for (const auto &it : v) {
os << it.first << " : " << it.second;
if (it != *v.rbegin())
os << ", ";
}
os << "}\n";
return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &v) {
os << "(";
os << v.first << ", " << v.second << ")";
os << "\n";
return os;
}
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
// __gcd(x, y)
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll N, K;
cin >> N >> K;
vector<ll> a(N);
for (int i = 0; i < N; i++)
cin >> a[i];
ll l = a[0] - 1;
ll r = a[a[0] - 1] - 1;
while (l != r) {
l = a[l] - 1;
r = a[a[r] - 1] - 1;
}
l = 0;
while (l != r) {
l = a[l] - 1;
r = a[r] - 1;
}
// floyd warshall cycle detection algorithm ends here to find start of cycle
ll cycleStar = l; // starting point of cycle
ll cnt = 0; // number of elements before the starting point of cycle
l = 0;
while (l != cycleStar) {
cnt++;
l = a[l] - 1;
}
ll pos = cnt; // number of elements before the starting point of cycle
ll c = 1; // length of cycle(num of elements in it)
l = cycleStar;
while (a[l] - 1 != cycleStar) {
l = a[l] - 1;
c++;
}
ll i = 0;
unordered_set<ll> visited;
visited.insert(0);
ll pos2 = -1;
ll c2 = 1;
int lenBefore = 0;
while (true) {
if (visited.count(a[i] - 1)) {
i = a[i] - 1;
pos2 = 0;
while (pos2 != i) {
pos2 = a[pos2] - 1;
lenBefore++;
}
pos2 = i;
while (pos2 != a[i] - 1) {
c2++;
i = a[i] - 1;
}
break;
}
visited.insert(a[i] - 1);
i = a[i] - 1;
}
if (pos != lenBefore) {
throw runtime_error(to_string(pos) + " my: " + to_string(lenBefore));
}
// if(pos != pos2)
// {
// throw runtime_error(to_string(pos) + " my: " + to_string(pos2));
// }
ll ans = 0;
while (lenBefore != 0 && K != 0) {
ans = a[ans] - 1;
pos--;
K--;
}
if (K == 0) {
cout << ans + 1 << endl;
return 0;
}
ll n = K % c;
while (n) {
ans = a[ans] - 1;
n--;
}
cout << ans + 1 << endl;
// if(K <= pos)
// {
// ll ans = 0;
// while(K)
// {
// K--;
// ans = a[ans]-1;
// }
// cout << ans+1 << endl;
// }
// else {
// ll ans = 0;
// int pos_c = pos;
// while(pos_c)
// {
// pos_c--;
// ans = a[ans]-1;
// }
// int n = (K - pos) % c;
// while(n)
// {
// n--;
// ans = a[ans]-1;
// }
// cout << ans+1 << endl;
// }
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define x first
#define y second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end() // Forward traversal
#define rall(x) (x).rbegin, (x).rend() // reverse traversal
#define ll long long
#define ld long double
const ld EPS = 10e-9;
const int INF = 1e9 + 5;
const long long INFLL = (ll)INF * (ll)INF;
const ll MOD = 1e9 + 7;
const ld PI = 3.14159265358979323846;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[";
for (int i = 0; i < (int)v.size(); ++i) {
os << v[i];
if (i != (int)v.size() - 1)
os << ", ";
}
os << "]\n";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "{";
for (const auto &it : v) {
os << it;
if (it != *v.rbegin())
os << ", ";
}
os << "}\n";
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &v) {
os << "{";
for (const auto &it : v) {
os << it;
if (it != *v.rbegin())
os << ", ";
}
os << "}\n";
return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const map<T, S> &v) {
os << "{";
for (const auto &it : v) {
os << it.first << " : " << it.second;
if (it != *v.rbegin())
os << ", ";
}
os << "}\n";
return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const unordered_map<T, S> &v) {
os << "{";
for (const auto &it : v) {
os << it.first << " : " << it.second;
if (it != *v.rbegin())
os << ", ";
}
os << "}\n";
return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &v) {
os << "(";
os << v.first << ", " << v.second << ")";
os << "\n";
return os;
}
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
// __gcd(x, y)
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll N, K;
cin >> N >> K;
vector<ll> a(N);
for (int i = 0; i < N; i++)
cin >> a[i];
ll l = a[0] - 1;
ll r = a[a[0] - 1] - 1;
while (l != r) {
l = a[l] - 1;
r = a[a[r] - 1] - 1;
}
l = 0;
while (l != r) {
l = a[l] - 1;
r = a[r] - 1;
}
// floyd warshall cycle detection algorithm ends here to find start of cycle
ll cycleStar = l; // starting point of cycle
ll cnt = 0; // number of elements before the starting point of cycle
l = 0;
while (l != cycleStar) {
cnt++;
l = a[l] - 1;
}
ll pos = cnt; // number of elements before the starting point of cycle
ll c = 1; // length of cycle(num of elements in it)
l = cycleStar;
while (a[l] - 1 != cycleStar) {
l = a[l] - 1;
c++;
}
ll i = 0;
unordered_set<ll> visited;
visited.insert(0);
ll pos2 = -1;
ll c2 = 1;
int lenBefore = 0;
while (true) {
if (visited.count(a[i] - 1)) {
i = a[i] - 1;
pos2 = 0;
while (pos2 != i) {
pos2 = a[pos2] - 1;
lenBefore++;
}
pos2 = i;
while (pos2 != a[i] - 1) {
c2++;
i = a[i] - 1;
}
break;
}
visited.insert(a[i] - 1);
i = a[i] - 1;
}
if (pos != lenBefore) {
throw runtime_error(to_string(pos) + " my: " + to_string(lenBefore));
}
// if(pos != pos2)
// {
// throw runtime_error(to_string(pos) + " my: " + to_string(pos2));
// }
ll ans = 0;
while (lenBefore != 0 && K != 0) {
ans = a[ans] - 1;
lenBefore--;
K--;
}
if (K == 0) {
cout << ans + 1 << endl;
return 0;
}
ll n = K % c;
while (n) {
ans = a[ans] - 1;
n--;
}
cout << ans + 1 << endl;
// if(K <= pos)
// {
// ll ans = 0;
// while(K)
// {
// K--;
// ans = a[ans]-1;
// }
// cout << ans+1 << endl;
// }
// else {
// ll ans = 0;
// int pos_c = pos;
// while(pos_c)
// {
// pos_c--;
// ans = a[ans]-1;
// }
// int n = (K - pos) % c;
// while(n)
// {
// n--;
// ans = a[ans]-1;
// }
// cout << ans+1 << endl;
// }
return 0;
}
| replace | 188 | 189 | 188 | 189 | TLE | |
p02684 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define int long long
const int N = 1e5 + 7;
const int K = 62;
int up[K][N];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, nd;
cin >> n >> nd;
for (int i = 0; i < n; i++) {
cin >> up[0][i];
up[0][i]--;
}
for (int i = 0; i + 1 < K; i++) {
for (int j = 0; j < n; j++) {
up[i + 1][j] = up[i][up[i][j]];
}
}
int p = 0;
for (int i = 0; i < K; i++) {
if ((nd >> i) & 1)
p = up[i][p];
}
cout << p + 1 << endl;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define int long long
const int N = 2e5 + 7;
const int K = 62;
int up[K][N];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, nd;
cin >> n >> nd;
for (int i = 0; i < n; i++) {
cin >> up[0][i];
up[0][i]--;
}
for (int i = 0; i + 1 < K; i++) {
for (int j = 0; j < n; j++) {
up[i + 1][j] = up[i][up[i][j]];
}
}
int p = 0;
for (int i = 0; i < K; i++) {
if ((nd >> i) & 1)
p = up[i][p];
}
cout << p + 1 << endl;
}
| replace | 27 | 28 | 27 | 28 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define multi_test true and false
#define all(a) (a).begin(), (a).end()
using namespace std;
void dfs(int v, vector<bool> &bani, vector<int> &path, int arr[]) {
if (bani[v]) {
path.push_back(v);
return;
}
bani[v] = true;
path.push_back(v);
dfs(arr[v], bani, path, arr);
}
void solve() {
int n, k;
cin >> n >> k;
int arr[n];
for (int &i : arr)
cin >> i;
for (int &i : arr)
i--;
vector<int> path;
vector<bool> bani(n, false);
dfs(0, bani, path, arr);
int index = -1;
for (int i = 0; i < (int)path.size(); i++) {
if (path[i] == path.back()) {
index = i;
break;
}
}
vector<int> new_path(path.begin() + index, path.end());
// for(int i : new_path) cout << i << ' ';
// cout << endl ;
k -= index;
n = (int)new_path.size() - 1;
k = k % n;
// cout << k << ' ' << n << endl ;
cout << new_path[k] + 1 << endl;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int test = 1;
if (multi_test)
cin >> test;
while (test--)
solve();
return 0;
}
| #include <bits/stdc++.h>
#define int long long
#define multi_test true and false
#define all(a) (a).begin(), (a).end()
using namespace std;
void dfs(int v, vector<bool> &bani, vector<int> &path, int arr[]) {
if (bani[v]) {
path.push_back(v);
return;
}
bani[v] = true;
path.push_back(v);
dfs(arr[v], bani, path, arr);
}
void solve() {
int n, k;
cin >> n >> k;
int arr[n];
for (int &i : arr)
cin >> i;
for (int &i : arr)
i--;
vector<int> path;
vector<bool> bani(n, false);
dfs(0, bani, path, arr);
int index = -1;
for (int i = 0; i < (int)path.size(); i++) {
if (path[i] == path.back()) {
index = i;
break;
}
}
if (k < (int)path.size()) {
cout << path[k] + 1 << endl;
return;
}
vector<int> new_path(path.begin() + index, path.end());
// for(int i : new_path) cout << i << ' ';
// cout << endl ;
k -= index;
n = (int)new_path.size() - 1;
k = k % n;
// cout << k << ' ' << n << endl ;
cout << new_path[k] + 1 << endl;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int test = 1;
if (multi_test)
cin >> test;
while (test--)
solve();
return 0;
}
| insert | 37 | 37 | 37 | 41 | 0 | |
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
long long K;
cin >> N >> K;
vector<vector<int>> next(60, vector<int>(N));
for (int j = 0; j < N; j++) {
cin >> next.at(0).at(j);
next.at(0).at(j)--;
}
for (int i = 0; i < 59; i++) {
for (int j = 0; j < N; j++) {
next.at(i + 1).at(j) = next.at(i).at(next.at(i).at(j));
}
}
int j = 0;
for (int i = 0; j < 60; j++) {
if (K & (1LL << i)) {
j = next.at(i).at(j);
}
}
cout << j + 1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
long long K;
cin >> N >> K;
vector<vector<int>> next(60, vector<int>(N));
for (int j = 0; j < N; j++) {
cin >> next.at(0).at(j);
next.at(0).at(j)--;
}
for (int i = 0; i < 59; i++) {
for (int j = 0; j < N; j++) {
next.at(i + 1).at(j) = next.at(i).at(next.at(i).at(j));
}
}
int j = 0;
for (int i = 0; i < 60; i++) {
if (K & (1LL << i)) {
j = next.at(i).at(j);
}
}
cout << j + 1 << endl;
} | replace | 18 | 19 | 18 | 19 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)
|
p02684 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fastIO() \
; \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define fr(i, a, b) for (lli i = a; i < b; i++)
#define f0(a, b) for (lli i = a; i < b; i++)
#define fn(b, a) for (lli i = b; i > a; i--)
#define dbg(x) \
; \
cout << "\n" << #x << ": " << x;
#define ret return
#define pb push_back
#define pf push_front
#define mp make_pair
#define E9 1000000007
#define E5 100007
#define INF 1e18 + 7
#define PI 3.1415926
#define sq(a) (a) * (a)
#define fs first
#define sc second
#define el "\n"
#define all(a) a.begin(), a.end()
typedef vector<long long int> vll;
typedef vector<vector<long long int>> vvll;
typedef map<long long int, long long int> mll;
typedef pair<long long int, long long int> pll;
typedef long long int lli; // e-18 to e18
void solve() {
lli n, k;
cin >> n >> k;
vector<lli> a(n + 1);
f0(1, n + 1) cin >> a[i];
vll b;
mll c;
lli pos = 1, h = 1;
while (c.find(pos) == c.end()) {
c[pos] = h++;
b.pb(pos);
pos = a[pos];
}
if (k < c[pos]) {
cout << b[k] << el;
} else {
k -= c[pos];
vll d;
f0(c[pos], b.size()) d.pb(b[i]);
cout << d[k % d.size()] << el;
}
}
int main() {
fastIO();
lli t(1);
// cin>>t;
while (t--)
solve();
ret 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fastIO() \
; \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define fr(i, a, b) for (lli i = a; i < b; i++)
#define f0(a, b) for (lli i = a; i < b; i++)
#define fn(b, a) for (lli i = b; i > a; i--)
#define dbg(x) \
; \
cout << "\n" << #x << ": " << x;
#define ret return
#define pb push_back
#define pf push_front
#define mp make_pair
#define E9 1000000007
#define E5 100007
#define INF 1e18 + 7
#define PI 3.1415926
#define sq(a) (a) * (a)
#define fs first
#define sc second
#define el "\n"
#define all(a) a.begin(), a.end()
typedef vector<long long int> vll;
typedef vector<vector<long long int>> vvll;
typedef map<long long int, long long int> mll;
typedef pair<long long int, long long int> pll;
typedef long long int lli; // e-18 to e18
void solve() {
lli n, k;
cin >> n >> k;
vector<lli> a(n + 1);
f0(1, n + 1) cin >> a[i];
vll b;
mll c;
lli pos = 1, h = 0;
while (c.find(pos) == c.end()) {
c[pos] = h++;
b.pb(pos);
pos = a[pos];
}
if (k < c[pos]) {
cout << b[k] << el;
} else {
k -= c[pos];
vll d;
f0(c[pos], b.size()) d.pb(b[i]);
cout << d[k % d.size()] << el;
}
}
int main() {
fastIO();
lli t(1);
// cin>>t;
while (t--)
solve();
ret 0;
} | replace | 37 | 38 | 37 | 38 | 0 | |
p02684 | C++ | Time Limit Exceeded | #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()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T> T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <typename T> T pow(T a, int b) {
return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1;
}
ll modpow(ll a, int b, int _mod) {
return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) {
for (auto &vi : vec)
os << vi << " ";
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.F << " " << p.S;
return os;
}
template <typename T> inline istream &operator>>(istream &is, vector<T> &v) {
rep(j, sz(v)) is >> v[j];
return is;
}
template <class T> inline void add(T &a, int b) {
a += b;
if (a >= mod)
a -= mod;
}
void solve();
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
int T;
// cin >> T;
T = 1;
while (T--) {
solve();
}
}
// https://atcoder.jp/contests/abc167/submissions/13082002
// 間違いの検証
void solve() {
int n;
cin >> n;
string k;
cin >> k;
const int N = 200005;
vector<vector<int>> G(N);
vector<int> seen(N);
int pos = -1; // cycle 中に含まれる頂点 pos
stack<int> hist; // 訪問履歴
auto dfs = [&](auto &&dfs, int v, int p) -> void {
seen[v] = 1;
hist.push(v);
for (auto nv : G[v]) {
if (nv == p)
continue; // ---------- 問題点を探す ----------
if (seen[nv] == 2)
continue;
if (seen[nv] == 1) { // cycle を検出
pos = nv;
return;
}
dfs(dfs, nv, v);
if (pos != -1)
return;
}
hist.pop();
seen[v] = 2;
};
rep(i, n) {
int b;
cin >> b;
b--;
G[i].eb(b);
}
ll x_ = stoll(k);
if (x_ <= 10000000) { // ループに入る前に終わる
int now = 0;
rep(i, x_) { now = G[now][0]; }
cout << now + 1 << endl;
return;
}
dfs(dfs, 0, -1);
// cycle 復元
vector<int> cycle;
while (!hist.empty()) {
int t = hist.top();
cycle.eb(t);
hist.pop();
if (t == pos)
break;
}
reverse(all(cycle));
// for (auto e : cycle) cout << e << " "; cout << endl;
// ---------- 間違いはここか? ----------
if (sz(cycle) == 0) {
while (1) {
}
}
int cnt = 0, now = 0;
while (1) {
if (now == cycle[0]) {
break;
}
now = G[now][0];
cnt++;
}
int k3 = 0;
rep(i, sz(k)) {
k3 *= 10;
k3 += k[i] - '0';
k3 %= sz(cycle);
}
k3 -= cnt; // 先に足すと, 10 倍するのが効いてしまう
while (k3 < 0)
k3 += sz(cycle);
k3 %= sz(cycle);
now = cycle[0];
while (k3--) {
now = G[now][0];
}
cout << now + 1 << endl;
}
| #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()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T> T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <typename T> T pow(T a, int b) {
return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1;
}
ll modpow(ll a, int b, int _mod) {
return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) {
for (auto &vi : vec)
os << vi << " ";
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.F << " " << p.S;
return os;
}
template <typename T> inline istream &operator>>(istream &is, vector<T> &v) {
rep(j, sz(v)) is >> v[j];
return is;
}
template <class T> inline void add(T &a, int b) {
a += b;
if (a >= mod)
a -= mod;
}
void solve();
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
int T;
// cin >> T;
T = 1;
while (T--) {
solve();
}
}
// https://atcoder.jp/contests/abc167/submissions/13082002
// 間違いの検証
void solve() {
int n;
cin >> n;
string k;
cin >> k;
const int N = 200005;
vector<vector<int>> G(N);
vector<int> seen(N);
int pos = -1; // cycle 中に含まれる頂点 pos
stack<int> hist; // 訪問履歴
auto dfs = [&](auto &&dfs, int v, int p) -> void {
seen[v] = 1;
hist.push(v);
for (auto nv : G[v]) {
if (nv == p)
continue; // ---------- 問題点を探す ----------
if (seen[nv] == 2)
continue;
if (seen[nv] == 1) { // cycle を検出
pos = nv;
return;
}
dfs(dfs, nv, v);
if (pos != -1)
return;
}
hist.pop();
seen[v] = 2;
};
rep(i, n) {
int b;
cin >> b;
b--;
G[i].eb(b);
}
ll x_ = stoll(k);
if (x_ <= 10000000) { // ループに入る前に終わる
int now = 0;
rep(i, x_) { now = G[now][0]; }
cout << now + 1 << endl;
return;
}
dfs(dfs, 0, -1);
// cycle 復元
vector<int> cycle;
while (!hist.empty()) {
int t = hist.top();
cycle.eb(t);
hist.pop();
if (t == pos)
break;
}
reverse(all(cycle));
// for (auto e : cycle) cout << e << " "; cout << endl;
// 本当は cycle の size が 2
if (sz(cycle) == 0) { // ---------- あってる? ----------
ll k_ = stoll(k);
vector<int> v(n + 5);
v[1] = G[0][0];
rep3(i, 2, n + 5) v[i] = G[v[i - 1]][0];
// cout << "v " << v << endl;
rep(i, n + 5) {
if (v[i] == v[i + 2]) {
k_ %= 2;
(k_ = k_ - i % 2 + 2) %= 2;
if (k_ % 2 == 0)
cout << v[i] + 1 << endl;
else
cout << v[i + 1] + 1 << endl;
return;
}
}
}
int cnt = 0, now = 0;
while (1) {
if (now == cycle[0]) {
break;
}
now = G[now][0];
cnt++;
}
int k3 = 0;
rep(i, sz(k)) {
k3 *= 10;
k3 += k[i] - '0';
k3 %= sz(cycle);
}
k3 -= cnt; // 先に足すと, 10 倍するのが効いてしまう
while (k3 < 0)
k3 += sz(cycle);
k3 %= sz(cycle);
now = cycle[0];
while (k3--) {
now = G[now][0];
}
cout << now + 1 << endl;
}
| replace | 144 | 147 | 144 | 161 | TLE |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.