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
p02915
Python
Runtime Error
a = input() print(a**3)
a = int(input()) print(a**3)
replace
0
1
0
1
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02915/Python/s461864634.py", line 2, in <module> print(a ** 3) TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
p02915
Python
Runtime Error
N = input(int()) print(N**3)
N = int(input()) print(N**3)
replace
0
1
0
1
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02915/Python/s203905734.py", line 2, in <module> print(N**3) TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
p02915
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define SPEED \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define pob pop_back(); #define for_t \ int t; \ cin >> t; \ while (t--) #define MOD 1000000007 #define fi first #define se second #define le length #define debug(n1) cout << n1 << endl #define set_bits(n) __builtin_popcount(n); #define rep(i, j, n) for (ll i = j; i <= n; i++) #define per(i, j, n) for (ll i = j; i >= n; i--) typedef long long int ll; typedef vector<ll> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef pair<pii, int> ppi; typedef map<int, int> mapp; int stoif(string num) { stringstream geek(num); int x = 0; geek >> x; return x; } int main() { SPEED; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; cin >> n; int ans = n * n * n; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define SPEED \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define pob pop_back(); #define for_t \ int t; \ cin >> t; \ while (t--) #define MOD 1000000007 #define fi first #define se second #define le length #define debug(n1) cout << n1 << endl #define set_bits(n) __builtin_popcount(n); #define rep(i, j, n) for (ll i = j; i <= n; i++) #define per(i, j, n) for (ll i = j; i >= n; i--) typedef long long int ll; typedef vector<ll> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef pair<pii, int> ppi; typedef map<int, int> mapp; int stoif(string num) { stringstream geek(num); int x = 0; geek >> x; return x; } int main() { SPEED; int n; cin >> n; int ans = n * n * n; cout << ans; return 0; }
delete
36
40
36
36
0
p02915
Python
Runtime Error
len = input() print(len**3)
len = int(input()) print(len**3)
replace
0
1
0
1
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02915/Python/s357662058.py", line 2, in <module> print(len**3) TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
p02915
Python
Runtime Error
a = input() print(a**3)
a = int(input()) print(a**3)
replace
0
1
0
1
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02915/Python/s464353610.py", line 2, in <module> print(a**3) TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
p02915
C++
Runtime Error
/* Life Before Death, Strength Before Weakness, Journey Before Destination ------------------------------------------------------------------------ You don't become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process. */ // #pragma comment(linker, ack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << std::endl; } 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 trace(...) #endif #define rep(i, n) for (ll i = 0; i < (n); ++i) #define repA(i, a, n) for (ll i = a; i <= (n); ++i) #define repD(i, a, n) for (ll i = a; i >= (n); --i) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define fill(a) memset(a, 0, sizeof(a)) #define fst first #define snd second // #define mp make_pair #define pb push_back #define PI 3.141592653589793238462643383279502884197169399 /* pi */ // #define te typedef long double ld; typedef long long ll; typedef pair<ll, ll> pii; typedef vector<ll> vi; const int maxN = 100100; void solve() { ll n; cin >> n; ll ans = n * n * n; cout << ans << endl; } int main() { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); ll ti; cin >> ti; while (ti--) solve(); return 0; }
/* Life Before Death, Strength Before Weakness, Journey Before Destination ------------------------------------------------------------------------ You don't become great by trying to be great. You become great by wanting to do something, and then doing it so hard that you become great in the process. */ // #pragma comment(linker, ack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << std::endl; } 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 trace(...) #endif #define rep(i, n) for (ll i = 0; i < (n); ++i) #define repA(i, a, n) for (ll i = a; i <= (n); ++i) #define repD(i, a, n) for (ll i = a; i >= (n); --i) #define trav(a, x) for (auto &a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define fill(a) memset(a, 0, sizeof(a)) #define fst first #define snd second // #define mp make_pair #define pb push_back #define PI 3.141592653589793238462643383279502884197169399 /* pi */ // #define te typedef long double ld; typedef long long ll; typedef pair<ll, ll> pii; typedef vector<ll> vi; const int maxN = 100100; void solve() { ll n; cin >> n; ll ans = n * n * n; cout << ans << endl; } int main() { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); // ll ti; cin >> ti; while(ti--) solve(); return 0; }
replace
61
65
61
63
-6
terminate called after throwing an instance of 'std::__ios_failure' what(): basic_ios::clear: iostream error
p02915
C++
Runtime Error
#include <stdio.h> int main() { int N; scanf("%d", N); printf("%d", N * N * N); return 0; }
#include <stdio.h> int main() { int n; scanf("%d", &n); printf("%d\n", n * n * n); return 0; }
replace
3
6
3
6
-11
p02915
C++
Runtime Error
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> using namespace std; #define int long long #define all(arr) arr.begin(), arr.end() #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define vi vector<int> #define vstr vector<string> #define vbool vector<bool> #define vvi vector<vector<int>> #define mii map<int, int> #define pb push_back #define pii pair<int, int> #define vpair vector<pii> #define mkp make_pair #define scan(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i] #define print(a, n) \ for (int i = 0; i < n; i++) { \ cout << a[i] << ' '; \ } \ cout << '\n' #define mem(a, v) memset(a, v, sizeof(a)) #define loop(i, a, b) for (int i = a; i < b; i++) #define loope(i, a, b) for (int i = a; i <= b; i++) #define FastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define PRECISION \ std::cout.unsetf(std::ios::fixed); \ std::cout.precision(9) #define PI 3.14159265 #define S second #define F first #define CHECK cout << "CHEDEDWB" << endl #define br '\n' /*int mod = 1e9+7; int inf = 1e18; int m_inf = INT_MIN; int MOD = 100001;*/ void solve() { int n; cin >> n; vi arr(n); cout << n * n * n << endl; } int32_t main() { FastIO; PRECISION; int t = 1; cin >> t; while (t--) solve(); return 0; }
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> using namespace std; #define int long long #define all(arr) arr.begin(), arr.end() #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define vi vector<int> #define vstr vector<string> #define vbool vector<bool> #define vvi vector<vector<int>> #define mii map<int, int> #define pb push_back #define pii pair<int, int> #define vpair vector<pii> #define mkp make_pair #define scan(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i] #define print(a, n) \ for (int i = 0; i < n; i++) { \ cout << a[i] << ' '; \ } \ cout << '\n' #define mem(a, v) memset(a, v, sizeof(a)) #define loop(i, a, b) for (int i = a; i < b; i++) #define loope(i, a, b) for (int i = a; i <= b; i++) #define FastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define PRECISION \ std::cout.unsetf(std::ios::fixed); \ std::cout.precision(9) #define PI 3.14159265 #define S second #define F first #define CHECK cout << "CHEDEDWB" << endl #define br '\n' /*int mod = 1e9+7; int inf = 1e18; int m_inf = INT_MIN; int MOD = 100001;*/ void solve() { int n; cin >> n; vi arr(n); cout << n * n * n << endl; } int32_t main() { FastIO; PRECISION; int t = 1; // cin>>t; while (t--) solve(); return 0; }
replace
85
86
85
86
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02915
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define For(i, n) for (ll i = 0; i < (n); i++) int main() { ll n, ans = 0; cin >> n; vector<ll> vec(10000000); for (ll i = 0; i < 1000; i++) { for (ll j = 0; j < 10000; j++) { for (int k = 0; k < 500; k++) { vec.at(i + j + k)++; } } } cout << n * n * n << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define For(i, n) for (ll i = 0; i < (n); i++) int main() { ll n, ans = 0; cin >> n; vector<ll> vec(10000000); for (ll i = 0; i < 1000; i++) { for (ll j = 0; j < 10000; j++) { for (int k = 0; k < 50; k++) { vec.at(i + j + k)++; } } } cout << n * n * n << endl; }
replace
10
11
10
11
TLE
p02915
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n; cin >> n; return n * n * n; }
#include <iostream> using namespace std; int main() { int n; cin >> n; cout << n * n * n << endl; return 0; }
replace
7
8
7
9
8
p02915
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define pb push_back #define mp make_pair #define ff first #define ss second #define mod 1000000007 // typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; #define sz(a) int((a).size()) #define all(c) (c).begin(), (c).end() #define tr(c, i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++) #define present(c, x) ((c).find(x) != (c).end()) #define cpresent(c, x) (find(all(c), x) != (c).end()) // main function here int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("C:/Users/Saurav Kumar Singh/Desktop/cp/input.txt", "r", stdin); freopen("C:/Users/Saurav Kumar Singh/Desktop/cp/output.txt", "w", stdout); #endif ll n; cin >> n; cout << n * n * n << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define pb push_back #define mp make_pair #define ff first #define ss second #define mod 1000000007 // typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; #define sz(a) int((a).size()) #define all(c) (c).begin(), (c).end() #define tr(c, i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++) #define present(c, x) ((c).find(x) != (c).end()) #define cpresent(c, x) (find(all(c), x) != (c).end()) // main function here int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin >> n; cout << n * n * n << "\n"; return 0; }
replace
27
31
27
28
0
p02915
C++
Runtime Error
#include <iostream> using namespace std; int main() { int a; cin >> a; int n; n = a * a * a; return n; }
#include <iostream> using namespace std; int main() { int a; cin >> a; int n; n = a * a * a; cout << n; }
replace
7
8
7
8
8
p02915
C++
Runtime Error
#include <iostream> int main() { int n; std::cin >> n; return (n * n * n); }
#include <iostream> int main() { int n; std::cin >> n; std::cout << n * n * n; }
replace
5
6
5
6
8
p02915
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define ull unsigned long long #define ff first #define ss second #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define mp make_pair #define inf 2000000009 #define mod 1000000007 using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast; ll n; cin >> n; cout << pow(n, 3) << endl; }
#include <bits/stdc++.h> #define ll long long int #define ull unsigned long long #define ff first #define ss second #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define mp make_pair #define inf 2000000009 #define mod 1000000007 using namespace std; int main() { fast; ll n; cin >> n; cout << pow(n, 3) << endl; }
delete
17
21
17
17
0
p02915
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long int ll; typedef unsigned long long int ull; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set; #define int ll #define pb push_back #define mp make_pair #define xx first #define yy second #define all(a) a.begin(), a.end() #define vi vector<int> #define vpi vector<pii> #define pii pair<int, int> #define present(DT, val) (DT.find(val) != DT.end()) // for set and map #define cpresent(DT, val) (find(all(DT), val) != DT.end()) // vectors #define sd " " #define nl "\n" #define input "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt" #define output "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt" #define error "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt" #define IOS() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define INF 2e18 #define MOD 1000000007 #define clr(x) memset(x, 0, sizeof(x)) #define init(x, a) memset(x, a, sizeof(x)) #define siz(a) sizeof(a) / sizeof(a[0]) #define out(a) \ for (auto i : a) \ cout << i << " "; \ cout << "\n" #define cpy(a, b) memcpy(a, b, sizeof(b)) #define itos(a) to_string(a) #define ctoi(a) int(a) - 48 #define setd(val, n) \ cout << fixed; \ cout << setprecision(n) << val << "\n" ll mod(ll a) { return ((a % MOD) + MOD) % MOD; } ll fpow(ll base, ll expo) { ll res = 1; while (expo > 0) { if (expo & 1) res = (res * base) % MOD; base = (base * base) % MOD; expo >>= 1; } return res; } ll modinv(ll a) { return mod(fpow(mod(a), MOD - 2)); } void solve() { int n; cin >> n; cout << pow(n, 3) << nl; } signed main() { IOS(); #ifndef ONLINE_JUDGE freopen(input, "r", stdin); freopen(output, "w", stdout); freopen(error, "w", stderr); #endif int t = 1; // cin>>t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long int ll; typedef unsigned long long int ull; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set; #define int ll #define pb push_back #define mp make_pair #define xx first #define yy second #define all(a) a.begin(), a.end() #define vi vector<int> #define vpi vector<pii> #define pii pair<int, int> #define present(DT, val) (DT.find(val) != DT.end()) // for set and map #define cpresent(DT, val) (find(all(DT), val) != DT.end()) // vectors #define sd " " #define nl "\n" #define input "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt" #define output "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt" #define error "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt" #define IOS() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define INF 2e18 #define MOD 1000000007 #define clr(x) memset(x, 0, sizeof(x)) #define init(x, a) memset(x, a, sizeof(x)) #define siz(a) sizeof(a) / sizeof(a[0]) #define out(a) \ for (auto i : a) \ cout << i << " "; \ cout << "\n" #define cpy(a, b) memcpy(a, b, sizeof(b)) #define itos(a) to_string(a) #define ctoi(a) int(a) - 48 #define setd(val, n) \ cout << fixed; \ cout << setprecision(n) << val << "\n" ll mod(ll a) { return ((a % MOD) + MOD) % MOD; } ll fpow(ll base, ll expo) { ll res = 1; while (expo > 0) { if (expo & 1) res = (res * base) % MOD; base = (base * base) % MOD; expo >>= 1; } return res; } ll modinv(ll a) { return mod(fpow(mod(a), MOD - 2)); } void solve() { int n; cin >> n; cout << pow(n, 3) << nl; } signed main() { IOS(); int t = 1; // cin>>t; while (t--) solve(); return 0; }
delete
72
77
72
72
0
p02915
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int i; cin >> i; long long j = 1; while (i > 0) { j <<= 1; } cout << j; return 0; }
#include <iostream> using namespace std; int main() { int i; cin >> i; cout << i * i * i; return 0; }
replace
5
10
5
6
TLE
p02915
C++
Time Limit Exceeded
// #pragma GCC optimize("O3", "unroll-loops") // #pragma GCC target("avx2") #include <bits/stdc++.h> #define FAST \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define FIXED cout << fixed << setprecision(12) #define RANDOM srand(94385) #define all(a) a.begin(), a.end() #define shuffle(a) \ for (int i = 0; i < sz(a); ++i) \ swap(a[i], a[rand() % sz(a)]); #define enter putchar('\n') #define space putchar(' ') #define Mem(a, x) memset(a, x, sizeof(a)) using namespace std; typedef long long ll; typedef pair<int, int> pii; void debug_out() { cerr << '\n'; } template <typename T, typename... R> void debug_out(const T &f, const R &...r) { cerr << f << " "; debug_out(r...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__); inline ll read() { ll x = 0; int f = 0; char ch = getchar(); while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return x = f ? -x : x; } inline void write(ll x) { if (x == 0) { putchar('0'); return; } if (x < 0) { putchar('-'); x = -x; } static char s[23]; int l = 0; while (x != 0) s[l++] = x % 10 + 48, x /= 10; while (l) putchar(s[--l]); } int lowbit(int x) { return x & (-x); } template <class T> T big(const T &a1, const T &a2) { return a1 > a2 ? a1 : a2; } template <typename T, typename... R> T big(const T &f, const R &...r) { return big(f, big(r...)); } template <class T> T sml(const T &a1, const T &a2) { return a1 < a2 ? a1 : a2; } template <typename T, typename... R> T sml(const T &f, const R &...r) { return sml(f, sml(r...)); } template <class T, class U> inline void checkMin(T &x, U y) { if (y < x) x = y; } template <class T, class U> inline void checkMax(T &x, U y) { if (y > x) x = y; } template <class T, class U> inline bool ifMax(T &x, U y) { if (y > x) return x = y, true; return false; } template <class T, class U> inline bool ifMin(T &x, U y) { if (y < x) return x = y, true; return false; } const int M = 212345; // 2e5+5 const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1000000007; // 1e9+7 // HAVE FREE OPEN IN MAIN FUNCTION void init() { int n = read(); write(n * n * n), enter; } void solve() {} int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif init(); solve(); return 0; }
// #pragma GCC optimize("O3", "unroll-loops") // #pragma GCC target("avx2") #include <bits/stdc++.h> #define FAST \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define FIXED cout << fixed << setprecision(12) #define RANDOM srand(94385) #define all(a) a.begin(), a.end() #define shuffle(a) \ for (int i = 0; i < sz(a); ++i) \ swap(a[i], a[rand() % sz(a)]); #define enter putchar('\n') #define space putchar(' ') #define Mem(a, x) memset(a, x, sizeof(a)) using namespace std; typedef long long ll; typedef pair<int, int> pii; void debug_out() { cerr << '\n'; } template <typename T, typename... R> void debug_out(const T &f, const R &...r) { cerr << f << " "; debug_out(r...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__); inline ll read() { ll x = 0; int f = 0; char ch = getchar(); while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return x = f ? -x : x; } inline void write(ll x) { if (x == 0) { putchar('0'); return; } if (x < 0) { putchar('-'); x = -x; } static char s[23]; int l = 0; while (x != 0) s[l++] = x % 10 + 48, x /= 10; while (l) putchar(s[--l]); } int lowbit(int x) { return x & (-x); } template <class T> T big(const T &a1, const T &a2) { return a1 > a2 ? a1 : a2; } template <typename T, typename... R> T big(const T &f, const R &...r) { return big(f, big(r...)); } template <class T> T sml(const T &a1, const T &a2) { return a1 < a2 ? a1 : a2; } template <typename T, typename... R> T sml(const T &f, const R &...r) { return sml(f, sml(r...)); } template <class T, class U> inline void checkMin(T &x, U y) { if (y < x) x = y; } template <class T, class U> inline void checkMax(T &x, U y) { if (y > x) x = y; } template <class T, class U> inline bool ifMax(T &x, U y) { if (y > x) return x = y, true; return false; } template <class T, class U> inline bool ifMin(T &x, U y) { if (y < x) return x = y, true; return false; } const int M = 212345; // 2e5+5 const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1000000007; // 1e9+7 // HAVE FREE OPEN IN MAIN FUNCTION void init() { int n = read(); write(n * n * n), enter; } void solve() {} int main() { init(); solve(); return 0; }
delete
110
114
110
110
TLE
p02915
C++
Runtime Error
/* ########################### # Author : Pranay Garg # # College : SGSITS # ########################### */ #include <bits/stdc++.h> #define ll long long int #define ironman \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define MOD 1000000007 #define endl '\n' #define INF 1e18L + 1 #define mp make_pair #define fi first #define se second #define debug1(x) cout << #x << " " << x << endl; #define debug2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl; #define debug3(x, y, z) \ cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z \ << endl; #define pb push_back #define pf push_front using namespace std; template <class T> T max(T a, T b, T c) { return max(a, max(b, c)); } template <class T> T min(T a, T b, T c) { return min(a, min(b, c)); } void fastio() { ironman #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif } ll prime[100005]; void SieveOfEratosthenes(ll n) // O(nloglogn) { memset(prime, true, sizeof(prime)); for (ll p = 2; p * p <= n; p++) { if (prime[p] == true) { for (ll i = p * p; i <= n; i += p) prime[i] = false; } } } bool isPrime(ll n) // O(sqrt(n)) { if (n < 2) return false; for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } std::vector<ll> factors(ll n) // O(sqrt(n)) { std::vector<ll> f; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { f.push_back(i); n = n / i; } } if (n > 1) f.push_back(n); return f; } ll gcd(ll a, ll b) // O(logn) { if (!b) return a; return gcd(b, a % b); } ll modpow(ll x, ll n, ll m) // O(logn)// used for calculating (x^n)%m { if (n == 0) return 1 % m; ll u = modpow(x, n / 2, m); u = (u % m * u % m) % m; if (n % 2 == 1) u = (u % m * x % m) % m; return u % m; } ll eulerstotientfunction(ll n) // O(sqrt(n)) { ll ans = n; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) n = n / i; ans -= ans / i; } } if (n > 1) ans -= ans / n; return ans; } ll modinverse(ll x, ll m) // O(logn) { ll temp = eulerstotientfunction(m); return modpow(x, temp - 1, m); } ll ncr(ll n, ll k) { ll res = 1; k = min(k, n - k); for (ll i = 0; i < k; i++) { res *= (n - i); res /= (i + 1); } return res; } int main() { fastio(); ll t = 1; // cin >> t; while (t--) { ll n; cin >> n; cout << n * n * n << endl; } }
/* ########################### # Author : Pranay Garg # # College : SGSITS # ########################### */ #include <bits/stdc++.h> #define ll long long int #define ironman \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define MOD 1000000007 #define endl '\n' #define INF 1e18L + 1 #define mp make_pair #define fi first #define se second #define debug1(x) cout << #x << " " << x << endl; #define debug2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl; #define debug3(x, y, z) \ cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z \ << endl; #define pb push_back #define pf push_front using namespace std; template <class T> T max(T a, T b, T c) { return max(a, max(b, c)); } template <class T> T min(T a, T b, T c) { return min(a, min(b, c)); } void fastio() { ironman #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif } ll prime[100005]; void SieveOfEratosthenes(ll n) // O(nloglogn) { memset(prime, true, sizeof(prime)); for (ll p = 2; p * p <= n; p++) { if (prime[p] == true) { for (ll i = p * p; i <= n; i += p) prime[i] = false; } } } bool isPrime(ll n) // O(sqrt(n)) { if (n < 2) return false; for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } std::vector<ll> factors(ll n) // O(sqrt(n)) { std::vector<ll> f; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { f.push_back(i); n = n / i; } } if (n > 1) f.push_back(n); return f; } ll gcd(ll a, ll b) // O(logn) { if (!b) return a; return gcd(b, a % b); } ll modpow(ll x, ll n, ll m) // O(logn)// used for calculating (x^n)%m { if (n == 0) return 1 % m; ll u = modpow(x, n / 2, m); u = (u % m * u % m) % m; if (n % 2 == 1) u = (u % m * x % m) % m; return u % m; } ll eulerstotientfunction(ll n) // O(sqrt(n)) { ll ans = n; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) n = n / i; ans -= ans / i; } } if (n > 1) ans -= ans / n; return ans; } ll modinverse(ll x, ll m) // O(logn) { ll temp = eulerstotientfunction(m); return modpow(x, temp - 1, m); } ll ncr(ll n, ll k) { ll res = 1; k = min(k, n - k); for (ll i = 0; i < k; i++) { res *= (n - i); res /= (i + 1); } return res; } int main() { // fastio(); ll t = 1; // cin >> t; while (t--) { ll n; cin >> n; cout << n * n * n << endl; } }
replace
113
114
113
114
0
p02915
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, Ans = 0; cin >> N; int A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; // cout << A[i] << endl; } int B[N]; for (int i = 0; i < N; i++) { cin >> B[i]; // cout << B[i] << endl; } int C[N - 1]; for (int i = 0; i < N - 1; i++) { cin >> C[i]; // cout << C[i] << endl; } for (int i = 0; i < N; i++) { Ans += B[A[i] - 1]; if (i < N - 1) { if (A[i] == A[i + 1] - 1) { Ans += C[A[i] - 1]; } } } cout << Ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; cout << a * a * a << endl; return 0; }
replace
4
31
4
7
-11
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n), b(n), c(n - 1); for (int i = 0; i < n; i++) cin >> a.at(i); for (int i = 0; i < n; i++) cin >> b.at(i); for (int i = 0; i < n - 1; i++) cin >> c.at(i); int sum = 0; for (int i = 0; i < n; i++) { sum += b.at(a.at(i) - 1); if (i > 0 && a.at(i) == a.at(i - 1) + 1) sum += c.at(a.at(i) - 1); } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n), b(n), c(n - 1); for (int i = 0; i < n; i++) cin >> a.at(i); for (int i = 0; i < n; i++) cin >> b.at(i); for (int i = 0; i < n - 1; i++) cin >> c.at(i); int sum = 0; for (int i = 0; i < n; i++) { sum += b.at(a.at(i) - 1); if (i > 0 && a.at(i) == a.at(i - 1) + 1) sum += c.at(a.at(i) - 2); } cout << sum << endl; }
replace
17
18
17
18
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int *a = (int *)malloc(n * sizeof(int)); int *nxt = (int *)malloc(n * sizeof(int)); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) nxt[a[i - 1]] = a[i]; int ans = 0; for (int i = 0; i < n; i++) { int b; cin >> b; ans += b; } for (int i = 1; i < n; i++) { int c; cin >> c; if (nxt[i] == i + 1) ans += c; } cout << ans; free(a); free(nxt); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int *a = (int *)malloc(n * sizeof(int)); int *nxt = (int *)malloc((n + 1) * sizeof(int)); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) nxt[a[i - 1]] = a[i]; int ans = 0; for (int i = 0; i < n; i++) { int b; cin >> b; ans += b; } for (int i = 1; i < n; i++) { int c; cin >> c; if (nxt[i] == i + 1) ans += c; } cout << ans; free(a); free(nxt); return 0; }
replace
8
9
8
9
0
p02916
Python
Runtime Error
N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) # 定義してないリストを参照するとエラーがでるからダミー置いといた。 A.append(100) C.append(0) total = 0 total = sum(B) for i in range(1, N): if A[i] - A[i - 1] == 1: total += C[A[i] - 1 - 1] print(total) A = list(map(int, input().split())) print(A) print(sum(A))
N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) # 定義してないリストを参照するとエラーがでるからダミー置いといた。 A.append(100) C.append(0) total = 0 total = sum(B) for i in range(1, N): if A[i] - A[i - 1] == 1: total += C[A[i] - 1 - 1] print(total)
delete
18
22
18
18
EOFError: EOF when reading a line
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02916/Python/s740527149.py", line 20, in <module> A = list(map(int, input().split())) EOFError: EOF when reading a line
p02916
Python
Runtime Error
n = int(input()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] c = [int(i) for i in input().split()] if len(c) == 1: print(sum(b) + sum(c)) else: print(sum(b) + sum(c) - c[a[n - 1] - 1])
n = int(input()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] c = [int(i) for i in input().split()] ans = b[a[0] - 1] for i in range(1, n): ans += b[a[i] - 1] if a[i] == a[i - 1] + 1: ans += c[a[i - 1] - 1] print(ans)
replace
4
8
4
10
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n), b(n), c(n - 1); int cnt = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { cin >> b[i]; } for (int i = 1; i <= n - 1; i++) { cin >> c[i]; } for (int i = 1; i <= n; i++) { cnt += b[a[i]]; if (a[i] + 1 == a[i + 1]) cnt += c[a[i]]; } cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(100), b(100), c(100); int cnt = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { cin >> b[i]; } for (int i = 1; i <= n - 1; i++) { cin >> c[i]; } for (int i = 1; i <= n; i++) { cnt += b[a[i]]; if (a[i] + 1 == a[i + 1]) cnt += c[a[i]]; } cout << cnt << endl; }
replace
6
7
6
7
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); vector<int> b(n); vector<int> c(n - 1); int cnt = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { cin >> b[i]; } for (int i = 1; i <= n - 1; i++) { cin >> c[i]; } for (int i = 1; i <= n; i++) { cnt += b[a[i]]; if (a[i] + 1 == a[i + 1]) cnt += c[a[i]]; } cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n + 1); vector<int> b(n + 1); vector<int> c(n); int cnt = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { cin >> b[i]; } for (int i = 1; i <= n - 1; i++) { cin >> c[i]; } for (int i = 1; i <= n; i++) { cnt += b[a[i]]; if (a[i] + 1 == a[i + 1]) cnt += c[a[i]]; } cout << cnt << endl; }
replace
6
9
6
9
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(0); vector<int> b(0); vector<int> c(0); int in; for (int i = 0; i < n; i++) { cin >> in; a.push_back(in); } for (int i = 0; i < n; i++) { cin >> in; b.push_back(in); } for (int i = 0; i < n - 1; i++) { cin >> in; c.push_back(in); } int ans = 0; for (int i = 0; i < n; i++) { ans += b.at(a.at(i) - 1); if (i > 0) { if (a.at(i) - a.at(i - 1) == 1) { ans += c.at(a.at(i) - 1); } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(0); vector<int> b(0); vector<int> c(0); int in; for (int i = 0; i < n; i++) { cin >> in; a.push_back(in); } for (int i = 0; i < n; i++) { cin >> in; b.push_back(in); } for (int i = 0; i < n - 1; i++) { cin >> in; c.push_back(in); } int ans = 0; for (int i = 0; i < n; i++) { ans += b.at(a.at(i) - 1); if (i > 0) { if (a.at(i) - a.at(i - 1) == 1) { ans += c.at(a.at(i - 1) - 1); } } } cout << ans << endl; }
replace
33
34
33
34
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 1; i < (int)n + 1; i++) using namespace std; int main() { int n, ans, temp; cin >> n; vector<int> a(20), b(50), c(50); rep(i, n) { cin >> a.at(i); } rep(i, n) { cin >> b.at(i); } rep(i, n - 1) { cin >> c.at(i); } ans = 0; rep(i, n) { temp = b.at(i); ans += temp; } rep(i, n - 1) { int FoodNo = a.at(i); if (FoodNo + 1 == a.at(i + 1)) { FoodNo = a.at(i); ans += c.at(FoodNo); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 1; i < (int)n + 1; i++) using namespace std; int main() { int n, ans, temp; cin >> n; vector<int> a(21), b(51), c(51); rep(i, n) { cin >> a.at(i); } rep(i, n) { cin >> b.at(i); } rep(i, n - 1) { cin >> c.at(i); } ans = 0; rep(i, n) { temp = b.at(i); ans += temp; } rep(i, n - 1) { int FoodNo = a.at(i); if (FoodNo + 1 == a.at(i + 1)) { FoodNo = a.at(i); ans += c.at(FoodNo); } } cout << ans << endl; return 0; }
replace
9
10
9
10
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // ----------------------R00TDADA------------------------------ #define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++) #define nrep(i, a, b) for (__typeof((b)) i = (b); i > (a); i--) #define all(a) (a).begin(), (a).end() #define ff first #define ss second #define ppi pair<int, int> #define pppi pair<ppi, int> #define vi vector<int> #define vii vector<ppi> #define viii vector<pppi> #define vs vector<string> #define pb push_back #define mp make_pair #define sz(x) (int)x.size() #define M_PI 3.14159265358979323846 #define rootdada ios_base::sync_with_stdio(false) #define int long long signed main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif rootdada; int n; cin >> n; int a[n], b[n], c[n]; rep(i, 0, n) cin >> a[i]; rep(i, 0, n) cin >> b[i]; rep(i, 0, n - 1) cin >> c[i]; int s = 0; rep(i, 0, n) { s += b[a[i] - 1]; if ((i != 0) && a[i] == a[i - 1] + 1) { s += c[a[i - 1] - 1]; } } cout << s << endl; }
#include <bits/stdc++.h> using namespace std; // ----------------------R00TDADA------------------------------ #define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++) #define nrep(i, a, b) for (__typeof((b)) i = (b); i > (a); i--) #define all(a) (a).begin(), (a).end() #define ff first #define ss second #define ppi pair<int, int> #define pppi pair<ppi, int> #define vi vector<int> #define vii vector<ppi> #define viii vector<pppi> #define vs vector<string> #define pb push_back #define mp make_pair #define sz(x) (int)x.size() #define M_PI 3.14159265358979323846 #define rootdada ios_base::sync_with_stdio(false) #define int long long signed main() { rootdada; int n; cin >> n; int a[n], b[n], c[n]; rep(i, 0, n) cin >> a[i]; rep(i, 0, n) cin >> b[i]; rep(i, 0, n - 1) cin >> c[i]; int s = 0; rep(i, 0, n) { s += b[a[i] - 1]; if ((i != 0) && a[i] == a[i - 1] + 1) { s += c[a[i - 1] - 1]; } } cout << s << endl; }
replace
22
28
22
23
-11
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); vector<int> B(N); for (int i = 0; i < N; i++) cin >> B.at(i); vector<int> C(N - 1); for (int i = 0; i < N - 1; i++) cin >> C.at(i); int sum = 0; for (int i = 0; i < N; i++) sum += B.at(i); for (int i = 0; i < N - 1; i++) { if (A.at(i + 1) - A.at(i) == 1) sum += C.at(A.at(i)); } cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); vector<int> B(N); for (int i = 0; i < N; i++) cin >> B.at(i); vector<int> C(N - 1); for (int i = 0; i < N - 1; i++) cin >> C.at(i); int sum = 0; for (int i = 0; i < N; i++) sum += B.at(i); for (int i = 0; i < N - 1; i++) { if (A.at(i + 1) - A.at(i) == 1) sum += C.at(A.at(i) - 1); } cout << sum << endl; return 0; }
replace
20
21
20
21
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); // vector<int> b(n); int ans = 0; int tmp; vector<int> c(n - 1); for (int i = 0; i < n; i++) { cin >> a.at(i); } for (int i = 0; i < n; i++) { cin >> tmp; ans += tmp; } for (int i = 0; i < n - 1; i++) { cin >> c.at(i); } for (int i = 0; i < n - 1; i++) { if (a.at(i) + 1 == a.at(i + 1)) { ans += c.at(a.at(i)); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); // vector<int> b(n); int ans = 0; int tmp; vector<int> c(n - 1); for (int i = 0; i < n; i++) { cin >> a.at(i); } for (int i = 0; i < n; i++) { cin >> tmp; ans += tmp; } for (int i = 0; i < n - 1; i++) { cin >> c.at(i); } for (int i = 0; i < n - 1; i++) { if (a.at(i) + 1 == a.at(i + 1)) { ans += c.at(a.at(i) - 1); } } cout << ans << endl; }
replace
23
24
23
24
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; int tManzoku = 0; cin >> N; vector<int> Ryouri(N); vector<int> Manzoku(N); vector<int> mBonus(N - 1); for (int i = 0; i < N; i++) cin >> Ryouri.at(i); for (int i = 0; i < N; i++) cin >> Manzoku.at(i); for (int i = 0; i < N - 1; i++) cin >> mBonus.at(i); for (int i = 0; i < N; i++) { if (i == 0) tManzoku += Manzoku.at(Ryouri.at(i) - 1); else { if (Ryouri.at(i) - 1 == Ryouri.at(i - 1)) tManzoku += Manzoku.at(Ryouri.at(i) - 1) + mBonus.at(i - 2); else { tManzoku += Manzoku.at(Ryouri.at(i) - 1); } } } cout << tManzoku << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; int tManzoku = 0; cin >> N; vector<int> Ryouri(N); vector<int> Manzoku(N); vector<int> mBonus(N - 1); for (int i = 0; i < N; i++) cin >> Ryouri.at(i); for (int i = 0; i < N; i++) cin >> Manzoku.at(i); for (int i = 0; i < N - 1; i++) cin >> mBonus.at(i); for (int i = 0; i < N; i++) { tManzoku += Manzoku.at(Ryouri.at(i) - 1); if (i != 0 && Ryouri.at(i - 1) + 1 == Ryouri.at(i)) tManzoku += mBonus.at(Ryouri.at(i - 1) - 1); } cout << tManzoku << endl; }
replace
17
26
17
20
0
p02916
C++
Runtime Error
#define _GLIBCXX_DEBUG #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <cstdint> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <tuple> #include <utility> #include <vector> using namespace std; int cnt; int ans; int main(void) { int N; cin >> N; vector<int> A(N); vector<int> B(N); vector<int> C(N - 1); for (int i = 0; i < N; i++) cin >> A.at(i); for (int i = 0; i < N; i++) cin >> B.at(i); for (int i = 0; i < N - 1; i++) cin >> C.at(i); int tmp; for (auto &i : A) { if (i == tmp + 1) ans += (B.at(i - 1) + C.at(tmp - 1)); else ans += B.at(i - 1); tmp = i; } cout << ans << endl; }
#define _GLIBCXX_DEBUG #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <cstdint> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <tuple> #include <utility> #include <vector> using namespace std; int cnt; int ans; int main(void) { int N; cin >> N; vector<int> A(N); vector<int> B(N); vector<int> C(N - 1); for (int i = 0; i < N; i++) cin >> A.at(i); for (int i = 0; i < N; i++) cin >> B.at(i); for (int i = 0; i < N - 1; i++) cin >> C.at(i); int tmp = -1; for (auto &i : A) { if (i == tmp + 1) ans += (B.at(i - 1) + C.at(tmp - 1)); else ans += B.at(i - 1); tmp = i; } cout << ans << endl; }
replace
36
37
36
37
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N), B(N), C(N - 1); for (int i = 0; i < N; i++) cin >> A.at(i); for (int i = 0; i < N; i++) cin >> B.at(i); for (int i = 0; i < N - 1; i++) cin >> C.at(i); int ans = 0; for (int i = 0; i < N; i++) { ans += B.at(i); } for (int i = 1; i < N; i++) { if (A.at(i) - 1 == A.at(i - 1)) { ans += C.at(i); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N), B(N), C(N - 1); for (int i = 0; i < N; i++) cin >> A.at(i); for (int i = 0; i < N; i++) cin >> B.at(i); for (int i = 0; i < N - 1; i++) cin >> C.at(i); int ans = 0; for (int i = 0; i < N; i++) { ans += B.at(i); } for (int i = 1; i < N; i++) { if (A.at(i) - 1 == A.at(i - 1)) { ans += C.at(A.at(i) - 2); } } cout << ans << endl; }
replace
24
25
24
25
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)
p02916
C++
Runtime Error
/* _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\||| : |||// \ / _||||| -:- |||||- \ | | \\\ - /// | | | \_| ''\---/'' | | \ .-\__ `-` ___/-. / ___`. .' /--.--\ `. . __ ."" '< `.___\_<|>_/___.' >'"". | | : `- \`.;`\ _ /`;.`/ - ` : | | \ \ `-. \_ __\ /__ _/ .-` / / ======`-.____`-.___\_____/___.-`____.-'====== `=---=' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ prayer */ // g++ -std=c++11 a.cpp #include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <typeinfo> #include <unordered_map> #include <utility> #include <vector> #define loop(i, a, b) for (long long i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define FOR(i, a) for (auto i : a) #define pb push_back #define all(in) in.begin(), in.end() #define shosu(x) fixed << setprecision(x) #define show1d(v) \ { \ rep(_, v.size()) cout << " " << v[_]; \ cout << endl; \ } #define show2d(v) \ { rep(__, v.size()) show1d(v[__]); } using namespace std; // kaewasuretyuui typedef long long ll; // #define int ll typedef int Def; typedef pair<Def, Def> pii; typedef vector<Def> vi; typedef vector<vi> vvi; typedef vector<pii> vp; typedef vector<vp> vvp; typedef vector<string> vs; typedef vector<double> vd; typedef vector<vd> vvd; typedef pair<Def, pii> pip; typedef vector<pip> vip; #define mt make_tuple typedef tuple<int, int, int, int> tp; typedef vector<tp> vt; template <typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; } template <typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; } const double PI = acos(-1); const double EPS = 1e-9; Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9 + 10; #define yes cout << "Yes\n" #define no cout << "No\n" template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; vi a(n), b(n), c(n - 1); cin >> a >> b >> c; int t = 0; rep(i, n) t += b[i]; rep(i, n - 1) if (a[i] + 1 == a[i + 1]) t += c[a[i] - 1]; cout << t << endl; }
/* _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\||| : |||// \ / _||||| -:- |||||- \ | | \\\ - /// | | | \_| ''\---/'' | | \ .-\__ `-` ___/-. / ___`. .' /--.--\ `. . __ ."" '< `.___\_<|>_/___.' >'"". | | : `- \`.;`\ _ /`;.`/ - ` : | | \ \ `-. \_ __\ /__ _/ .-` / / ======`-.____`-.___\_____/___.-`____.-'====== `=---=' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ prayer */ // g++ -std=c++11 a.cpp #include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <typeinfo> #include <unordered_map> #include <utility> #include <vector> #define loop(i, a, b) for (long long i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define FOR(i, a) for (auto i : a) #define pb push_back #define all(in) in.begin(), in.end() #define shosu(x) fixed << setprecision(x) #define show1d(v) \ { \ rep(_, v.size()) cout << " " << v[_]; \ cout << endl; \ } #define show2d(v) \ { rep(__, v.size()) show1d(v[__]); } using namespace std; // kaewasuretyuui typedef long long ll; // #define int ll typedef int Def; typedef pair<Def, Def> pii; typedef vector<Def> vi; typedef vector<vi> vvi; typedef vector<pii> vp; typedef vector<vp> vvp; typedef vector<string> vs; typedef vector<double> vd; typedef vector<vd> vvd; typedef pair<Def, pii> pip; typedef vector<pip> vip; #define mt make_tuple typedef tuple<int, int, int, int> tp; typedef vector<tp> vt; template <typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; } template <typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; } const double PI = acos(-1); const double EPS = 1e-9; Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9 + 10; #define yes cout << "Yes\n" #define no cout << "No\n" template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vi a(n), b(n), c(n - 1); cin >> a >> b >> c; int t = 0; rep(i, n) t += b[i]; rep(i, n - 1) if (a[i] + 1 == a[i + 1]) t += c[a[i] - 1]; cout << t << endl; }
insert
98
98
98
99
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N); int ans; ans = 0; for (int i = 0; i < N; i++) { cin >> A.at(i); } vector<int> B(N); for (int i = 0; i < N; i++) { cin >> B.at(i); } vector<int> C(N - 1); for (int i = 0; i < N - 1; i++) { cin >> C.at(i); } for (int i = 0; i < N - 1; i++) { if (A.at(i) + 1 == A.at(i + 1)) { ans += C.at(A.at(i)); } } for (int i = 0; i < N; i++) { ans += B.at(i); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N); int ans; ans = 0; for (int i = 0; i < N; i++) { cin >> A.at(i); } vector<int> B(N); for (int i = 0; i < N; i++) { cin >> B.at(i); } vector<int> C(N - 1); for (int i = 0; i < N - 1; i++) { cin >> C.at(i); } for (int i = 0; i < N - 1; i++) { if (A.at(i) + 1 == A.at(i + 1)) { ans += C.at(A.at(i) - 1); } } for (int i = 0; i < N; i++) { ans += B.at(i); } cout << ans << endl; }
replace
22
23
22
23
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; vector<int> a(n), b(n), c(n - 1); for (auto &i : a) cin >> i; for (auto &i : b) cin >> i; for (auto &i : c) cin >> i; int sut = 0; int prex = 0; for (auto xa : a) { sut += b.at(xa - 1); if (xa == prex + 1) sut += c.at(xa - 2); prex = xa; } cout << sut << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; vector<int> a(n), b(n), c(n - 1); for (auto &i : a) cin >> i; for (auto &i : b) cin >> i; for (auto &i : c) cin >> i; int sut = 0; int prex = 0; for (auto xa : a) { sut += b.at(xa - 1); if (xa >= 2 && xa == prex + 1) sut += c.at(xa - 2); prex = xa; } cout << sut << endl; return 0; }
replace
17
18
17
18
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; long long ncr(int n, int r) { if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r) long long ans = 1; int i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } ll mod(ll a, ll b, ll m) { if (b == 0) return 1; if (b % 2 == 0) { ll y = mod(a, b / 2, m); return (y * y) % m; } else { return ((a % m) * mod(a, b - 1, m)) % m; } } ll modinv(ll a, ll m) { return mod(a, m - 2, m); // works only for prime m. // else calculate phi(m)-1. } int main() { int n; cin >> n; vector<int> a(n), b(n), c(n); int ans = 0; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; for (int i = 1; i <= n - 1; i++) cin >> c[i]; int p = -1; for (int i = 1; i <= n; i++) { ans += b[a[i]]; if (a[i] == p + 1) ans += c[a[i] - 1]; p = a[i]; } cout << ans; return 0; }
#include <bits/stdc++.h> #include <iostream> #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; long long ncr(int n, int r) { if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r) long long ans = 1; int i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } ll mod(ll a, ll b, ll m) { if (b == 0) return 1; if (b % 2 == 0) { ll y = mod(a, b / 2, m); return (y * y) % m; } else { return ((a % m) * mod(a, b - 1, m)) % m; } } ll modinv(ll a, ll m) { return mod(a, m - 2, m); // works only for prime m. // else calculate phi(m)-1. } int main() { int n; cin >> n; vector<int> a(n + 1), b(n + 1), c(n + 1); int ans = 0; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; for (int i = 1; i <= n - 1; i++) cin >> c[i]; int p = -1; for (int i = 1; i <= n; i++) { ans += b[a[i]]; if (a[i] == p + 1) ans += c[a[i] - 1]; p = a[i]; } cout << ans; return 0; }
replace
40
41
40
41
0
p02916
C++
Time Limit Exceeded
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<ll> vl; typedef vector<vector<int, int>> vvi; #define pb push_back #define mp make_pair #define f first #define s second #define in insert #define FOR(i, a, b) for (int i = a; i < b; i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define speed \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); const int INF = 1e9 + 5; int main() { int n; cin >> n; vi a; vi b; vi c; int x; for (int i = 0; i < n; i++) { cin >> x; a.pb(x); } for (int i = 0; i < n; i++) { cin >> x; b.pb(x); } while (true) { int input; cin >> input; if (input == -100) break; c.pb(input); } int sum = 0; for (int i = 0; i < n; i++) { sum += b[a[i] - 1]; } for (int i = 0; i < (n - 1); i++) { if ((a[i + 1] - a[i]) == 1) { sum += c[a[i] - 1]; } } cout << sum; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<ll> vl; typedef vector<vector<int, int>> vvi; #define pb push_back #define mp make_pair #define f first #define s second #define in insert #define FOR(i, a, b) for (int i = a; i < b; i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define speed \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); const int INF = 1e9 + 5; int main() { int n; cin >> n; vi a; vi b; vi c; int x; for (int i = 0; i < n; i++) { cin >> x; a.pb(x); } for (int i = 0; i < n; i++) { cin >> x; b.pb(x); } for (int i = 0; i < n - 1; i++) { cin >> x; c.pb(x); } int sum = 0; for (int i = 0; i < n; i++) { sum += b[a[i] - 1]; } for (int i = 0; i < (n - 1); i++) { if ((a[i + 1] - a[i]) == 1) { sum += c[a[i] - 1]; } } cout << sum; }
replace
39
46
39
42
TLE
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 1; i <= (int)n; i++) #define rep2(i, m, n) for (int i = (int)m; i < (int)n; i++) typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<vi> vii; // 2次元配列 typedef vector<ll> vll; typedef vector<string> vs; /*FUNCs=================================================*/ /*MAIN==================================================*/ int main() { cin.tie(nullptr); ios::sync_with_stdio(false); // cin cout 高速化 int n; cin >> n; vi a(n), b(n), c(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, n) cin >> c[i]; c.push_back(-100); int cnt = 0; int pre_I = -100; rep(i, n) { int I = a[i]; cnt += b[I]; if (I == pre_I + 1) cnt += c[pre_I]; pre_I = I; } cout << cnt << '\n'; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 1; i <= (int)n; i++) #define rep2(i, m, n) for (int i = (int)m; i < (int)n; i++) typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<vi> vii; // 2次元配列 typedef vector<ll> vll; typedef vector<string> vs; /*FUNCs=================================================*/ /*MAIN==================================================*/ int main() { cin.tie(nullptr); ios::sync_with_stdio(false); // cin cout 高速化 int n; cin >> n; vi a(n + 1), b(n + 1), c(n + 1); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, n) cin >> c[i]; c.push_back(-100); int cnt = 0; int pre_I = -100; rep(i, n) { int I = a[i]; cnt += b[I]; if (I == pre_I + 1) cnt += c[pre_I]; pre_I = I; } cout << cnt << '\n'; }
replace
21
22
21
22
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); vector<int> b(n); vector<int> c(n - 1); for (int i = 0; i < n; i++) { cin >> a.at(i); } for (int i = 0; i < n; i++) { cin >> b.at(i); } for (int i = 0; i < n - 1; i++) { cin >> c.at(i); } int satis = 0; for (int i = 0; i < n; i++) { satis += b.at(a.at(i) - 1); } for (int i = 0; i < n - 1; i++) { if (a.at(i) == a.at(i + 1) - 1) satis += c.at(i + 1); } cout << satis << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); vector<int> b(n); vector<int> c(n - 1); for (int i = 0; i < n; i++) { cin >> a.at(i); } for (int i = 0; i < n; i++) { cin >> b.at(i); } for (int i = 0; i < n - 1; i++) { cin >> c.at(i); } int satis = 0; for (int i = 0; i < n; i++) { satis += b.at(a.at(i) - 1); } for (int i = 0; i < n - 1; i++) { if (a.at(i) == a.at(i + 1) - 1) satis += c.at(a.at(i) - 1); } cout << satis << endl; }
replace
24
25
24
25
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)
p02916
C++
Runtime Error
/* ****mittal**** */ #include <bits/stdc++.h> #define ll long long int #define pb push_back #define endl '\n' #define pii pair<ll int, ll int> #define vi vector<ll int> #define all(a) (a).begin(), (a).end() #define F first #define S second #define sz(x) (ll int)x.size() #define hell 1000000007 #define rep(i, a, b) for (ll int i = a; i < b; i++) #define repr(i, a, b) for (ll int i = a; i >= b; i--) #define lbnd lower_bound #define ubnd upper_bound #define mp make_pair using namespace std; #define N 100005 int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int TESTS = 1; // cin>>TESTS; while (TESTS--) { ll n; cin >> n; ll a[28], b[28], c[28]; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { cin >> b[i]; } a[0] = 500; for (int i = 1; i <= n - 1; i++) cin >> c[i]; ll ans = 0; for (int i = 1; i <= n; i++) { ans += b[a[i]]; if (a[i] = a[i - 1] + 1) ans += c[a[i]]; } cout << ans; } return 0; }
/* ****mittal**** */ #include <bits/stdc++.h> #define ll long long int #define pb push_back #define endl '\n' #define pii pair<ll int, ll int> #define vi vector<ll int> #define all(a) (a).begin(), (a).end() #define F first #define S second #define sz(x) (ll int)x.size() #define hell 1000000007 #define rep(i, a, b) for (ll int i = a; i < b; i++) #define repr(i, a, b) for (ll int i = a; i >= b; i--) #define lbnd lower_bound #define ubnd upper_bound #define mp make_pair using namespace std; #define N 100005 int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int TESTS = 1; // cin>>TESTS; while (TESTS--) { ll n; cin >> n; ll a[28], b[28], c[28]; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { cin >> b[i]; } a[0] = 500; for (int i = 1; i <= n - 1; i++) cin >> c[i]; ll ans = 0; for (int i = 1; i <= n; i++) { ans += b[a[i]]; if (a[i] == a[i - 1] + 1) ans += c[a[i - 1]]; } cout << ans; } return 0; }
replace
41
43
41
43
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define all(a) a.begin(), a.end() #define P pair<long long, long long> #define double long double using namespace std; signed main() { int a; cin >> a; vector<int> b(a); vector<int> c(a); vector<int> d(a - 1); rep(i, a) cin >> b.at(i); rep(i, a) cin >> c.at(i); rep(i, a - 1) cin >> d.at(i); int e = 0; rep(i, a) e += c.at(i); rep(i, a - 1) e += d.at(i); if (b.at(a - 1) == a) cout << e; else cout << e - d.at(b.at(a - 1)); }
#include <bits/stdc++.h> #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define all(a) a.begin(), a.end() #define P pair<long long, long long> #define double long double using namespace std; signed main() { int a; cin >> a; vector<int> b(a); vector<int> c(a); vector<int> d(a - 1); rep(i, a) cin >> b.at(i); rep(i, a) cin >> c.at(i); rep(i, a - 1) cin >> d.at(i); int e = 0; rep(i, a) e += c.at(i); rep(i, a - 1) { if (b.at(i) + 1 == b.at(i + 1)) e += d.at(b.at(i) - 1); } cout << e; }
replace
19
24
19
24
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)
p02916
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <math.h> #include <numeric> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <utility> #include <vector> #define rep(i, f, n) for (int(i) = (f); i < (n); i++) #define LL long long int /* greater<int>() sortの第三因数に入れて降順 sqrt(double) √を求める pair<int,int> x=make_pair(a,b) x.first tuple get<番目>(変数名) */ using namespace std; LL lcm(LL n, LL m) { LL u; LL ansl = 0; for (u = m; u >= m; u++) { if (u % n == 0) { if (u % m == 0) { ansl = u; break; } } } return ansl; } int main(void) { int n; cin >> n; vector<int> a(n), b(n), c(n); rep(i, 1, n + 1) { scanf("%d", &a[i]); } rep(i, 1, n + 1) { scanf("%d", &b[i]); } rep(i, 1, n) { scanf("%d", &c[i]); } int mae = 6000; int ans = 0; rep(i, 1, n + 1) { if (a[i] == mae + 1) { ans += c[mae]; } ans += b[a[i]]; mae = a[i]; } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <math.h> #include <numeric> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <utility> #include <vector> #define rep(i, f, n) for (int(i) = (f); i < (n); i++) #define LL long long int /* greater<int>() sortの第三因数に入れて降順 sqrt(double) √を求める pair<int,int> x=make_pair(a,b) x.first tuple get<番目>(変数名) */ using namespace std; LL lcm(LL n, LL m) { LL u; LL ansl = 0; for (u = m; u >= m; u++) { if (u % n == 0) { if (u % m == 0) { ansl = u; break; } } } return ansl; } int main(void) { int n; cin >> n; int a[n + 1], b[n + 1], c[n + 1]; rep(i, 1, n + 1) { scanf("%d", &a[i]); } rep(i, 1, n + 1) { scanf("%d", &b[i]); } rep(i, 1, n) { scanf("%d", &c[i]); } int mae = 6000; int ans = 0; rep(i, 1, n + 1) { if (a[i] == mae + 1) { ans += c[mae]; } ans += b[a[i]]; mae = a[i]; } cout << ans << endl; return 0; }
replace
45
46
45
46
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0; cin >> n; vector<int> a(n); vector<int> b(n); vector<int> c(n - 1); for (int i = 0; i < n; i++) { cin >> a.at(i); } for (int i = 0; i < n; i++) { cin >> b.at(i); } for (int i = 0; i < n - 1; i++) { cin >> c.at(i); } for (int i = 0; i < n; i++) { sum += b.at(i); } for (int i = 0; i < n - 1; i++) { if (a.at(i) + 1 == a.at(i + 1)) { sum += c.at(i - 1); } } cout << sum; }
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0; cin >> n; vector<int> a(n); vector<int> b(n); vector<int> c(n - 1); for (int i = 0; i < n; i++) { cin >> a.at(i); } for (int i = 0; i < n; i++) { cin >> b.at(i); } for (int i = 0; i < n - 1; i++) { cin >> c.at(i); } for (int i = 0; i < n; i++) { sum += b.at(i); } for (int i = 0; i < n - 1; i++) { if (a.at(i) + 1 == a.at(i + 1)) { sum += c.at(a.at(i) - 1); } } cout << sum; }
replace
26
27
26
27
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) using namespace std; int main() { int N; cin >> N; vector<int> A(N); vector<int> B(N); vector<int> C(N); int ans = 0; rep(i, N) { cin >> A[i]; } rep(i, N) { cin >> B[i]; ans += B[i]; } rep(i, N) { cin >> C[i]; } rep(i, N) { if (A[i + 1] = A[i] + 1) ans += C[A[i] - 1]; } cout << ans; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) using namespace std; int main() { int N; cin >> N; vector<int> A(N); vector<int> B(N); vector<int> C(N); int ans = 0; rep(i, N) { cin >> A[i]; } rep(i, N) { cin >> B[i]; ans += B[i]; } rep(i, N) { cin >> C[i]; } rep(i, N - 1) { if (A[i + 1] == A[i] + 1) ans += C[A[i] - 1]; } cout << ans; return 0; }
replace
16
18
16
18
0
p02916
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <iostream> #include <string> using namespace std; int MOD = 1000000007; int main(void) { int N, ans = 0; cin >> N; int A[N + 10], B[N + 10], C[N + 10]; for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) cin >> B[i]; for (int i = 0; i < N - 1; i++) cin >> C[i]; for (int i = 0; i < N; i++) { if (i != 0 && A[i - 1] + 1 == A[i]) { ans += C[A[i - 2]]; } ans += B[A[i] - 1]; } cout << ans << endl; }
#include <algorithm> #include <bits/stdc++.h> #include <iostream> #include <string> using namespace std; int MOD = 1000000007; int main(void) { int N, ans = 0; cin >> N; int A[N + 10], B[N + 10], C[N + 10]; for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) cin >> B[i]; for (int i = 0; i < N - 1; i++) cin >> C[i]; for (int i = 0; i < N; i++) { if (i != 0 && A[i - 1] + 1 == A[i]) { ans += C[A[i - 1] - 1]; } ans += B[A[i] - 1]; } cout << ans << endl; }
replace
20
21
20
21
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; scanf("%d", &N); vector<int> A(N, 0); for (int i = 0; i < N; i++) { scanf("%d", &A.at(i)); A.at(i)--; } vector<int> B(N, 0); for (int i = 0; i < N; i++) { scanf("%d", &B.at(i)); } vector<int> C(N - 1, 0); for (int i = 0; i < N - 1; i++) { scanf("%d", &C.at(i)); } int ans = 0; for (int i = 0; i < N; i++) { ans += B.at(A.at(i)); if (i > 0 && A.at(i) == A.at(i - 1) - 1) { ans += C.at(A.at(i - 1)); } } printf("%d", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; scanf("%d", &N); vector<int> A(N, 0); for (int i = 0; i < N; i++) { scanf("%d", &A.at(i)); A.at(i)--; } vector<int> B(N, 0); for (int i = 0; i < N; i++) { scanf("%d", &B.at(i)); } vector<int> C(N - 1, 0); for (int i = 0; i < N - 1; i++) { scanf("%d", &C.at(i)); } int ans = 0; for (int i = 0; i < N; i++) { ans += B.at(A.at(i)); if (i > 0 && A.at(i) == A.at(i - 1) + 1) { ans += C.at(A.at(i - 1)); } } printf("%d", ans); return 0; }
replace
26
27
26
27
0
p02916
C++
Time Limit Exceeded
#include <iostream> #include <string> int main(void) { // int N; N = 0; std::cin >> N; // A int *A = new int[N](); int *B = new int[N](); int *C = new int[N](); for (int i = 1; i <= N; i++) { while (!(std::cin >> A[i])) { } // std::cout << A[i] << std::endl; // } // B int sum = 0; for (int i = 1; i <= N; i++) { while (!(std::cin >> B[i])) { } } // C for (int i = 1; i < N; i++) { sum += B[A[i]]; // std::cout << B[A[i]] << std::endl; // std::cout << sum << std::endl; while (!(std::cin >> C[i])) { } } sum += B[A[N]]; for (int i = 1; i < N; i++) { if (A[i] + 1 == A[i + 1]) { sum += C[A[i]]; } // std::cout << sum << std::endl; } // std::cout << sum << std::endl; while (1) { } return 0; }
#include <iostream> #include <string> int main(void) { // int N; N = 0; std::cin >> N; // A int *A = new int[N](); int *B = new int[N](); int *C = new int[N](); for (int i = 1; i <= N; i++) { while (!(std::cin >> A[i])) { } // std::cout << A[i] << std::endl; // } // B int sum = 0; for (int i = 1; i <= N; i++) { while (!(std::cin >> B[i])) { } } // C for (int i = 1; i < N; i++) { sum += B[A[i]]; // std::cout << B[A[i]] << std::endl; // std::cout << sum << std::endl; while (!(std::cin >> C[i])) { } } sum += B[A[N]]; for (int i = 1; i < N; i++) { if (A[i] + 1 == A[i + 1]) { sum += C[A[i]]; } // std::cout << sum << std::endl; } // std::cout << sum << std::endl; return 0; }
delete
43
45
43
43
TLE
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int A; cin >> A; vector<int> b(A + 1); vector<int> c(A + 1); vector<int> d(A + 1); int ans = 0; for (int i = 0; i < A; i++) { cin >> b.at(i); } for (int i = 0; i < A; i++) { cin >> c.at(i); } for (int i = 0; i < A - 1; i++) { cin >> d.at(i); } for (int i = 0; i < A; i++) { ans += c.at(b.at(i) - 1); if (b.at(i) == b.at(i + 1) - 1) ; ans += d.at(i - 1); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int A; cin >> A; vector<int> b(A + 1); vector<int> c(A + 1); vector<int> d(A + 1); int ans = 0; for (int i = 0; i < A; i++) { cin >> b.at(i); } for (int i = 0; i < A; i++) { cin >> c.at(i); } for (int i = 0; i < A - 1; i++) { cin >> d.at(i); } for (int i = 0; i < A; i++) { ans += c.at(b.at(i) - 1); if (b.at(i) == b.at(i + 1) - 1) { ans += d.at(b.at(i) - 1); } } cout << ans << endl; }
replace
22
25
22
25
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 4)
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; int chk = -1; int pnt = 0; cin >> n; vector<int> a(n); vector<int> b(n); vector<int> c(n - 1); for (int i = 0; i < n; i++) { cin >> a.at(i); } for (int i = 0; i < n; i++) { cin >> b.at(i); } for (int i = 0; i < n - 1; i++) { cin >> c.at(i); } for (int i = 0; i < n; i++) { int x = a.at(i) - 1; pnt += b.at(x); if (x - 1 == chk) { pnt += c.at(x - 1); } chk = x; } cout << pnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; int chk = -1; int pnt = 0; cin >> n; vector<int> a(n); vector<int> b(n); vector<int> c(n - 1); for (int i = 0; i < n; i++) { cin >> a.at(i); } for (int i = 0; i < n; i++) { cin >> b.at(i); } for (int i = 0; i < n - 1; i++) { cin >> c.at(i); } for (int i = 0; i < n; i++) { int x = a.at(i) - 1; pnt += b.at(x); if (x - 1 == chk && x != 0) { pnt += c.at(x - 1); } chk = x; } cout << pnt << endl; return 0; }
replace
26
27
26
27
0
p02916
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n, ans = 0; cin >> n; vector<int> a{0}, b{0}, c{0}; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i]; for (int i = 0; i < n - 1; ++i) cin >> c[i]; for (int i = 0; i < n; ++i) { ans += b[a[i] - 1]; if (a[i] + 1 == a[i + 1] && a[i + 1] != 0) { ans += c[a[i] - 1]; } } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n, ans = 0; cin >> n; int a[n], b[n], c[n - 1]; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i]; for (int i = 0; i < n - 1; ++i) cin >> c[i]; for (int i = 0; i < n; ++i) { ans += b[a[i] - 1]; if (a[i] + 1 == a[i + 1] && a[i + 1] != 0) { ans += c[a[i] - 1]; } } cout << ans << endl; return 0; }
replace
9
10
9
10
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ans = 0; int before = n + 1; vector<int> a(n), b(n), c(n - 1); for (int i = 0; i < n; i++) cin >> a.at(i); for (int i = 0; i < n; i++) cin >> b.at(i); for (int i = 0; i < n - 1; i++) cin >> c.at(i); for (int i = 0; i < n; i++) { ans += b.at(a.at(i) - 1); if (a.at(i) - 1 == before) ans += c.at(a.at(i) - 1); before = a.at(i); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ans = 0; int before = n + 1; vector<int> a(n), b(n), c(n - 1); for (int i = 0; i < n; i++) cin >> a.at(i); for (int i = 0; i < n; i++) cin >> b.at(i); for (int i = 0; i < n - 1; i++) cin >> c.at(i); for (int i = 0; i < n; i++) { ans += b.at(a.at(i) - 1); if (a.at(i) - 1 == before) ans += c.at(a.at(i) - 2); before = a.at(i); } cout << ans << endl; return 0; }
replace
22
23
22
23
0
p02916
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define ll long long #define pp pair<int, int> const int INF = 1001001001; // int 2×10の9乗 // vector<vector<int>> a(n, vector<int>(m)); // rep(i,n){ // rep(j,m) cin >> a[i][j]; //} int main() { int n; cin >> n; vector<int> a(n), b(n), c(n - 1); for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; for (int i = 1; i <= n - 1; i++) cin >> c[i]; int ans = b[a[1]]; for (int i = 2; i <= n; i++) { if (a[i] == a[i - 1] + 1) ans += b[a[i]] + c[a[i - 1]]; else ans += b[a[i]]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define ll long long #define pp pair<int, int> const int INF = 1001001001; // int 2×10の9乗 // vector<vector<int>> a(n, vector<int>(m)); // rep(i,n){ // rep(j,m) cin >> a[i][j]; //} int main() { int n; cin >> n; vector<int> a(n), b(n), c(n - 1); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, n - 1) cin >> c[i]; rep(i, n) a[i]--; int ans = 0; rep(i, n) ans += b[a[i]]; rep(i, n - 1) { if (a[i] + 1 == a[i + 1]) ans += c[a[i]]; } cout << ans << endl; }
replace
17
29
17
26
0
p02916
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n, a[n], b[n], c[n - 1]; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } for (int i = 0; i <= n; i++) { cin >> c[i]; } int score = b[a[0] - 1]; for (int i = 1; i < n; i++) { score += b[a[i] - 1]; if (a[i] - a[i - 1] == 1) score += c[a[i - 1] - 1]; } cout << score; return 0; }
#include <iostream> using namespace std; int main() { int n, a[21], b[21], c[21]; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } for (int i = 0; i <= n; i++) { cin >> c[i]; } int score = b[a[0] - 1]; for (int i = 1; i < n; i++) { score += b[a[i] - 1]; if (a[i] - a[i - 1] == 1) score += c[a[i - 1] - 1]; } cout << score; return 0; }
replace
4
5
4
5
-11
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, a[21], b[21], s = 0; cin >> n; for (int i = 1; i <= n - 1; i++) scanf("%d", &b[i]); for (int i = n - 1; i >= 1; i--) { if (i == n - 1) { a[i + 1] = b[i]; a[i] = b[i]; } else if (b[i] < a[i + 1]) { a[i + 1] = b[i]; a[i] = b[i]; } else a[i] = b[i]; } for (int i = 1; i <= n; i++) s += a[i]; cout << s; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a[101], b[101], s = 0; cin >> n; for (int i = 1; i <= n - 1; i++) scanf("%d", &b[i]); for (int i = n - 1; i >= 1; i--) { if (i == n - 1) { a[i + 1] = b[i]; a[i] = b[i]; } else if (b[i] < a[i + 1]) { a[i + 1] = b[i]; a[i] = b[i]; } else a[i] = b[i]; } for (int i = 1; i <= n; i++) s += a[i]; cout << s; return 0; }
replace
3
4
3
4
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define all(v) v.begin(), v.end() using in = int64_t; #define rep(i, n) for (in i = 0; i < (in)(n); i++) const double PI = 3.14159265358979323846; const int64_t waru = 1000000007; const in INF = 1 << 30; #define vecvec(a, y, x) vector<vector<int>> a(y, vector<int>(x)) #define vec(a, n) \ vector<int> a(n); \ rep(i, n) cin >> a[i] int main() { int n; vec(b, n - 1); vector<int> a(n - 1); a[0] = b[0]; for (int i = 1; i < n - 1; i++) { a[i] = min(b[i - 1], b[i]); } int ans = b[n - 2]; rep(i, n - 1) ans += a[i]; cout << ans; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define all(v) v.begin(), v.end() using in = int64_t; #define rep(i, n) for (in i = 0; i < (in)(n); i++) const double PI = 3.14159265358979323846; const int64_t waru = 1000000007; const in INF = 1 << 30; #define vecvec(a, y, x) vector<vector<int>> a(y, vector<int>(x)) #define vec(a, n) \ vector<int> a(n); \ rep(i, n) cin >> a[i] int main() { int n; cin >> n; vec(b, n - 1); vector<int> a(n - 1); a[0] = b[0]; for (int i = 1; i < n - 1; i++) { a[i] = min(b[i - 1], b[i]); } int ans = b[n - 2]; rep(i, n - 1) ans += a[i]; cout << ans; }
insert
16
16
16
17
-6
terminate called after throwing an instance of 'std::length_error' what(): cannot create std::vector larger than max_size()
p02917
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { int n; vector<int> b(n - 1); rep(i, n - 1) cin >> b[i]; vector<int> a(n); a[0] = b[0]; for (int i = 1; i <= n - 2; i++) { a[i] = min(b[i], b[i - 1]); } a[n - 1] = b[n - 2]; int ans = 0; rep(i, n) ans += a[i]; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { int n; cin >> n; vector<int> b(n - 1); rep(i, n - 1) cin >> b[i]; vector<int> a(n); a[0] = b[0]; for (int i = 1; i <= n - 2; i++) { a[i] = min(b[i], b[i - 1]); } a[n - 1] = b[n - 2]; int ans = 0; rep(i, n) ans += a[i]; cout << ans << endl; return 0; }
insert
7
7
7
8
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define ll long long #define pp pair<int, int> const int INF = 1001001001; // int 2×10の9乗 // vector<vector<int>> a(n, vector<int>(m)); // rep(i,n){ // rep(j,m) cin >> a[i][j]; //} int main() { int n; cin >> n; vector<int> a(n), b(n - 1); for (int i = 1; i <= n - 1; i++) cin >> b[i]; int ans = b[1]; for (int i = 1; i <= n - 1; i++) { a[i + 1] = b[i]; ans += a[i + 1]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define ll long long #define pp pair<int, int> const int INF = 1001001001; // int 2×10の9乗 // vector<vector<int>> a(n, vector<int>(m)); // rep(i,n){ // rep(j,m) cin >> a[i][j]; //} int main() { int n; cin >> n; vector<int> a(n), b(n - 1); rep(i, n) cin >> b[i]; a[0] = b[0]; rep(i, n - 2) a[i + 1] = min(b[i], b[i + 1]); a[n - 1] = b[n - 2]; int ans = 0; rep(i, n) ans += a[i]; cout << ans << endl; }
replace
17
24
17
23
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18; const int BIG = 1e9 + 555; const int maxN = 20 + 9; int n; int a[maxN], b[maxN]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i + 1 <= n; i++) { cin >> b[i]; } b[0] = b[n] = BIG; ll sum = 0; for (int i = 1; i <= n; i++) { a[i] = min(b[i - 1], b[i]); sum += a[i]; } cout << sum << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e18; const int BIG = 1e9 + 555; const int maxN = 1e5 + 9; int n; int a[maxN], b[maxN]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i + 1 <= n; i++) { cin >> b[i]; } b[0] = b[n] = BIG; ll sum = 0; for (int i = 1; i <= n; i++) { a[i] = min(b[i - 1], b[i]); sum += a[i]; } cout << sum << '\n'; return 0; }
replace
6
7
6
7
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) using namespace std; typedef long long ll; int n; vector<int> b; ll ans; const int inf = 100000000; int main(int argc, char **argv) { cin >> n; b.resize(n - 1); rep(i, n - 1) { cin >> b[i]; } b[n - 1] = inf; ans = b[0]; rep(i, n - 1) { ans += min(b[i], b[i + 1]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) using namespace std; typedef long long ll; int n; vector<int> b; ll ans; const int inf = 100000000; int main(int argc, char **argv) { cin >> n; b.resize(n); rep(i, n - 1) { cin >> b[i]; } b[n - 1] = inf; ans = b[0]; rep(i, n - 1) { ans += min(b[i], b[i + 1]); } cout << ans << endl; return 0; }
replace
11
12
11
12
0
p02917
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; vector<int> b(n - 1); rep(i, n - 1) cin >> b[i]; vector<int> a(n); a[0] = b[0]; for (int i = 1; i <= n - 2; i++) { a[i] = min(b[i], b[i - 1]); } a[n - 1] = b[n - 2]; int ans = 0; rep(i, n) ans += a[i]; 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>; int main() { int n; cin >> n; vector<int> b(n - 1); rep(i, n - 1) cin >> b[i]; vector<int> a(n); a[0] = b[0]; for (int i = 1; i <= n - 2; i++) { a[i] = min(b[i], b[i - 1]); } a[n - 1] = b[n - 2]; int ans = 0; rep(i, n) ans += a[i]; cout << ans << endl; return 0; }
insert
8
8
8
9
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; using namespace std; int main() { int N; vector<ll> A(N + 1); vector<ll> B(N); for (int i = 1; i <= N - 1; i++) cin >> B[i]; ll ans = 0; A[1] = B[1]; A[N] = B[N - 1]; for (int i = 2; i <= N - 1; i++) { A[i] = min(B[i - 1], B[i]); } for (int i = 1; i <= N; i++) ans += A[i]; cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; using namespace std; int main() { int N; cin >> N; vector<ll> A(N + 1); vector<ll> B(N); for (int i = 1; i <= N - 1; i++) cin >> B[i]; ll ans = 0; A[1] = B[1]; A[N] = B[N - 1]; for (int i = 2; i <= N - 1; i++) { A[i] = min(B[i - 1], B[i]); } for (int i = 1; i <= N; i++) ans += A[i]; cout << ans << endl; }
insert
8
8
8
9
0
p02917
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> A(N), B(N - 1); for (int i = 1; i <= N - 1; i++) { cin >> B[i]; } int ans = B[1] + B[N - 1]; for (int i = 0; i <= N - 2; i++) { ans += min(B[i], B[i + 1]); } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> B(N); for (int i = 1; i <= N - 1; i++) { cin >> B[i]; } int ans = B[1] + B[N - 1]; for (int i = 0; i <= N - 2; i++) { ans += min(B[i], B[i + 1]); } cout << ans << endl; }
replace
9
10
9
10
0
p02917
C++
Runtime Error
#include <algorithm> #include <bitset> #include <functional> #include <iomanip> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) const long long mod = 1000000007; typedef long long ll; int main() { int N; cin >> N; vector<int> B(N - 1); rep(i, N - 1) cin >> B.at(i); int ans = B.at(0) + B.at(N - 1); for (int i = 1; i < N - 1; i++) { if (B.at(i - 1) >= B.at(i)) { ans += B.at(i); } else { ans += B.at(i - 1); } } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <functional> #include <iomanip> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) const long long mod = 1000000007; typedef long long ll; int main() { int N; cin >> N; vector<int> B(N - 1); rep(i, N - 1) cin >> B.at(i); int ans = B.at(0) + B.at(N - 2); for (int i = 1; i < N - 1; i++) { if (B.at(i - 1) >= B.at(i)) { ans += B.at(i); } else { ans += B.at(i - 1); } } cout << ans << endl; return 0; }
replace
19
20
19
20
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> B(N - 1); for (int i = 0; i < N - 1; i++) { cin >> B.at(i); } int A = B.at(0) + B.at(N - 1); for (int i = 0; i < N - 2; i++) { if (B.at(i) <= B.at(i + 1)) { A = A + B.at(i); } else if (B.at(i) > B.at(i + 1)) { A = A + B.at(i + 1); } } cout << A << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> B(N - 1); for (int i = 0; i < N - 1; i++) { cin >> B.at(i); } int A = B.at(0) + B.at(N - 2); for (int i = 0; i < N - 2; i++) { if (B.at(i) <= B.at(i + 1)) { A = A + B.at(i); } else if (B.at(i) > B.at(i + 1)) { A = A + B.at(i + 1); } } cout << A << endl; }
replace
13
14
13
14
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)
p02917
C++
Runtime Error
#include <algorithm> #include <bitset> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; #define ff(ii, nn, mm) for (int ii = nn; ii < mm; ii++) #define i64 int64_t #define tos(x) to_string(x) int main() { int n; vector<int> data(n + 1); ff(i, 1, n) { cin >> data.at(i); } data.at(0) = data.at(1); data.at(n) = data.at(n - 1); int ans = 0; ff(i, 0, n) { ans += min(data.at(i), data.at(i + 1)); } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; #define ff(ii, nn, mm) for (int ii = nn; ii < mm; ii++) #define i64 int64_t #define tos(x) to_string(x) int main() { int n; cin >> n; vector<int> data(n + 1); ff(i, 1, n) { cin >> data.at(i); } data.at(0) = data.at(1); data.at(n) = data.at(n - 1); int ans = 0; ff(i, 0, n) { ans += min(data.at(i), data.at(i + 1)); } cout << ans << endl; return 0; }
insert
16
16
16
17
0
p02917
C++
Runtime Error
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> B(N - 1, 0); for (int i = 0; i < N - 1; i++) { int Bi; cin >> Bi; B[i] = Bi; } B[N - 1] = B[N - 2]; vector<int> A(N, 0); A[0] = B[0]; int prev = B[1]; for (int i = 1; i < N; i++) { A[i] = min(B[i - 1], B[i]); } int total = 0; for (int i = 0; i < N; i++) { total += A[i]; } cout << total; return 0; }
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> B(N, 0); for (int i = 0; i < N - 1; i++) { int Bi; cin >> Bi; B[i] = Bi; } B[N - 1] = B[N - 2]; vector<int> A(N, 0); A[0] = B[0]; int prev = B[1]; for (int i = 1; i < N; i++) { A[i] = min(B[i - 1], B[i]); } int total = 0; for (int i = 0; i < N; i++) { total += A[i]; } cout << total; return 0; }
replace
9
10
9
10
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define INF 1 << 30 #define endl '\n' #define maxn 100005 #define tc printf("Case %d: ", cs) #define tcn printf("Case %d:\n", cs); #define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); typedef long long ll; const double PI = acos(-1.0); #define dbg1(x) cerr << #x << " = " << x << endl; #define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl; #define dbg3(x, y, z) \ cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " \ << z << endl; #define dbg4(w, x, y, z) \ cerr << #w << " = " << w << ", " << #x << " = " << x << ", " << #y << " = " \ << y << ", " << #z << " = " << z << endl; template <typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ", "; os << *it; } return os << "}"; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { os << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ", "; os << *it; } return os << "]"; } template <typename F, typename S> ostream &operator<<(ostream &os, const map<F, S> &v) { os << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ", "; os << it->first << " = " << it->second; } return os << "]"; } #define dbg(args...) \ do { \ cerr << #args << " : "; \ faltu(args); \ } while (0) clock_t tStart = clock(); #define timeStamp \ dbg("Execution Time: ", (double)(clock() - tStart) / CLOCKS_PER_SEC) void faltu() { cerr << endl; } template <typename T> void faltu(T a[], int n) { for (int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << endl; } template <typename T, typename... hello> void faltu(T arg, const hello &...rest) { cerr << arg << ' '; faltu(rest...); } // Program showing a policy-based data structure. #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> #include <functional> // for less #include <iostream> using namespace __gnu_pbds; using namespace std; // GNU link : https://goo.gl/WVDL6g typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; /**___________________________________________________**/ int main() { FASTIO ///* // #ifndef ONLINE_JUDGE // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // freopen("error.txt", "w", stderr); // #endif //*/ int T; // scanf("%d", &T); T = 1; for (int cs = 1; cs <= T; cs++) { int n; cin >> n; vector<int> a(n), b(n); for (int i = 0; i <= n; i++) b[i] = 1e9; for (int i = 0; i < n - 1; i++) cin >> a[i]; //, --a[i]; for (int i = 0; i < n - 1; i++) { for (int j = i; j <= i + 1 && j + 1 < n; j++) { // dbg(i, b[j], a[i]); b[j] = min(b[j], a[i]); // dbg(i, b[j], a[i]); } // cerr << "--------------\n"; } b[n - 1] = a[n - 2]; int ans = 0; for (int i = 0; i < n; i++) { // dbg(b[i]); ans += b[i]; } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 1 << 30 #define endl '\n' #define maxn 100005 #define tc printf("Case %d: ", cs) #define tcn printf("Case %d:\n", cs); #define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); typedef long long ll; const double PI = acos(-1.0); #define dbg1(x) cerr << #x << " = " << x << endl; #define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl; #define dbg3(x, y, z) \ cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " \ << z << endl; #define dbg4(w, x, y, z) \ cerr << #w << " = " << w << ", " << #x << " = " << x << ", " << #y << " = " \ << y << ", " << #z << " = " << z << endl; template <typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ", "; os << *it; } return os << "}"; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { os << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ", "; os << *it; } return os << "]"; } template <typename F, typename S> ostream &operator<<(ostream &os, const map<F, S> &v) { os << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << ", "; os << it->first << " = " << it->second; } return os << "]"; } #define dbg(args...) \ do { \ cerr << #args << " : "; \ faltu(args); \ } while (0) clock_t tStart = clock(); #define timeStamp \ dbg("Execution Time: ", (double)(clock() - tStart) / CLOCKS_PER_SEC) void faltu() { cerr << endl; } template <typename T> void faltu(T a[], int n) { for (int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << endl; } template <typename T, typename... hello> void faltu(T arg, const hello &...rest) { cerr << arg << ' '; faltu(rest...); } // Program showing a policy-based data structure. #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> #include <functional> // for less #include <iostream> using namespace __gnu_pbds; using namespace std; // GNU link : https://goo.gl/WVDL6g typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; /**___________________________________________________**/ int main() { FASTIO ///* // #ifndef ONLINE_JUDGE // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // freopen("error.txt", "w", stderr); // #endif //*/ int T; // scanf("%d", &T); T = 1; for (int cs = 1; cs <= T; cs++) { int n; cin >> n; vector<int> a(n + 10), b(n + 10); for (int i = 0; i <= n; i++) b[i] = 1e9; for (int i = 0; i < n - 1; i++) cin >> a[i]; //, --a[i]; for (int i = 0; i < n - 1; i++) { for (int j = i; j <= i + 1 && j + 1 < n; j++) { // dbg(i, b[j], a[i]); b[j] = min(b[j], a[i]); // dbg(i, b[j], a[i]); } // cerr << "--------------\n"; } b[n - 1] = a[n - 2]; int ans = 0; for (int i = 0; i < n; i++) { // dbg(b[i]); ans += b[i]; } cout << ans << endl; } return 0; }
replace
108
109
108
109
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> #define int long long #define inf 1000000007 #define pa pair<int, int> #define ll long long #define pal pair<double, double> #define ppap pair<pa, int> #define PI 3.14159265358979323846 #define paa pair<int, char> #define mp make_pair #define pb push_back #define EPS (1e-8) int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1}; using namespace std; class pa3 { public: int x; int y, z; pa3(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {} bool operator<(const pa3 &p) const { if (x != p.x) return x < p.x; if (y != p.y) return y < p.y; return z < p.z; // return x != p.x ? x<p.x: y<p.y; } bool operator>(const pa3 &p) const { if (x != p.x) return x > p.x; if (y != p.y) return y > p.y; return z > p.z; // return x != p.x ? x<p.x: y<p.y; } bool operator==(const pa3 &p) const { return x == p.x && y == p.y && z == p.z; } bool operator!=(const pa3 &p) const { return !(x == p.x && y == p.y && z == p.z); } }; class pa4 { public: int x; int y, z, w; pa4(int x = 0, int y = 0, int z = 0, int w = 0) : x(x), y(y), z(z), w(w) {} bool operator<(const pa4 &p) const { if (x != p.x) return x < p.x; if (y != p.y) return y < p.y; if (z != p.z) return z < p.z; return w < p.w; // return x != p.x ? x<p.x: y<p.y; } bool operator>(const pa4 &p) const { if (x != p.x) return x > p.x; if (y != p.y) return y > p.y; if (z != p.z) return z > p.z; return w > p.w; // return x != p.x ? x<p.x: y<p.y; } bool operator==(const pa4 &p) const { return x == p.x && y == p.y && z == p.z && w == p.w; } }; class pa2 { public: int x, y; pa2(int x = 0, int y = 0) : x(x), y(y) {} pa2 operator+(pa2 p) { return pa2(x + p.x, y + p.y); } pa2 operator-(pa2 p) { return pa2(x - p.x, y - p.y); } bool operator<(const pa2 &p) const { return y != p.y ? y < p.y : x < p.x; } bool operator>(const pa2 &p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const pa2 &p) const { return abs(x - p.x) == 0 && abs(y - p.y) == 0; } bool operator!=(const pa2 &p) const { return !(abs(x - p.x) == 0 && abs(y - p.y) == 0); } }; string itos(int i) { ostringstream s; s << i; return s.str(); } int gcd(int v, int b) { if (v > b) return gcd(b, v); if (v == b) return b; if (b % v == 0) return v; return gcd(v, b % v); } int mod; int extgcd(int a, int b, int &x, int &y) { if (b == 0) { x = 1; y = 0; return a; } int d = extgcd(b, a % b, y, x); y -= a / b * x; return d; } pa operator+(const pa &l, const pa &r) { return {l.first + r.first, l.second + r.second}; } pa operator-(const pa &l, const pa &r) { return {l.first - r.first, l.second - r.second}; } int pr[1001010]; int inv[1001010]; int beki(int wa, int rr, int warukazu) { if (rr == 0) return 1 % warukazu; if (rr == 1) return wa % warukazu; wa %= warukazu; if (rr % 2 == 1) return ((ll)beki(wa, rr - 1, warukazu) * (ll)wa) % warukazu; ll zx = beki(wa, rr / 2, warukazu); return (zx * zx) % warukazu; } int comb(int nn, int rr) { if (rr < 0 || rr > nn || nn < 0) return 0; int r = pr[nn] * inv[rr]; r %= mod; r *= inv[nn - rr]; r %= mod; return r; } void gya(int ert) { pr[0] = 1; for (int i = 1; i <= ert; i++) { pr[i] = (pr[i - 1] * i) % mod; } inv[ert] = beki(pr[ert], mod - 2, mod); for (int i = ert - 1; i >= 0; i--) { inv[i] = inv[i + 1] * (i + 1) % mod; } } // cin.tie(0); // ios::sync_with_stdio(false); // priority_queue<pa3,vector<pa3>,greater<pa3>> pq; // sort(ve.begin(),ve.end(),greater<int>()); // mt19937(clock_per_sec); // mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) ; //----------------kokomade tenpure------------ signed main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<int> ve(n, inf); for (int i = 0; i < n; i++) { int y; cin >> y; ve[i] = min(ve[i], y); ve[i + 1] = min(ve[1 + i], y); } int ans = 0; for (auto v : ve) ans += v; cout << ans << endl; return 0; }
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> #define int long long #define inf 1000000007 #define pa pair<int, int> #define ll long long #define pal pair<double, double> #define ppap pair<pa, int> #define PI 3.14159265358979323846 #define paa pair<int, char> #define mp make_pair #define pb push_back #define EPS (1e-8) int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1}; using namespace std; class pa3 { public: int x; int y, z; pa3(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {} bool operator<(const pa3 &p) const { if (x != p.x) return x < p.x; if (y != p.y) return y < p.y; return z < p.z; // return x != p.x ? x<p.x: y<p.y; } bool operator>(const pa3 &p) const { if (x != p.x) return x > p.x; if (y != p.y) return y > p.y; return z > p.z; // return x != p.x ? x<p.x: y<p.y; } bool operator==(const pa3 &p) const { return x == p.x && y == p.y && z == p.z; } bool operator!=(const pa3 &p) const { return !(x == p.x && y == p.y && z == p.z); } }; class pa4 { public: int x; int y, z, w; pa4(int x = 0, int y = 0, int z = 0, int w = 0) : x(x), y(y), z(z), w(w) {} bool operator<(const pa4 &p) const { if (x != p.x) return x < p.x; if (y != p.y) return y < p.y; if (z != p.z) return z < p.z; return w < p.w; // return x != p.x ? x<p.x: y<p.y; } bool operator>(const pa4 &p) const { if (x != p.x) return x > p.x; if (y != p.y) return y > p.y; if (z != p.z) return z > p.z; return w > p.w; // return x != p.x ? x<p.x: y<p.y; } bool operator==(const pa4 &p) const { return x == p.x && y == p.y && z == p.z && w == p.w; } }; class pa2 { public: int x, y; pa2(int x = 0, int y = 0) : x(x), y(y) {} pa2 operator+(pa2 p) { return pa2(x + p.x, y + p.y); } pa2 operator-(pa2 p) { return pa2(x - p.x, y - p.y); } bool operator<(const pa2 &p) const { return y != p.y ? y < p.y : x < p.x; } bool operator>(const pa2 &p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const pa2 &p) const { return abs(x - p.x) == 0 && abs(y - p.y) == 0; } bool operator!=(const pa2 &p) const { return !(abs(x - p.x) == 0 && abs(y - p.y) == 0); } }; string itos(int i) { ostringstream s; s << i; return s.str(); } int gcd(int v, int b) { if (v > b) return gcd(b, v); if (v == b) return b; if (b % v == 0) return v; return gcd(v, b % v); } int mod; int extgcd(int a, int b, int &x, int &y) { if (b == 0) { x = 1; y = 0; return a; } int d = extgcd(b, a % b, y, x); y -= a / b * x; return d; } pa operator+(const pa &l, const pa &r) { return {l.first + r.first, l.second + r.second}; } pa operator-(const pa &l, const pa &r) { return {l.first - r.first, l.second - r.second}; } int pr[1001010]; int inv[1001010]; int beki(int wa, int rr, int warukazu) { if (rr == 0) return 1 % warukazu; if (rr == 1) return wa % warukazu; wa %= warukazu; if (rr % 2 == 1) return ((ll)beki(wa, rr - 1, warukazu) * (ll)wa) % warukazu; ll zx = beki(wa, rr / 2, warukazu); return (zx * zx) % warukazu; } int comb(int nn, int rr) { if (rr < 0 || rr > nn || nn < 0) return 0; int r = pr[nn] * inv[rr]; r %= mod; r *= inv[nn - rr]; r %= mod; return r; } void gya(int ert) { pr[0] = 1; for (int i = 1; i <= ert; i++) { pr[i] = (pr[i - 1] * i) % mod; } inv[ert] = beki(pr[ert], mod - 2, mod); for (int i = ert - 1; i >= 0; i--) { inv[i] = inv[i + 1] * (i + 1) % mod; } } // cin.tie(0); // ios::sync_with_stdio(false); // priority_queue<pa3,vector<pa3>,greater<pa3>> pq; // sort(ve.begin(),ve.end(),greater<int>()); // mt19937(clock_per_sec); // mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()) ; //----------------kokomade tenpure------------ signed main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<int> ve(n, inf); for (int i = 0; i < n - 1; i++) { int y; cin >> y; ve[i] = min(ve[i], y); ve[i + 1] = min(ve[1 + i], y); } int ans = 0; for (auto v : ve) ans += v; cout << ans << endl; return 0; }
replace
180
181
180
181
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i) #define rreps(i, n) for (int i = ((int)(n)); i > 0; --i) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define SZ(x) ((int)(x).size()) #define pb push_back #define optimize_cin() \ cin.tie(0); \ ios::sync_with_stdio(false) #define debug(x) std::cerr << #x << ": " << (x) << endl; using namespace std; using lint = long long; template <class T> using grid = vector<vector<T>>; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } static const lint MOD = (lint)1e9 + 7; lint Sum(vector<lint> nums) { lint sum = 0; rep(i, SZ(nums)) { sum += nums[i]; } return sum; } int main() { int N; cin >> N; vector<lint> B(N - 1); rep(i, N - 1) { cin >> B[i]; } vector<lint> A(N); A[0] = B[0]; for (int i = N - 1; i >= 0; --i) { A[i - 1] = min(B[i - 1], B[i]); } A[N - 1] = B[N - 2]; rep(i, N) { cerr << A[i] << " "; } cerr << endl; lint sum = Sum(A); cout << sum << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i) #define rreps(i, n) for (int i = ((int)(n)); i > 0; --i) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define SZ(x) ((int)(x).size()) #define pb push_back #define optimize_cin() \ cin.tie(0); \ ios::sync_with_stdio(false) #define debug(x) std::cerr << #x << ": " << (x) << endl; using namespace std; using lint = long long; template <class T> using grid = vector<vector<T>>; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } static const lint MOD = (lint)1e9 + 7; lint Sum(vector<lint> nums) { lint sum = 0; rep(i, SZ(nums)) { sum += nums[i]; } return sum; } int main() { int N; cin >> N; vector<lint> B(N - 1); rep(i, N - 1) { cin >> B[i]; } vector<lint> A(N); A[0] = B[0]; for (int i = N - 1; i > 0; --i) { A[i] = min(B[i - 1], B[i]); } A[N - 1] = B[N - 2]; rep(i, N) { cerr << A[i] << " "; } cerr << endl; lint sum = Sum(A); cout << sum << endl; return 0; }
replace
46
48
46
48
-6
2 0 5 munmap_chunk(): invalid pointer
p02917
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long int ll; typedef vector<ll> vll; typedef vector<vll> vvll; const ll MOD = 1000000007; int main() { ll n; cin >> n; vll a(n), b(n + 1); rep(i, n - 1) cin >> b[i]; a[0] = b[0]; b[n - 1] = b[n - 2]; rep(i, n) a[i + 1] = min(b[i], b[i + 1]); ll ans = 0; rep(i, n) ans += a[i]; cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long int ll; typedef vector<ll> vll; typedef vector<vll> vvll; const ll MOD = 1000000007; int main() { ll n; cin >> n; vll a(n + 10, 0), b(n + 10, 0); rep(i, n - 1) cin >> b[i]; a[0] = b[0]; b[n - 1] = b[n - 2]; rep(i, n) a[i + 1] = min(b[i], b[i + 1]); ll ans = 0; rep(i, n) ans += a[i]; cout << ans << endl; }
replace
15
16
15
16
-6
free(): invalid pointer
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define inf 1072114514 #define llinf 4154118101919364364 #define mod 1000000007 #define pi 3.1415926535897932384 int round(int a, int b) { if ((a % b) * 2 >= b) { return (a / b) + 1; } return a / b; } int gcd(int a, int b) { int c; while (b != 0) { c = a % b; a = b; b = c; } return a; } // 最大公約数 int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a * b; } // 最小公倍数 int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; } return r; } // コンビネーション int nHr(int a, int b) { return nCr(a + b - 1, b); } // 重複組み合わせ int fact(int a) { int i, r = 1; for (i = 1; i <= a; i++) { r *= i; } return r; } // 階乗 int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; } return r; } // a~bまでの階乗 int dsum(int x) { int r = 0; while (x) { r += (x % 10); x /= 10; } return r; } // 数字の各位の和 int dsumb(int x, int b) { int r = 0; while (x) { r += (x % b); x /= b; } return r; } // b進数の各位の和? int sankaku(int x) { return ((1 + x) * x) / 2; } // 三角数 xまでの和 // 以下long long ver long long llmax(long long a, long long b) { if (a > b) { return a; } return b; } long long llmin(long long a, long long b) { if (a < b) { return a; } return b; } long long llzt(long long a, long long b) { return llmax(a, b) - llmin(a, b); } long long llround(long long a, long long b) { if ((a % b) * 2 >= b) { return (a / b) + 1; } return a / b; } long long llceil(long long a, long long b) { if (a % b == 0) { return a / b; } return (a / b) + 1; } long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a % b; a = b; b = c; } return a; } long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a * b; } long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; } return r; } long long llnHr(long long a, long long b) { return llnCr(a + b - 1, b); } long long llfact(long long a) { long long i, r = 1; for (i = 1; i <= a; i++) { r *= i; } return r; } long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; } return r; } long long lldsum(long long x) { long long r = 0; while (x) { r += (x % 10); x /= 10; } return r; } long long lldsumb(long long x, long long b) { long long r = 0; while (x) { r += (x % b); x /= b; } return r; } long long llsankaku(long long x) { return ((1 + x) * x) / 2; } // double double dbmax(double a, double b) { if (a > b) { return a; } return b; } double dbmin(double a, double b) { if (a < b) { return a; } return b; } double dbzt(double a, double b) { return dbmax(a, b) - dbmin(a, b); } typedef pair<int, int> ii; typedef long long ll; typedef vector<ll> vll; typedef pair<ll, ll> pll; #define forr(i, a, b) \ ; \ for (int i = (a); i < (b); i++) #define clean(arr, val) memset(arr, val, sizeof(arr)) #define forn(i, n) forr(i, 0, n) #define PB push_back typedef vector<int> vi; typedef vector<ii> vii; typedef vector<pll> vpll; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; bool is_prime(int x) { if (x <= 1) return false; for (int i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } string alpha = "abcdefghijklmnopqrstuvwxyz"; /*CODE START HERE*/ int main() { int n; cin >> n; vector<int> b(n - 1); forn(i, n - 1) { cin >> b.at(i); } int sum = b.at(0) + b.at(n - 1); forr(i, 1, n - 1) { sum += min(b.at(i), b.at(i - 1)); } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; #define inf 1072114514 #define llinf 4154118101919364364 #define mod 1000000007 #define pi 3.1415926535897932384 int round(int a, int b) { if ((a % b) * 2 >= b) { return (a / b) + 1; } return a / b; } int gcd(int a, int b) { int c; while (b != 0) { c = a % b; a = b; b = c; } return a; } // 最大公約数 int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a * b; } // 最小公倍数 int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; } return r; } // コンビネーション int nHr(int a, int b) { return nCr(a + b - 1, b); } // 重複組み合わせ int fact(int a) { int i, r = 1; for (i = 1; i <= a; i++) { r *= i; } return r; } // 階乗 int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; } return r; } // a~bまでの階乗 int dsum(int x) { int r = 0; while (x) { r += (x % 10); x /= 10; } return r; } // 数字の各位の和 int dsumb(int x, int b) { int r = 0; while (x) { r += (x % b); x /= b; } return r; } // b進数の各位の和? int sankaku(int x) { return ((1 + x) * x) / 2; } // 三角数 xまでの和 // 以下long long ver long long llmax(long long a, long long b) { if (a > b) { return a; } return b; } long long llmin(long long a, long long b) { if (a < b) { return a; } return b; } long long llzt(long long a, long long b) { return llmax(a, b) - llmin(a, b); } long long llround(long long a, long long b) { if ((a % b) * 2 >= b) { return (a / b) + 1; } return a / b; } long long llceil(long long a, long long b) { if (a % b == 0) { return a / b; } return (a / b) + 1; } long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a % b; a = b; b = c; } return a; } long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a * b; } long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; } return r; } long long llnHr(long long a, long long b) { return llnCr(a + b - 1, b); } long long llfact(long long a) { long long i, r = 1; for (i = 1; i <= a; i++) { r *= i; } return r; } long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; } return r; } long long lldsum(long long x) { long long r = 0; while (x) { r += (x % 10); x /= 10; } return r; } long long lldsumb(long long x, long long b) { long long r = 0; while (x) { r += (x % b); x /= b; } return r; } long long llsankaku(long long x) { return ((1 + x) * x) / 2; } // double double dbmax(double a, double b) { if (a > b) { return a; } return b; } double dbmin(double a, double b) { if (a < b) { return a; } return b; } double dbzt(double a, double b) { return dbmax(a, b) - dbmin(a, b); } typedef pair<int, int> ii; typedef long long ll; typedef vector<ll> vll; typedef pair<ll, ll> pll; #define forr(i, a, b) \ ; \ for (int i = (a); i < (b); i++) #define clean(arr, val) memset(arr, val, sizeof(arr)) #define forn(i, n) forr(i, 0, n) #define PB push_back typedef vector<int> vi; typedef vector<ii> vii; typedef vector<pll> vpll; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; bool is_prime(int x) { if (x <= 1) return false; for (int i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } string alpha = "abcdefghijklmnopqrstuvwxyz"; /*CODE START HERE*/ int main() { int n; cin >> n; vector<int> b(n - 1); forn(i, n - 1) { cin >> b.at(i); } int sum = b.at(0) + b.at(n - 2); forr(i, 1, n - 1) { sum += min(b.at(i), b.at(i - 1)); } cout << sum << endl; }
replace
197
198
197
198
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)
p02917
Python
Runtime Error
n = int(input()) B = list(map(int, input().split())) ans = 0 ans += B[0] for i in range(n - 2): if B[i] > B[i + 1]: ans += B[i + i] else: ans += B[i] ans += B[-1] print(ans)
n = int(input()) B = list(map(int, input().split())) ans = 0 ans += B[0] for i in range(n - 2): if B[i] > B[i + 1]: ans += B[i + 1] else: ans += B[i] ans += B[-1] print(ans)
replace
6
7
6
7
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int b[1000010]; long long ans = 0; int main() { int n; scanf("%d", n); for (int i = 1; i < n; i++) scanf("%d", &b[i]); b[0] = b[n] = 0x7f7f7f7f; for (int i = 1; i <= n; i++) ans += min(b[i - 1], b[i]); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int b[1000010]; long long ans = 0; int main() { int n; scanf("%d", &n); for (int i = 1; i < n; i++) scanf("%d", &b[i]); b[0] = b[n] = 0x7f7f7f7f; for (int i = 1; i <= n; i++) ans += min(b[i - 1], b[i]); cout << ans << endl; return 0; }
replace
9
10
9
10
-11
p02917
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; int main(void) { int numbers_count; vector<int> limit_values; cin >> numbers_count; for (int i = 0; i < numbers_count - 1; i++) { int lv; cin >> lv; limit_values.push_back(lv); } int sum = limit_values[0]; for (int i = 1; i < numbers_count - 1; i--) { sum += min(limit_values[i - 1], limit_values[i]); } sum += limit_values.back(); cout << sum << endl; return 0; }
#include <iostream> #include <vector> using namespace std; int main(void) { int numbers_count; vector<int> limit_values; cin >> numbers_count; for (int i = 0; i < numbers_count - 1; i++) { int lv; cin >> lv; limit_values.push_back(lv); } int sum = limit_values[0]; for (int i = 1; i < numbers_count - 1; i++) { sum += min(limit_values[i - 1], limit_values[i]); } sum += limit_values.back(); cout << sum << endl; return 0; }
replace
18
19
18
19
TLE
p02917
Python
Runtime Error
N = int(input()) B = [int(i) for i in input().split()][::-1] # N = 6 # B = [0, 153, 10, 10, 23] # N = 3 # B = [2, 5] ans = 0 ans += B[1] # A[1] for i in range(0, N - 1): ans += min(B[i - 1], B[i]) print(ans)
N = int(input()) B = [int(i) for i in input().split()][::-1] ret = B[0] + B[N - 2] for i in range(1, N - 1): ret += min(B[i - 1], B[i]) print(ret)
replace
2
11
2
6
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n), b(n - 1); for (int i = 0; i < n - 1; i++) { cin >> b[i]; } a[0] = b[0]; a[n] = b[n - 1]; for (int i = 0; i < n - 1; i++) { a[i + 1] = min(b[i], b[i + 1]); } int sum = 0; for (int i = 0; i < n; i++) { sum += a[i]; } cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n), b(n - 1); for (int i = 0; i < n - 1; i++) { cin >> b[i]; } a[0] = b[0]; a[n - 1] = b[n - 2]; for (int i = 0; i < n - 2; i++) { a[i + 1] = min(b[i], b[i + 1]); } int sum = 0; for (int i = 0; i < n; i++) { sum += a[i]; } cout << sum << endl; return 0; }
replace
13
15
13
15
0
p02917
C++
Runtime Error
#include <iostream> int main() { int i, N, B[20]; scanf("%d", &N); for (i = 0; i <= N - 2; i++) { scanf("%d", &B[i]); } if (N == 2) { printf("%d", B[0] * 2); return 0; } int sum = B[0]; for (i = 0; i <= N - 3; i++) { if (B[i] >= B[i + 1]) { sum = sum + B[i + 1]; } else { sum = sum + B[i]; } } sum = sum + B[N - 2]; printf("%d", sum); }
#include <iostream> int main() { int i, N, B[100]; scanf("%d", &N); for (i = 0; i <= N - 2; i++) { scanf("%d", &B[i]); } if (N == 2) { printf("%d", B[0] * 2); return 0; } int sum = B[0]; for (i = 0; i <= N - 3; i++) { if (B[i] >= B[i + 1]) { sum = sum + B[i + 1]; } else { sum = sum + B[i]; } } sum = sum + B[N - 2]; printf("%d", sum); }
replace
3
4
3
4
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<long> B(N - 1); long sum = 0; bool flag = true; for (int i = 0; i < N - 1; i++) { cin >> B.at(i); } for (int i = 0; i < N - 1; i++) { if (i == 0) { sum += B.at(i); if (B.at(i) > B.at(i + 1)) { sum += B.at(i + 1); } else { sum += B.at(i); } } else if (i == N - 2) sum += B.at(i); else { if (B.at(i) > B.at(i + 1)) { sum += B.at(i + 1); flag = true; } else if (B.at(i - 1) == B.at(i)) { sum += B.at(i); flag = false; } else { // else if(B.at(i) < B.at(i+1)){ sum += B.at(i); flag = true; } } } cout << sum; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<long> B(N - 1); long sum = 0; bool flag = true; for (int i = 0; i < N - 1; i++) { cin >> B.at(i); } for (int i = 0; i < N - 1; i++) { if (i == 0) { sum += B.at(i); if (N > 2) { if (B.at(i) > B.at(i + 1)) { sum += B.at(i + 1); } else { sum += B.at(i); } } else { sum += B.at(i); } } else if (i == N - 2) sum += B.at(i); else { if (B.at(i) > B.at(i + 1)) { sum += B.at(i + 1); flag = true; } else if (B.at(i - 1) == B.at(i)) { sum += B.at(i); flag = false; } else { // else if(B.at(i) < B.at(i+1)){ sum += B.at(i); flag = true; } } } cout << sum; return 0; }
replace
19
21
19
25
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // ----------------------R00TDADA------------------------------ #define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++) #define nrep(i, a, b) for (__typeof((b)) i = (b); i > (a); i--) #define all(a) (a).begin(), (a).end() #define ff first #define ss second #define ppi pair<int, int> #define pppi pair<ppi, int> #define vi vector<int> #define vii vector<ppi> #define viii vector<pppi> #define vs vector<string> #define pb push_back #define mp make_pair #define sz(x) (int)x.size() #define M_PI 3.14159265358979323846 #define rootdada ios_base::sync_with_stdio(false) #define int long long signed main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif rootdada; int n; cin >> n; int a[n - 1]; rep(i, 0, n - 1) cin >> a[i]; int b[n]; b[0] = a[0]; rep(i, 0, n - 1) { if (a[i] == max(a[i], b[i])) b[i + 1] = a[i]; else { b[i + 1] = a[i]; b[i] = a[i]; } } int sum = 0; rep(i, 0, n) sum += b[i]; cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; // ----------------------R00TDADA------------------------------ #define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++) #define nrep(i, a, b) for (__typeof((b)) i = (b); i > (a); i--) #define all(a) (a).begin(), (a).end() #define ff first #define ss second #define ppi pair<int, int> #define pppi pair<ppi, int> #define vi vector<int> #define vii vector<ppi> #define viii vector<pppi> #define vs vector<string> #define pb push_back #define mp make_pair #define sz(x) (int)x.size() #define M_PI 3.14159265358979323846 #define rootdada ios_base::sync_with_stdio(false) #define int long long signed main() { rootdada; int n; cin >> n; int a[n - 1]; rep(i, 0, n - 1) cin >> a[i]; int b[n]; b[0] = a[0]; rep(i, 0, n - 1) { if (a[i] == max(a[i], b[i])) b[i + 1] = a[i]; else { b[i + 1] = a[i]; b[i] = a[i]; } } int sum = 0; rep(i, 0, n) sum += b[i]; cout << sum << endl; }
replace
22
28
22
23
-11
p02917
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; vector<int> b(n - 1); rep(i, n - 1) cin >> b[i]; vector<int> a(n); rep(i, n) { if (i == 0) a[i] = b[i]; else if (i == n - 1) a[i] = b[i - 1]; else { if (b[i] - b[i - 1] >= 0) a[i] = b[i - 1]; else a[i] = b[i]; } } int ans = 0; rep(i, n) ans += a[i]; 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>; int main() { int n; cin >> n; vector<int> b(n - 1); rep(i, n - 1) cin >> b[i]; vector<int> a(n); rep(i, n) { if (i == 0) a[i] = b[i]; else if (i == n - 1) a[i] = b[i - 1]; else { if (b[i] - b[i - 1] >= 0) a[i] = b[i - 1]; else a[i] = b[i]; } } int ans = 0; rep(i, n) ans += a[i]; cout << ans << endl; return 0; }
insert
8
8
8
9
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; vector<int> b(n); for (int i = 0; i < n - 1; i++) cin >> b[i]; b[n] = 0; vector<int> a(n); a[0] = b[0]; for (int i = 1; i < n - 1; i++) { if (b[i] >= b[i - 1]) a[i] = b[i - 1]; else a[i] = b[i]; } a[n - 1] = b[n - 2]; int sum = 0; for (int i = 0; i < n; i++) { sum += a[i]; } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; cin >> n; vector<int> b(n); for (int i = 0; i < n - 1; i++) cin >> b[i]; b[n - 1] = 0; vector<int> a(n); a[0] = b[0]; for (int i = 1; i < n - 1; i++) { if (b[i] >= b[i - 1]) a[i] = b[i - 1]; else a[i] = b[i]; } a[n - 1] = b[n - 2]; int sum = 0; for (int i = 0; i < n; i++) { sum += a[i]; } cout << sum << endl; }
replace
10
11
10
11
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, sum; sum = 0; vector<int> b(n - 1); vector<int> a(n); for (int i = 0; i < n - 1; i++) { cin >> b.at(i); } a.at(0) = b.at(0); a.at(n - 1) = b.at(n - 2); for (int i = 1; i < n - 1; i++) { a.at(i) = min(b.at(i - 1), b.at(i)); } for (int i = 0; i < n; i++) { sum += a.at(i); } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, sum; sum = 0; cin >> n; vector<int> b(n - 1); vector<int> a(n); for (int i = 0; i < n - 1; i++) { cin >> b.at(i); } a.at(0) = b.at(0); a.at(n - 1) = b.at(n - 2); for (int i = 1; i < n - 1; i++) { a.at(i) = min(b.at(i - 1), b.at(i)); } for (int i = 0; i < n; i++) { sum += a.at(i); } cout << sum << endl; }
insert
6
6
6
7
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define inf INT_MAX #define INF LLONG_MAX #define ll long long #define ull unsigned long long #define M (int)(1e9 + 7) #define P pair<int, int> #define PLL pair<ll, ll> #define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++) #define RFOR(i, m, n) for (int i = (int)m; i >= (int)n; i--) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) RFOR(i, n, 0) #define all(a) a.begin(), a.end() #define IN(a, n) \ rep(i, n) { cin >> a[i]; } const int vx[4] = {0, 1, 0, -1}; const int vy[4] = {1, 0, -1, 0}; #define PI 3.14159265 #define F first #define S second #define PB push_back #define EB emplace_back #define int ll #define vi vector<int> signed main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vi b(n - 1); rep(i, n - 1) { cin >> b[i]; } vi a(n - 1, -inf); a[0] = b[0]; a[1] = b[0]; FOR(i, 1, n - 1) { if (a[i] > b[i]) a[i] = b[i]; a[i + 1] = b[i]; } int ans = 0; rep(i, n) { ans += a[i]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define inf INT_MAX #define INF LLONG_MAX #define ll long long #define ull unsigned long long #define M (int)(1e9 + 7) #define P pair<int, int> #define PLL pair<ll, ll> #define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++) #define RFOR(i, m, n) for (int i = (int)m; i >= (int)n; i--) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) RFOR(i, n, 0) #define all(a) a.begin(), a.end() #define IN(a, n) \ rep(i, n) { cin >> a[i]; } const int vx[4] = {0, 1, 0, -1}; const int vy[4] = {1, 0, -1, 0}; #define PI 3.14159265 #define F first #define S second #define PB push_back #define EB emplace_back #define int ll #define vi vector<int> signed main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vi b(n - 1); rep(i, n - 1) { cin >> b[i]; } vi a(n, -inf); a[0] = b[0]; a[1] = b[0]; FOR(i, 1, n - 1) { if (a[i] > b[i]) a[i] = b[i]; a[i + 1] = b[i]; } int ans = 0; rep(i, n) { ans += a[i]; } cout << ans << endl; }
replace
36
37
36
37
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif int n; cin >> n; n--; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int sum = 0; for (int i = n - 1; i >= 0; i--) { // cout<<a[i]<<endl; if (i + 1 < n) { if (a[i] > a[i + 1]) { sum += a[i + 1]; continue; } } sum += a[i]; } cout << sum + a[0]; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { std::ios::sync_with_stdio(false); int n; cin >> n; n--; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int sum = 0; for (int i = n - 1; i >= 0; i--) { // cout<<a[i]<<endl; if (i + 1 < n) { if (a[i] > a[i + 1]) { sum += a[i + 1]; continue; } } sum += a[i]; } cout << sum + a[0]; return 0; }
replace
6
9
6
7
-11
p02917
C++
Runtime Error
#include <bits/stdc++.h> #define ff first #define ss second #define MAX 10005 #define endl "\n" #define mp make_pair #define pb push_back #define int long long #define MOD 1000000007 #define INF 0x3f3f3f3f #define vi vector<int> #define mii map<int, int> #define pii pair<int, int> #define len(x) (x.size()) #define all(a) a.begin(), a.end() #define f(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) for (int i = 0; i < a; i++) #define debug(x) cerr << #x << ": " << x << endl #define T \ int tc; \ cin >> tc; \ for (int t = 1; t <= tc; t++) #define set_arr(arr, i) memset(arr, i, sizeof(arr)) #define trace1(x) cerr << #x << ": " << x << endl; #define trace2(x, y) \ cerr << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl; using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; cin >> n; vi b(n - 1); rep(i, n - 1) { cin >> b[i]; } vi a(n); a[0] = b[0]; f(i, 1, n - 1) { a[i] = min(b[i], b[i - 1]); } a[n - 1] = max(b[n - 2], a[n - 1]); int ans = 0; rep(i, n) ans += a[i]; cout << ans; return 0; }
#include <bits/stdc++.h> #define ff first #define ss second #define MAX 10005 #define endl "\n" #define mp make_pair #define pb push_back #define int long long #define MOD 1000000007 #define INF 0x3f3f3f3f #define vi vector<int> #define mii map<int, int> #define pii pair<int, int> #define len(x) (x.size()) #define all(a) a.begin(), a.end() #define f(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) for (int i = 0; i < a; i++) #define debug(x) cerr << #x << ": " << x << endl #define T \ int tc; \ cin >> tc; \ for (int t = 1; t <= tc; t++) #define set_arr(arr, i) memset(arr, i, sizeof(arr)) #define trace1(x) cerr << #x << ": " << x << endl; #define trace2(x, y) \ cerr << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl; using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vi b(n - 1); rep(i, n - 1) { cin >> b[i]; } vi a(n); a[0] = b[0]; f(i, 1, n - 1) { a[i] = min(b[i], b[i - 1]); } a[n - 1] = max(b[n - 2], a[n - 1]); int ans = 0; rep(i, n) ans += a[i]; cout << ans; return 0; }
replace
45
49
45
46
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; vector<int> b(n - 1); cin >> n; for (int i = 0; i < n - 1; ++i) cin >> b[i]; vector<int> a(n); a[0] = b[0]; a[n - 1] = b[n - 2]; for (int i = 1; i < n - 1; ++i) { a[i] = min(b[i - 1], b[i]); } int sum = 0; for (int i = 0; i < n; ++i) { sum += a[i]; } cout << sum << endl; for (int i = 0; i < n; ++i) cout << a[i] << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; vector<int> b(n - 1); cin >> n; for (int i = 0; i < n - 1; ++i) cin >> b[i]; vector<int> a(n); a[0] = b[0]; a[n - 1] = b[n - 2]; for (int i = 1; i < n - 1; ++i) { a[i] = min(b[i - 1], b[i]); } int sum = 0; for (int i = 0; i < n; ++i) { sum += a[i]; } cout << sum << endl; }
delete
19
21
19
19
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> b(n - 1); vector<int> a(n); for (int i = 0; i < n - 1; i++) cin >> b[i]; for (int i = n - 1; i >= 0; i++) { if (i == 0) { a[i] = b[i]; } else if (i == n - 1) { a[i] = b[i - 1]; } else { a[i] = min(b[i], b[i - 1]); } } int sum = 0; for (int it : a) sum += it; cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> b(n - 1); vector<int> a(n); for (int i = 0; i < n - 1; i++) cin >> b[i]; for (int i = n - 1; i >= 0; i--) { if (i == 0) { a[i] = b[i]; } else if (i == n - 1) { a[i] = b[i - 1]; } else { a[i] = min(b[i], b[i - 1]); } } int sum = 0; for (int it : a) sum += it; cout << sum << endl; return 0; }
replace
11
12
11
12
-11
p02917
C++
Runtime Error
#include <iostream> #include <math.h> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> a(n); vector<int> b(n - 1); for (int i = 0; i < n; i++) { cin >> b[i]; } a[0] = b[0]; a[n] = b[n - 1]; int count = a[0] + a[n]; for (int j = 1; j < n; j++) { a[j] = min(b[j - 1], b[j]); count += a[j]; } cout << count << endl; return 0; }
#include <iostream> #include <math.h> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> a(n); vector<int> b(n - 1); for (int i = 0; i < n; i++) { cin >> b[i]; } a[0] = b[0]; a[n - 1] = b[n - 2]; int count = a[n - 1] + a[0]; for (int j = 1; j < n - 1; j++) { a[j] = min(b[j - 1], b[j]); count += a[j]; } cout << count << endl; return 0; }
replace
14
17
14
17
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = 1000000007; const double PI = 3.14159265358979; const ll INF = pow(10, 18); typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vl> vvl; #define FOR(i, a, b) for (ll i = a; i < b; i++) #define rep(i, n) FOR(i, 0, n) string abc = "abcdefghijklmnopqrstuvwxyz"; string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int main() { ll n; vl b(n - 1); rep(i, n - 1) { cin >> b[i]; } ll ans = b[0] + b[n - 2]; rep(i, n - 2) { ans += min(b[i], b[i + 1]); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = 1000000007; const double PI = 3.14159265358979; const ll INF = pow(10, 18); typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vl> vvl; #define FOR(i, a, b) for (ll i = a; i < b; i++) #define rep(i, n) FOR(i, 0, n) string abc = "abcdefghijklmnopqrstuvwxyz"; string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int main() { ll n; cin >> n; vl b(n - 1); rep(i, n - 1) { cin >> b[i]; } ll ans = b[0] + b[n - 2]; rep(i, n - 2) { ans += min(b[i], b[i + 1]); } cout << ans << endl; }
insert
16
16
16
17
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, b[n - 1], a[n]; int c = 0; cin >> n; for (int i = 0; i < n - 1; i++) { cin >> b[i]; } a[0] = b[0]; a[n - 1] = b[n - 2]; for (int i = 0; i < n - 2; i++) { a[i + 1] = min(b[i], b[i + 1]); } for (int i = 0; i < n; i++) { c += a[i]; } cout << c; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long int n, b[n - 1], a[n]; long int c = 0; cin >> n; for (int i = 0; i < n - 1; i++) { cin >> b[i]; } a[0] = b[0]; a[n - 1] = b[n - 2]; for (int i = 0; i < n - 2; i++) { a[i + 1] = min(b[i], b[i + 1]); } for (int i = 0; i < n; i++) { c += a[i]; } cout << c; return 0; }
replace
3
5
3
5
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repm(i, m, n) for (int i = (m); i < (int)(n); i++) #define repr(i, n) for (int i = (n); i > 0; i--) #define all(vec) vec.begin(), vec.end() using namespace std; int main() { int a; // string a; cin >> a; vector<int> seq(a - 1); rep(i, a - 1) cin >> seq[i]; int ans = 0; // string ans = "Yes"; // string ans = "No"; // string ans = "YES"; // string ans = "NO"; int cnt = 0; ans = seq[0]; rep(i, a - 2) a += min(seq[i + 1], seq[i]); ans += seq[a - 2]; cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repm(i, m, n) for (int i = (m); i < (int)(n); i++) #define repr(i, n) for (int i = (n); i > 0; i--) #define all(vec) vec.begin(), vec.end() using namespace std; int main() { int a; // string a; cin >> a; vector<int> seq(a - 1); rep(i, a - 1) cin >> seq[i]; int ans = 0; // string ans = "Yes"; // string ans = "No"; // string ans = "YES"; // string ans = "NO"; int cnt = 0; vector<int> w(a); w[0] = seq[0]; repm(i, 1, a - 1) w[i] = min(seq[i], seq[i - 1]); w[a - 1] = seq[a - 2]; rep(i, a) ans += w[i]; cout << ans << endl; }
replace
20
23
20
25
0
p02917
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> B(N); vector<int> A(N); for (int i = 0; i < N; i++) cin >> B[i]; for (int i = 0; i < N; i++) { A[i] = B[i]; if (B[i] < B[i + 1]) A[i + 1] = B[i]; else A[i + 1] = B[i + 1]; } int ans = 0; for (int i = 0; i < N; i++) ans += A[i]; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> B(N); vector<int> A(N); for (int i = 0; i < N; i++) cin >> B[i]; A[0] = B[0]; A[N - 1] = B[N - 2]; for (int i = 1; i < N - 1; i++) { A[i] = min(B[i], B[i - 1]); } int ans = 0; for (int i = 0; i < N; i++) ans += A[i]; cout << ans; return 0; }
replace
10
17
10
14
0
p02918
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i)) using ll = long long; using namespace std; int main() { int N, K; cin >> N >> K; string S; cin >> S; vector<pair<char, int>> T; S += "X"; char prev = S[0]; int num = 1; for (int i = 1; i < S.size(); ++i) { if (prev == S[i]) { num++; } else { T.emplace_back(prev, num); num = 1; prev = S[i]; } } if (T.size() % 2 == 0) T.emplace_back('X', 0); vector<pair<int, int>> p; for (int i = 1; i < T.size() - 1; i += 2) { int num = T[i - 1].second + T[i].second + T[i + 1].second; p.emplace_back(num, i); } // for (auto tmp : p) { // cout << tmp.first << tmp.second << " "; // } // cout << endl; // sort(p.rbegin(), p.rend()); char tmp = T[0].first; rep(i, min(p[i].second, K)) { T[p[i].second].first = tmp; } string St = ""; rep(i, T.size()) { St += string(T[i].second, T[i].first); } int ans = 0; rep(i, St.size() - 1) { if (St[i] == St[i + 1]) ans++; } // cout << St << endl; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i)) using ll = long long; using namespace std; int main() { int N, K; cin >> N >> K; string S; cin >> S; vector<pair<char, int>> T; S += "X"; char prev = S[0]; int num = 1; for (int i = 1; i < S.size(); ++i) { if (prev == S[i]) { num++; } else { T.emplace_back(prev, num); num = 1; prev = S[i]; } } if (T.size() % 2 == 0) T.emplace_back('X', 0); vector<pair<int, int>> p; for (int i = 1; i < T.size() - 1; i += 2) { int num = T[i - 1].second + T[i].second + T[i + 1].second; p.emplace_back(num, i); } // for (auto tmp : p) { // cout << tmp.first << tmp.second << " "; // } // cout << endl; // sort(p.rbegin(), p.rend()); char tmp = T[0].first; int sz = min((int)p.size(), K); rep(i, sz) { T[p[i].second].first = tmp; } string St = ""; rep(i, T.size()) { St += string(T[i].second, T[i].first); } int ans = 0; rep(i, St.size() - 1) { if (St[i] == St[i + 1]) ans++; } // cout << St << endl; cout << ans << endl; }
replace
41
42
41
43
0
p02918
C++
Time Limit Exceeded
#include <iostream> #include <unordered_map> using namespace std; unordered_map<string, int> mp; int getHappyValue(string &s) { int size = s.size(); int happy = 0; for (int i = 0; i < size - 1; i++) { if (s[i] == s[i + 1]) { happy++; } } return happy; } void getRotateString(string &s, int l, int r) { int size = s.size(); for (int i = 0; i < size; i++) { if (i < l) { } else if (i > r) { } else { if (i <= r - i + l) { char a = s[i]; s[i] = (s[r - i + l] == 'L') ? 'R' : 'L'; s[r - i + l] = (a == 'L') ? 'R' : 'L'; } } } } int main(void) { int N; int K; string S; cin >> N >> K; cin >> S; int size = S.size(); int l = -1; int r = -1; string tmp = S; int k = 0; for (int i = 0; i < size; i++) { if (tmp[i] != tmp[i + 1] && l == -1) { l = i + 1; } else if (tmp[i] != tmp[i + 1] && l != -1) { r = i; } if (l != -1 && r != -1) { getRotateString(tmp, l, r); // cout << l << "," << r << ":" << tmp << endl; k++; i = l; l = -1; r = -1; if (k >= K) break; } } cout << getHappyValue(tmp); return 0; }
#include <iostream> #include <unordered_map> using namespace std; unordered_map<string, int> mp; int getHappyValue(string &s) { int size = s.size(); int happy = 0; for (int i = 0; i < size - 1; i++) { if (s[i] == s[i + 1]) { happy++; } } return happy; } void getRotateString(string &s, int l, int r) { int size = s.size(); for (int i = l; i <= r; i++) { if (i <= r - i + l) { char a = s[i]; s[i] = (s[r - i + l] == 'L') ? 'R' : 'L'; s[r - i + l] = (a == 'L') ? 'R' : 'L'; } } } int main(void) { int N; int K; string S; cin >> N >> K; cin >> S; int size = S.size(); int l = -1; int r = -1; string tmp = S; int k = 0; for (int i = 0; i < size; i++) { if (tmp[i] != tmp[i + 1] && l == -1) { l = i + 1; } else if (tmp[i] != tmp[i + 1] && l != -1) { r = i; } if (l != -1 && r != -1) { getRotateString(tmp, l, r); // cout << l << "," << r << ":" << tmp << endl; k++; i = l; l = -1; r = -1; if (k >= K) break; } } cout << getHappyValue(tmp); return 0; }
replace
19
28
19
24
TLE
p02918
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (long long i = 0; i < (n); i++) using namespace std; typedef long long ll; const int MOD = 1000000007; const int INF = 0x3f3f3f3f; const ll INFL = 0x3f3f3f3f3f3f3f3f; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, k; cin >> n >> k; string s; cin >> s; vector<int> vec; int sum = 1; if (n == 1) cout << 0 << endl; if (n == 2) cout << 1 << endl; else { rep(i, n - 1) { if (s[i] == s[i + 1]) sum++; else { vec.push_back(sum); sum = 1; } if (i == n - 2 && sum > 1) vec.push_back(sum); } int N = vec.size(); if (N == 1) cout << N - 1 << endl; else { ll ans = vec[0] + vec[N - 1]; rep(i, k) { if (i + 1 < N - 2 - i) ans += vec[i + 1] + vec[N - 2 - i]; else if (i + 1 == N - 2 - i) ans += vec[i + 1]; else break; } if (N - 2 * k > 0) cout << ans - 2 << endl; else cout << ans - 1 << endl; } } }
#include <bits/stdc++.h> #define rep(i, n) for (long long i = 0; i < (n); i++) using namespace std; typedef long long ll; const int MOD = 1000000007; const int INF = 0x3f3f3f3f; const ll INFL = 0x3f3f3f3f3f3f3f3f; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, k; cin >> n >> k; string s; cin >> s; int sum = 0; rep(i, n - 1) if (s[i] == s[i + 1]) sum++; cout << min(sum + 2 * k, n - 1) << endl; }
replace
17
53
17
20
0
p02918
C++
Runtime Error
#include <algorithm> #include <bitset> #include <complex> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; #define pi pair<int, int> #define pl pair<long long, long long> #define chmax(a, b) (a < b ? a = b : 0) #define chmin(a, b) (a > b ? a = b : 0) #define en cout << endl // セミコロンつけろ // #define MM 1000000000 // #define MOD MM+7 typedef long long ll; const int MM = 1e9; const int MOD = MM + 7; const long double PI = acos(-1); const long long INF = 1e15; int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1}; int dy[8] = {0, -1, 0, 1, -1, 1, 1, -1}; // 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122 template <typename T> T GCD(T u, T v) { return v ? GCD(v, u % v) : u; } template <typename T> T LCM(T x, T y) { T gc = GCD(x, y); return x * y / gc; } struct edge { ll to, cost; }; /* const int COM_MAX = 500500; long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX]; void init(){ fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i < COM_MAX; 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; } } long long COM(int n,int k){ if(n < k || n < 0 || k < 0) return 0; return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD; } */ int main() { int N, K; cin >> N >> K; string s; cin >> s; // Lmax vector<int> L(0), R(0), sz(0); int tmp = 1; for (int i = 1; i < s.size(); i++) { if (s[i - 1] == s[i]) { tmp++; } else { if (s[i] == 'R') { sz.push_back(tmp); } else { sz.push_back(tmp); } tmp = 1; } } sz.push_back(tmp); int length = 0, mx = 0; for (int i = 0; i < 2 * K + 1; i++) { length += sz[i]; } length--; for (int i = 2 * K + 1; i < sz.size(); i++) { length += sz[i] - 1; } // cout << "check : " << length << endl; mx = max(length, mx); int in = 1; for (int i = 2 * K + 1; i < sz.size(); i++) { length -= sz[in]; length += sz[in] - 1; length -= sz[in - 1]; length += sz[in - 1] - 1; in += 2; length -= sz[i] - 1; length += sz[i]; i++; mx = max(mx, length); // cout << "check : " << length << endl; } cout << mx << endl; }
#include <algorithm> #include <bitset> #include <complex> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; #define pi pair<int, int> #define pl pair<long long, long long> #define chmax(a, b) (a < b ? a = b : 0) #define chmin(a, b) (a > b ? a = b : 0) #define en cout << endl // セミコロンつけろ // #define MM 1000000000 // #define MOD MM+7 typedef long long ll; const int MM = 1e9; const int MOD = MM + 7; const long double PI = acos(-1); const long long INF = 1e15; int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1}; int dy[8] = {0, -1, 0, 1, -1, 1, 1, -1}; // 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122 template <typename T> T GCD(T u, T v) { return v ? GCD(v, u % v) : u; } template <typename T> T LCM(T x, T y) { T gc = GCD(x, y); return x * y / gc; } struct edge { ll to, cost; }; /* const int COM_MAX = 500500; long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX]; void init(){ fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i < COM_MAX; 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; } } long long COM(int n,int k){ if(n < k || n < 0 || k < 0) return 0; return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD; } */ int main() { int N, K; cin >> N >> K; string s; cin >> s; // Lmax vector<int> L(0), R(0), sz(0); int tmp = 1; for (int i = 1; i < s.size(); i++) { if (s[i - 1] == s[i]) { tmp++; } else { if (s[i] == 'R') { sz.push_back(tmp); } else { sz.push_back(tmp); } tmp = 1; } } if (tmp >= 1) sz.push_back(tmp); if (sz.size() % 2 == 0) { if (sz.size() / 2 <= K) { cout << N - 1 << endl; return 0; } } else { if (sz.size() - 1 <= 2 * K) { cout << N - 1 << endl; return 0; } } int length = 0, mx = 0; for (int i = 0; i < 2 * K + 1; i++) { length += sz[i]; } length--; for (int i = 2 * K + 1; i < sz.size(); i++) { length += sz[i] - 1; } // cout << "check : " << length << endl; mx = max(length, mx); int in = 1; for (int i = 2 * K + 1; i < sz.size(); i++) { length -= sz[in]; length += sz[in] - 1; length -= sz[in - 1]; length += sz[in - 1] - 1; in += 2; length -= sz[i] - 1; length += sz[i]; i++; mx = max(mx, length); // cout << "check : " << length << endl; } cout << mx << endl; }
replace
82
83
82
96
0
p02918
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define int long long using namespace std; const int INF = 1e10; const int ZERO = 0; signed main() { int N, K; cin >> N >> K; string S; cin >> S; int L = 0; int R = 0; for (int i = 0; i < N; i++) { if (S.at(i) == 'L') { L++; } else { R++; } } int A = 0; int C = 0; char s = S.at(0); bool B = false; for (int i = 1; i < N; i++) { if (S.at(i) != s) { C = i + 1; if (i == N - 1) { A = N; } if (B == true) { continue; } A++; B = true; if (A == K + 1) { A = i; break; } } else { B = false; } } if (A <= K) { A = C; } for (int i = 0; i < A; i++) { S.at(i) = s; } int ret = 0; for (int i = 0; i < N - 1; i++) { if (S.at(i) == S.at(i + 1)) { ret++; } } cout << ret << endl; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define int long long using namespace std; const int INF = 1e10; const int ZERO = 0; signed main() { int N, K; cin >> N >> K; string S; cin >> S; int L = 0; int R = 0; for (int i = 0; i < N; i++) { if (S.at(i) == 'L') { L++; } else { R++; } } int A = 0; int C = 0; char s = S.at(0); bool B = false; for (int i = 1; i < N; i++) { if (S.at(i) != s) { C = i + 1; if (i == N - 1) { if (A == K) { C = N; } else { A == N; } } if (B == true) { continue; } A++; B = true; if (A == K + 1) { A = i; break; } } else { B = false; } } if (A <= K) { A = C; } for (int i = 0; i < A; i++) { S.at(i) = s; } int ret = 0; for (int i = 0; i < N - 1; i++) { if (S.at(i) == S.at(i + 1)) { ret++; } } cout << ret << endl; }
replace
39
40
39
44
0
p02918
C++
Time Limit Exceeded
#include <iostream> using namespace std; string str; int N, K; char nt(char a) { if (a == 'R') { return 'L'; } if (a == 'L') { return 'R'; } } int findInd(int a) { int i = a; char c = str[a]; while (str[i] == c) { i++; } return i; } int rep(int l, int r) { string a(str); for (int i = 0; i <= r - l; i++) { a[i + l] = nt(str[r - i]); } str = a; return 0; } int countS() { int count = 0; for (int i = 0; i < N; i++) { if (str[i + 1] == str[i]) { count++; } } return count; } int main() { cin >> N >> K; cin >> str; int i = 0; while (findInd(0) != N && i < K) { rep(findInd(0), findInd(findInd(0)) - 1); i++; } cout << countS(); return 0; }
#include <iostream> using namespace std; string str; int N, K; char nt(char a) { if (a == 'R') { return 'L'; } if (a == 'L') { return 'R'; } } int findInd(int a) { int i = a; char c = str[a]; while (str[i] == c) { i++; } return i; } int rep(int l, int r) { string a(str); for (int i = 0; i <= r - l; i++) { a[i + l] = nt(str[r - i]); } str = a; return 0; } int countS() { int count = 0; for (int i = 0; i < N; i++) { if (str[i + 1] == str[i]) { count++; } } return count; } int main() { cin >> N >> K; cin >> str; int i = 0; int p = 0; while (findInd(p) != N && i < K) { p = findInd(p); rep(p, findInd(p) - 1); i++; } cout << countS(); return 0; }
replace
45
47
45
49
TLE
p02918
C++
Runtime Error
#include <algorithm> // minmax, sort, swap #include <climits> // INT_MIN, LLONG_MIN #include <cmath> // long, trig, pow #include <cstdio> // printf, scanf #include <deque> // deque #include <functional> // std::function<void(int)> #include <iomanip> // cout<<setprecision(n) #include <iostream> // cin, cout, cerr, clog #include <map> // key-value pairs sorted by keys #include <numeric> // iota, accumulate, inner_product #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, stoi, to_string #include <unordered_map> // hashed by keys #include <unordered_set> // hashed by keys #include <vector> // vector #define rep(i, n) for (int i = 0; i < (n); i++) #define ENDL '\n' #define print(i) std::cout << (i) << '\n' #define int long long // at least int64 > 9*10^18 #define all(v) (v).begin(), (v).end() /* libraries */ signed main() { int n, k; std::cin >> n >> k; std::string s; std::cin >> s; std::vector<int> unhappy; if (s[0] == 'L') unhappy.emplace_back(1); if (s[n - 1] == 'R') unhappy.emplace_back(1); rep(i, n - 1) { if (s[i] == 'R' && s[i + 1] == 'L') unhappy.emplace_back(2); } std::sort(all(unhappy), std::greater<int>()); int sum = n; for (int i : unhappy) sum -= i; rep(i, k) sum += unhappy[i]; print(sum); return 0; }
#include <algorithm> // minmax, sort, swap #include <climits> // INT_MIN, LLONG_MIN #include <cmath> // long, trig, pow #include <cstdio> // printf, scanf #include <deque> // deque #include <functional> // std::function<void(int)> #include <iomanip> // cout<<setprecision(n) #include <iostream> // cin, cout, cerr, clog #include <map> // key-value pairs sorted by keys #include <numeric> // iota, accumulate, inner_product #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, stoi, to_string #include <unordered_map> // hashed by keys #include <unordered_set> // hashed by keys #include <vector> // vector #define rep(i, n) for (int i = 0; i < (n); i++) #define ENDL '\n' #define print(i) std::cout << (i) << '\n' #define int long long // at least int64 > 9*10^18 #define all(v) (v).begin(), (v).end() /* libraries */ signed main() { int n, k; std::cin >> n >> k; std::string s; std::cin >> s; std::vector<int> unhappy; if (s[0] == 'L') unhappy.emplace_back(1); if (s[n - 1] == 'R') unhappy.emplace_back(1); rep(i, n - 1) { if (s[i] == 'R' && s[i + 1] == 'L') unhappy.emplace_back(2); } std::sort(all(unhappy), std::greater<int>()); int sum = n; for (int i : unhappy) sum -= i; rep(i, k) if (i < unhappy.size()) sum += unhappy[i]; if (k >= unhappy.size()) sum = n - 1; print(sum); return 0; }
replace
44
45
44
47
0