submission_id stringlengths 10 10 | problem_id stringlengths 6 6 | language stringclasses 3 values | code stringlengths 1 522k | compiler_output stringlengths 43 10.2k |
|---|---|---|---|---|
s092507239 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
//long long
using ll = long long;
//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
// begin() end()
#define all(x) (x).begin(),(x).end()
//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
//最大公約数
unsigned gcd(unsigned a, unsigned b) {
if(a < b) return gcd(b, a);
unsigned r;
while ((r=a%b)) {
a = b;
b = r;
}
return b;
}
int main(){
int n;
cin >> n
vector<int> a(n);
REP(i, n) cin >> a[i];
int ans1;
// +-+-の場合
if(n.at(0) <= 0) a[i] = a[i] + abs(1 - a[i]);
for(int i = 0; i < N; i++){
if(i % 2 == 0){
if(a[i] + a[i + 1] >= 0 ){
ans1 += -1 - a[i];
a[i] + a[i + 1] = a[i] + (-1 - a[i]);
}
}else if(i % 2 == 1){
if(a[i] + a[i + 1] >= 0){
ans1 += abs(1 - a[i]);
a[i] + a[i + 1] = a[i] + abs(1 - a[i]);
}
}
}
int ans2;
if(n.at(0) <= 0) a[i] = a[i] + abs(1 - a[i]);
for(int i = 0; i < N; i++){
if(a[i] + a[i + 1] >= 0){
ans2 += abs(1 - a[i]);
a[i] + a[i + 1] = a[i] + abs(1 - a[i]);
}else if(i % 2 == 1){
if(i % 2 == 0){
if(a[i] + a[i + 1] >= 0 ){
ans2 += -1 - a[i];
a[i] + a[i + 1] = a[i] + (-1 - a[i]);
}
}
}
}
// +-+-の場合
} | a.cc: In function 'int main()':
a.cc:38:13: error: expected ';' before 'vector'
38 | cin >> n
| ^
| ;
39 | vector<int> a(n);
| ~~~~~~
a.cc:40:22: error: 'a' was not declared in this scope
40 | REP(i, n) cin >> a[i];
| ^
a.cc:44:10: error: request for member 'at' in 'n', which is of non-class type 'int'
44 | if(n.at(0) <= 0) a[i] = a[i] + abs(1 - a[i]);
| ^~
a.cc:44:22: error: 'a' was not declared in this scope
44 | if(n.at(0) <= 0) a[i] = a[i] + abs(1 - a[i]);
| ^
a.cc:44:24: error: 'i' was not declared in this scope
44 | if(n.at(0) <= 0) a[i] = a[i] + abs(1 - a[i]);
| ^
a.cc:45:28: error: 'N' was not declared in this scope
45 | for(int i = 0; i < N; i++){
| ^
a.cc:47:20: error: 'a' was not declared in this scope
47 | if(a[i] + a[i + 1] >= 0 ){
| ^
a.cc:52:20: error: 'a' was not declared in this scope
52 | if(a[i] + a[i + 1] >= 0){
| ^
a.cc:59:11: error: request for member 'at' in 'n', which is of non-class type 'int'
59 | if(n.at(0) <= 0) a[i] = a[i] + abs(1 - a[i]);
| ^~
a.cc:59:23: error: 'a' was not declared in this scope
59 | if(n.at(0) <= 0) a[i] = a[i] + abs(1 - a[i]);
| ^
a.cc:59:25: error: 'i' was not declared in this scope
59 | if(n.at(0) <= 0) a[i] = a[i] + abs(1 - a[i]);
| ^
a.cc:60:28: error: 'N' was not declared in this scope
60 | for(int i = 0; i < N; i++){
| ^
a.cc:61:20: error: 'a' was not declared in this scope
61 | if(a[i] + a[i + 1] >= 0){
| ^
|
s209778081 | p03739 | C++ | #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[i];
}
long long sum = 0;
long long ans = 0;
for(int i = 0; i < N; i++){
sum += a[i];
if(i % 2 == 0){
if(sum < 0){
ans += -(sum) + 1;
sum = 1;
} else if(sum == 0){
ans++;
sum = 1;
}
} else {
if(sum > 0){
ans += sum + 1;
sum = -1;
} else if(sum == 0){
ans++;
sum = -1;
}
}
}
sum = 0;
long long ans2 = 0;
for(int i = 0; i < N; i++){
sum += a[i];
if(i % 2 == 0){
if(sum < 0){
ans2 += -(sum) + 1;
sum = 1;
} else if(sum == 0){
ans2++;
sum = 1;
}
} else {
if(sum > 0){
ans2 += sum + 1;
sum = -1;
} else if(sum == 0){
ans2++;
sum = -1;
}
}
}
cout << min(ans,ans2) << endl;
} | a.cc: In function 'int main()':
a.cc:7:19: error: 'N' was not declared in this scope
7 | vector<int> a(N);
| ^
|
s831566189 | p03739 | C++ | #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[i];
int odd = 0; even = 0; sum = 0;
for (int i=0; i<n; i++){
sum += a[i];
if(i%2==0&&sum<=0){
odd += abs(sum)+1;
sum = +1;
}
else if(i%2==1&&sum>=0){
odd += abs(sum)+1;
sum = -1;
}
}
sum = 0;
for (int i=0; i<n; i++){
sum += a[i];
if (i%2==1&&sum<=0){
even += abs(sum)+1;
sum = +1;
}
else if(i%2==0&&sum>=0){
even+=abs(sum)+1;
sum=-1;
}
}
cout << min(odd,even) << endl;
} | a.cc: In function 'int main()':
a.cc:11:16: error: 'even' was not declared in this scope
11 | int odd = 0; even = 0; sum = 0;
| ^~~~
a.cc:11:26: error: 'sum' was not declared in this scope
11 | int odd = 0; even = 0; sum = 0;
| ^~~
|
s965276594 | p03739 | C++ | #include<bits/stdc++.h>
using namespace std;
#define ll long long;
LL ans1,ans2,sum;
int n;
int a[100010];
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
sum=0;
for(int i=1,s=1;i<=n;i++,s*=-1){
sum+=a[i];
if(sum*s<=0) ans1+=abs(sum-s),sum=s;
}
sum=0;
for(int i=1,s=-1;i<=n;i++,s*=-1){
sum+=a[i];
if(sum*s<=0) ans2+=abs(sum-s),sum=s;
}
printf("%lld\n",min(ans1,ans2));
return 0;
}
| a.cc:4:1: error: 'LL' does not name a type; did you mean 'll'?
4 | LL ans1,ans2,sum;
| ^~
| ll
a.cc: In function 'int main()':
a.cc:11:9: error: 'sum' was not declared in this scope
11 | sum=0;
| ^~~
a.cc:14:30: error: 'ans1' was not declared in this scope
14 | if(sum*s<=0) ans1+=abs(sum-s),sum=s;
| ^~~~
a.cc:19:30: error: 'ans2' was not declared in this scope
19 | if(sum*s<=0) ans2+=abs(sum-s),sum=s;
| ^~~~
a.cc:21:29: error: 'ans1' was not declared in this scope
21 | printf("%lld\n",min(ans1,ans2));
| ^~~~
a.cc:21:34: error: 'ans2' was not declared in this scope
21 | printf("%lld\n",min(ans1,ans2));
| ^~~~
|
s925298641 | p03739 | C++ | #include <bits/stdc++.h>
#define int ll
#define abs(x) llabs((x))
using namespace std;
typedef long long ll;
int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int count=0;
int ans=0;
for(int i=0;i<n;i++){
count+=a[i];
if(i%2==0){
if(count<=0){
ans+=abs(count)+1;
count=1;
}
}
else{
if(count>=0){
ans+=count+1;
count=-1;
}
}
}
int count2=0;
int ans2=0;
for(int i=0;i<n;i++){
count2+=a[i];
if(i%2==1){
if(count2<=0){
ans2+=abs(count2)+1;
count2=1;
}
}
else{
if(count2>=0){
ans2+=count2+1;
count2=-1;
}
}
}
cout<<min(ans,ans2)<<endl;
}
| a.cc:2:13: error: '::main' must return 'int'
2 | #define int ll
| ^~
a.cc:7:1: note: in expansion of macro 'int'
7 | int main()
| ^~~
|
s400580488 | p03739 | C++ | #include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
//#include <map>
#include <algorithm>
using namespace std;
#define n_max 100000
#define N_max 100
#define rep(i, a, n) for(int i = a; i < n; i++)
#define rrep(i, a, n) for(int i = a; i > n; i--)
#define lrep(i, a, n) for(long int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
long int check(long int sum, long int ans, vector<int> T, int N, bool pre_pm) {
for(int i = 1; i < N; i ++) {
if(pre_pm) {
sum += T.at(i);
while (0 <= sum) {
sum--;
ans++;
}
pre_pm = false;
} else {
sum += T.at(i);
while (sum <= 0 ) {
sum++;
ans++;
}
pre_pm = true;
}
}
return ans;
}
int main()
{
int N;
vector<int> T;
cin >> N;
for(int i = 0; i < N; i++) {
int tmp;
cin >> tmp;
T.push_back(tmp);
}
//sort(T.begin(), T.end());
//for(int i = 0; i < N; i++) { //cout << T.at(i) << endl; }
long int ans = 0;
long int sum = 0;
bool pre_pm;
sum = T.at(0);
if(0 <= sum) {
pre_pm = true;
if(!sum) { sum++; ans++;
long int tmp1 = check(sum, ans, T, N, pre_pm);}
pre_pm = false;
long int tmp2 = check(-1, 1+sum, T, N, pre_pm);
cout << min(tmp1, tmp2) << endl;
} else {
pre_pm = false;
long int tmp1 = check(sum, ans, T, N, pre_pm);
pre_pm = true;
long int tmp2 = check(1, 1 + sum, T, N, pre_pm);
cout << min(tmp1, tmp2) << endl;
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:68:21: error: 'tmp1' was not declared in this scope; did you mean 'tmp2'?
68 | cout << min(tmp1, tmp2) << endl;
| ^~~~
| tmp2
|
s081296645 | p03739 | C++ | #include<bits/stdc++.h>
using namespace std;
int main(){
long long N,sum,ans,ans2;
cin>>N;
sum=0;
vector<long long>x(N);
for(int i=0;i<N;i++){
cin>>x[i];
}
for(int i=0;i<N;i++){
sum+=x[i];
if(i%2==0&&sum<=0){
ans+=1-sum;
sum=1;
}
if(i%2==1&&sum>=0){
ans+=1+sum;
sum=-1;
}
}
ans2=ans;
ans=0;
sum=0;
for(int i=0;i<N;i++){
sum+=x[i];
if(i%2==1&&sum<=0){
ans+=1-sum;
sum=1;
}
if(i%2==0&&sum>=0){
ans+=1+sum;
sum=-1;
}
}
cout<<min(sum,sum2)<<endl;
}
| a.cc: In function 'int main()':
a.cc:38:21: error: 'sum2' was not declared in this scope; did you mean 'sum'?
38 | cout<<min(sum,sum2)<<endl;
| ^~~~
| sum
|
s280008744 | p03739 | C++ | #include <iostream>
#include <vector>
#include <cmath>
int main(void) {
// in
int n;
std::cin >> n;
std::vector<long long> a(n);
for(int i = 0; i < n; ++i) std::cin >> a[i];
// sum
int cost_all = 0;
std::vector<long long> s(n, 0);
for(int k = 0; k < 2; ++k) {
int cost = 0;
if(k == 0) {
s[0] = (a[0] > 0 ? a[0] : 1);
cost += std::abs(a[0] - s[0]);
}
else {
s[0] = (a[0] < 0 ? a[0] : -1);
cost += std::abs(a[0] - s[0]);
}
for(int i = 1; i < n; ++i) {
// current sum
s[i] = s[i-1] + a[i];
if(s[i] * s[i-1] < 0) continue;
else {
if(s[i-1] < 0) {
cost += std::abs(1 - s[i-1] - a[i]);
a[i] = 1 - s[i-1];
}
else {
cost += std::abs(- 1 - s[i-1] - a[i]);
a[i] = - 1 - s[i-1];
}
}
s[i] = s[i-1] + a[i];
}
cost_all = (cost < cost_all ? cost : cost_all);
}
//for(int i = 0; i < n; ++i) {
// std::cout << a[i] << std::endl;
//}
std::cout << cost << std::endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:49:22: error: 'cost' was not declared in this scope; did you mean 'cosl'?
49 | std::cout << cost << std::endl;
| ^~~~
| cosl
|
s655056600 | p03739 | C++ | #include <iostream>
#include <vector>
using namespace std;
#define int long long
int main() {
int N; cin >> N;
vector<int> S(N + 1);
S[0] = 0;
for (int i = 1; i <= N; ++i) {
cin >> S[i];
S[i] += S[i - 1];
}
int ians = (1 << 30);
for (int j = -1; j <= 1; j += 2) {
vector<int> S_(S);
int ans = 0;
int add = 0;
int sign = j;
for (int i = 1; i <= N; ++i) {
S_[i] += add;
int sign_i = ((S_[i] >> 31) << 1) + 1;
if (S_[i] == 0) {
ans += 1;
add += -sign;
S_[i] += -sign;
}
else if (sign_i == sign) {
ans += abs(-sign_i - S_[i]);
add += -sign_i - S_[i];
S_[i] = -sign_i;
}
sign = -sign;
}
ians = min(ans, ians);
}
cout << ians << endl;
}
| cc1plus: error: '::main' must return 'int'
|
s151491315 | p03739 | C++ | // AtCoder-Template.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include <iostream>
#include <algorithm>
#include <bitset>
#include <bits/stdc+++.h>
using namespace std;
using ll = long long;
#define FOR(i,N) for(auto i=0; i<N; ++i)
/* clang-format off */
template <class T> inline void chmin(T& a, const T& b) { if (b < a) a = b; }
/* clang-format on */
int main() {
ll N; cin >> N; vector<ll> A(N); FOR(i, N) cin >> A[i];
ll ans = 0;
auto getSign = [](auto a) { if (a > 0) return 1; else return -1; };
auto reverseSign = [&](auto a) { return -1 * getSign(a); };
ll accumu = A[0];
if (accumu <= 0) {
ans += abs(accumu) + 1;
accumu = 1;
}
FOR(i, N - 1) {
accumu += A[i + 1];
if (i + 1 >= 1 and !( ((i+1)%2 == 0) ? accumu > 0 : accumu < 0) ) {
ans += abs(accumu) + 1;
accumu = reverseSign(accumu);
}
;
}
// --------------------------
accumu = A[0];
ll tmp = 0;
if (accumu >= 0) {
tmp += abs(accumu) + 1;
accumu = -1;
}
FOR(i, N - 1) {
accumu += A[i + 1];
if (i + 1 >= 1 and !(((i+1)% 2 == 1) ? accumu > 0 : accumu < 0)) {
tmp += abs(accumu) + 1;
accumu = reverseSign(accumu);
}
}
chmin(ans, tmp);
cout << ans << endl;
return 0;
}
| a.cc:7:10: fatal error: bits/stdc+++.h: No such file or directory
7 | #include <bits/stdc+++.h>
| ^~~~~~~~~~~~~~~~
compilation terminated.
|
s498141669 | p03739 | C++ | #include <iostream>
#include <cmath>
using namespace std;
int main(){
int n;cin>>n;
int a[n];
for(int i = 0; n > i; i++)cin>>a[i];
long long sh = 0;
long long nw = 0;
for(int i = 0; n > i; i++){
(long long)nw += a[i];
if(i % 2 == 0)if(nw<=0)(long long)sh += 1-nw,nw=1;
if(i % 2 == 1)if(nw>=0)(long long)sh += nw+1,nw=-1;
}
long long hs = 0;
nw = 0;
for(int i = 0; n > i; i++){
(long long)nw += a[i];
if(i % 2 == 1)if(nw<=0)(long long)hs += 1-nw,nw=1;
if(i % 2 == 0)if(nw>=0)(long long)hs += nw+1,nw=-1;
}
cout << min(hs,sh) << endl;
} | a.cc: In function 'int main()':
a.cc:11:5: error: lvalue required as left operand of assignment
11 | (long long)nw += a[i];
| ^~~~~~~~~~~~~
a.cc:12:28: error: lvalue required as left operand of assignment
12 | if(i % 2 == 0)if(nw<=0)(long long)sh += 1-nw,nw=1;
| ^~~~~~~~~~~~~
a.cc:13:28: error: lvalue required as left operand of assignment
13 | if(i % 2 == 1)if(nw>=0)(long long)sh += nw+1,nw=-1;
| ^~~~~~~~~~~~~
a.cc:18:5: error: lvalue required as left operand of assignment
18 | (long long)nw += a[i];
| ^~~~~~~~~~~~~
a.cc:19:28: error: lvalue required as left operand of assignment
19 | if(i % 2 == 1)if(nw<=0)(long long)hs += 1-nw,nw=1;
| ^~~~~~~~~~~~~
a.cc:20:28: error: lvalue required as left operand of assignment
20 | if(i % 2 == 0)if(nw>=0)(long long)hs += nw+1,nw=-1;
| ^~~~~~~~~~~~~
|
s435550792 | p03739 | C++ | #include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define read_input freopen("in.txt","r", stdin)
#define print_output freopen("out.txt","w", stdout)
typedef long long ll;
typedef long double ld;
using namespace std;
int sign(int x) {
if(x > 0) return 1;
else if(x < 0) return 0;
else return -1;
}
ll f(ll t, int pre, int s) {
if(s == 0) return abs(-1-pre-t);
else return abs((1-t)-pre);
}
int main() {
int n, a[100005];
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
ll ans1 = 0, ans2 = 0;
int s = 1;
ll x = 0, tmp;
for(int i = 1; i <= n; i++, s ^= 1) {
tmp = x;
x += a[i];
if(sign(x) != s) ans1 += f(tmp, a[i], s);
if(not s) x = min(-1, x);
else x = max(1, x);
}
s = 0, x = 0;
for(int i = 1; i <= n; i++, s ^= 1) {
tmp = x;
x += a[i];
if(sign(x) != s) ans2 += f(tmp, a[i], s);
if(not s) x = min(-1, x);
else x = max(1, x);
}
cout << min(ans1, ans2) << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:37:26: error: no matching function for call to 'min(int, ll&)'
37 | if(not s) x = min(-1, x);
| ~~~^~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:37:26: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
37 | if(not s) x = min(-1, x);
| ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:37:26: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
37 | if(not s) x = min(-1, x);
| ~~~^~~~~~~
a.cc:38:21: error: no matching function for call to 'max(int, ll&)'
38 | else x = max(1, x);
| ~~~^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:38:21: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
38 | else x = max(1, x);
| ~~~^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:38:21: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
38 | else x = max(1, x);
| ~~~^~~~~~
a.cc:47:26: error: no matching function for call to 'min(int, ll&)'
47 | if(not s) x = min(-1, x);
| ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:47:26: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
47 | if(not s) x = min(-1, x);
| ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:47:26: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
47 | if(not s) x = min(-1, x);
| ~~~^~~~~~~
a.cc:48:21: error: no matching function for call to 'max(int, ll&)'
48 | else x = max(1, x);
| ~~~^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:48:21: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
48 | else x = max(1, x);
| ~~~^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:48:21: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
48 | else x = max(1, x);
| ~~~^~~~~~
|
s082645750 | p03739 | C++ | #include <iostream>
#define T true
#define F false
using namespace std;
int main(void) {
int num, i = 1, a;
long long sum, ans = 0;
bool sig = T;
cin >> num >> sum;
if (sum < 0)
sig = F;
for (; i < num; i++) {
scanf_s("%d", &a);
if (sum == 0) {
if (a >= 0) {
sum--;
sig = F;
}
else
sum++;
ans++;
}
sum += a;
if (sig == T && sum >= 0) {
ans += sum + 1;
sum = -1;
}
else if (sig == F && sum <= 0) {
ans += (-1) * sum + 1;
sum = 1;
}
sig = !sig;
}
cout << ans << "\n";
return 0;
} | a.cc: In function 'int main()':
a.cc:15:17: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
15 | scanf_s("%d", &a);
| ^~~~~~~
| scanf
|
s235261323 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> A(n, 0);
for (int i = 0; i<n; i++) cin >> A[i];
long long cnt1=0, acm1=0, cnt2=0, acm2=0;
for(int i = 0; i<n; i++) {
acm1+=A[i];
acm2+=A[i];
if(i%2) {
if(acm1>0);
else {
cnt1 += abs(acm1) + 1;
acm1 = 1;
}
if(acm2<0);
else {
cnt2 += abs(acm2) + 1;
acm2 = -1;
}
}
else {
if(acm1<0);
else {
cnt1 += abs(acm1) + 1;
acm1 = -1;
}
if(acm2>0);
else {
cnt2 += abs(acm2) + 1;
acm2 = 1;
}
}
cout << min(cnt1, cnt2) << "\n";
} | a.cc: In function 'int main()':
a.cc:39:2: error: expected '}' at end of input
39 | }
| ^
a.cc:4:12: note: to match this '{'
4 | int main() {
| ^
|
s003099129 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> A(n, 0);
for (int i = 0; i<n; i++) cin >> A[i];
long long cnt1=0, acm1=0, cnt2=0, acm2=0;
for(int i = 0; i<n; i++) {
acm1+=A[i];
acm2+=A[i];
if(i%2) {
if(acm1>0);
else {
cnt1 += abs(acm1) + 1;
acm1 = 1;
}
if(acm2<0);
else {
cnt2 += abs(acm2) + 1;
acm2 = -1;
}
else {
if(acm1<0);
else {
cnt1 += abs(acm1) + 1;
acm1 = -1;
}
if(acm2>0);
else {
cnt2 += abs(acm2) + 1;
acm2 = 1;
}
}
cout << min(cnt1, cnt2) << "\n";
} | a.cc: In function 'int main()':
a.cc:24:5: error: expected '}' before 'else'
24 | else {
| ^~~~
a.cc:13:13: note: to match this '{'
13 | if(i%2) {
| ^
a.cc:38:2: error: expected '}' at end of input
38 | }
| ^
a.cc:4:12: note: to match this '{'
4 | int main() {
| ^
|
s962771706 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans;
cin >> n;
int A[n];
for (int i = 0; i<n; i++) cin >> A[i];
int cnt=0, acm=0, ans=0;
for(int i = 0; i<n; i++) {
if(i%2) {
if(acm+A[i]>0) acm+=A[i];
else {
cnt += abs(acm+A[i]) + 1;
acm = 1;
}
}
else {
if(acm+A[i]<0) acm+=A[i];
else {
cnt += abs(acm+A[i]) + 1;
acm = -1;
}
}
}
ans = cnt;
cnt=0;
acm=0;
for(int i = 0; i<n; i++) {
if((i+1)%2) {
if(acm+A[i]>0) acm+=A[i];
else {
cnt += abs(acm+A[i]) + 1;
acm = 1;
}
}
else {
if(acm+A[i]<0) acm+=A[i];
else {
cnt += abs(acm+A[i]) + 1;
acm = -1;
}
}
}
ans = min(ans,cnt);
cout << ans << "\n";
} | a.cc: In function 'int main()':
a.cc:9:21: error: redeclaration of 'int ans'
9 | int cnt=0, acm=0, ans=0;
| ^~~
a.cc:5:10: note: 'int ans' previously declared here
5 | int n, ans;
| ^~~
|
s269566266 | p03739 | C++ | #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main(){
int N;
cin >> N;
vector<long long int> A(N);
for(int i = 0; i < N; i++) cin >> A[i];
long long unsigned int cnt, cnt1 ,cnt2 = 0;
long long unsigned int M = 0;
M = A[0];
for(int i = 1 ; i < N; i++){
if(i % 2 == 0){
cnt1 += abs(1 - M);
}else{
cnt1 += abs(-1 - M);
}
M += A[i];
}
M = A[0];
for(int i = 1 ; i < N; i++){
if(i % 2 == 1){
cnt2 += abs(1 - M);
}else{
cnt2 += abs(-1 - M);
}
}
cnt = min(cnt1, cnt2);
cout << cnt;
}
| a.cc: In function 'int main()':
a.cc:21:18: error: call of overloaded 'abs(long long unsigned int)' is ambiguous
21 | cnt1 += abs(1 - M);
| ~~~^~~~~~~
In file included from /usr/include/c++/14/cstdlib:79,
from /usr/include/c++/14/ext/string_conversions.h:43,
from /usr/include/c++/14/bits/basic_string.h:4154,
from /usr/include/c++/14/string:54,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
| ^~~
In file included from /usr/include/c++/14/cstdlib:81:
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
137 | abs(__float128 __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
85 | abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
| ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
79 | abs(long double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
75 | abs(float __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
71 | abs(double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
61 | abs(long long __x) { return __builtin_llabs (__x); }
| ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
56 | abs(long __i) { return __builtin_labs(__i); }
| ^~~
a.cc:23:18: error: call of overloaded 'abs(long long unsigned int)' is ambiguous
23 | cnt1 += abs(-1 - M);
| ~~~^~~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
| ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
137 | abs(__float128 __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
85 | abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
| ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
79 | abs(long double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
75 | abs(float __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
71 | abs(double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
61 | abs(long long __x) { return __builtin_llabs (__x); }
| ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
56 | abs(long __i) { return __builtin_labs(__i); }
| ^~~
a.cc:30:18: error: call of overloaded 'abs(long long unsigned int)' is ambiguous
30 | cnt2 += abs(1 - M);
| ~~~^~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
| ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
137 | abs(__float128 __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
85 | abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
| ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
79 | abs(long double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
75 | abs(float __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
71 | abs(double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
61 | abs(long long __x) { return __builtin_llabs (__x); }
| ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
56 | abs(long __i) { return __builtin_labs(__i); }
| ^~~
a.cc:32:18: error: call of overloaded 'abs(long long unsigned int)' is ambiguous
32 | cnt2 += abs(-1 - M);
| ~~~^~~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
| ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
137 | abs(__float128 __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
85 | abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
| ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
79 | abs(long double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
75 | abs(float __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
71 | abs(double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
61 | abs(long long __x) { return __builtin_llabs (__x); }
| ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
56 | abs(long __i) { return __builtin_labs(__i); }
| ^~~
|
s312060938 | p03739 | C++ | #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main(){
int N;
cin >> N;
vector<long long int> A(N);
for(int i = 0; i < N; i++) cin >> A[i];
long long unsigned int cnt, cnt1 ,cnt2 = 0;
long long unsigned int M = 0;
M = A[0];
for(int i = 1 ; i < N; i++){
if(i % 2 == 0){
cnt1 += abs(1 - M);
}else{
cnt1 += abs(-1 - M);
}
M += A[i];
}
M = A[0]
for(int i = 1 ; i < N; i++){
if(i % 2 == 1){
cnt2 += abs(1 - M);
}else{
cnt2 += abs(-1 - M);
}
}
cnt = min(cnt1, cnt2);
cout << cnt;
}
| a.cc: In function 'int main()':
a.cc:21:18: error: call of overloaded 'abs(long long unsigned int)' is ambiguous
21 | cnt1 += abs(1 - M);
| ~~~^~~~~~~
In file included from /usr/include/c++/14/cstdlib:79,
from /usr/include/c++/14/ext/string_conversions.h:43,
from /usr/include/c++/14/bits/basic_string.h:4154,
from /usr/include/c++/14/string:54,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
| ^~~
In file included from /usr/include/c++/14/cstdlib:81:
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
137 | abs(__float128 __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
85 | abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
| ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
79 | abs(long double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
75 | abs(float __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
71 | abs(double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
61 | abs(long long __x) { return __builtin_llabs (__x); }
| ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
56 | abs(long __i) { return __builtin_labs(__i); }
| ^~~
a.cc:23:18: error: call of overloaded 'abs(long long unsigned int)' is ambiguous
23 | cnt1 += abs(-1 - M);
| ~~~^~~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
| ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
137 | abs(__float128 __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
85 | abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
| ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
79 | abs(long double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
75 | abs(float __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
71 | abs(double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
61 | abs(long long __x) { return __builtin_llabs (__x); }
| ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
56 | abs(long __i) { return __builtin_labs(__i); }
| ^~~
a.cc:27:11: error: expected ';' before 'for'
27 | M = A[0]
| ^
| ;
28 | for(int i = 1 ; i < N; i++){
| ~~~
a.cc:28:19: error: 'i' was not declared in this scope
28 | for(int i = 1 ; i < N; i++){
| ^
|
s460516986 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
int main() {
long zero = 0;
int N;
cin >> N;
vector<int> sum(N,0);
int now;
cin >> now;
sum[0] = now;
for (int i=1; i<N; i++) {
cin >> now;
sum[i] = sum[i-1] + now;
}
long change = 0;
long ansp = 0;
int i = 0;
while (i<N) {
ansp += max(1-(sum[i]+change),zero);
change += max(1-(sum[i]+change),zero);
i++;
if (i==N) {
break;
}
ansp += max((sum[i]+change)+1,zero);
change -= max((sum[i]+change)+1,zero);
i++;
}
change = 0;
long ansm = 0;
i = 0;
while (i<N) {
ansm += max((sum[i]+change)+1,zero);
change -= max((sum[i]+change)+1,zero);
i++;
if (i==N) {
break;
}
ansm += max(1-(sum[i]+change),zero);
change += max(1-(sum[i]+change),zero)
i++;
}
cout << min(ansp,ansm) << endl;
} | a.cc: In function 'int main()':
a.cc:42:42: error: expected ';' before 'i'
42 | change += max(1-(sum[i]+change),zero)
| ^
| ;
43 | i++;
| ~
|
s528616735 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
int main() {
long zero = 0;
int N;
cin >> N;
vector<int> sum(N,0);
int now;
cin >> now;
sum[0] = now;
for (int i=1; i<N; i++) {
cin >> now;
sum[i] = sum[i-1] + now;
}
long change = 0;
long ansp = 0;
int i = 0;
while (i<N) {
ansp += max(1-(sum[i]+change),0);
change += max(1-(sum[i]+change),0);
i++;
if (i==N) {
break;
}
ansp += max((sum[i]+change)+1,0);
change -= max((sum[i]+change)+1,0);
i++;
}
change = 0;
long ansm = 0;
i = 0;
while (i<N) {
ansm += max((sum[i]+change)+1,zero);
change -= max((sum[i]+change)+1,zero);
i++;
if (i==N) {
break;
}
ansm += max(1-(sum[i]+change),zero);
change += max(1-(sum[i]+change),zero)
i++;
}
cout << min(ansp,ansm) << endl;
} | a.cc: In function 'int main()':
a.cc:21:16: error: no matching function for call to 'max(long int, int)'
21 | ansp += max(1-(sum[i]+change),0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:21:16: note: deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
21 | ansp += max(1-(sum[i]+change),0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:21:16: note: mismatched types 'std::initializer_list<_Tp>' and 'long int'
21 | ansp += max(1-(sum[i]+change),0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:22:18: error: no matching function for call to 'max(long int, int)'
22 | change += max(1-(sum[i]+change),0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:22:18: note: deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
22 | change += max(1-(sum[i]+change),0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:22:18: note: mismatched types 'std::initializer_list<_Tp>' and 'long int'
22 | change += max(1-(sum[i]+change),0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:27:16: error: no matching function for call to 'max(long int, int)'
27 | ansp += max((sum[i]+change)+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:27:16: note: deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
27 | ansp += max((sum[i]+change)+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:27:16: note: mismatched types 'std::initializer_list<_Tp>' and 'long int'
27 | ansp += max((sum[i]+change)+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:28:18: error: no matching function for call to 'max(long int, int)'
28 | change -= max((sum[i]+change)+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:28:18: note: deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
28 | change -= max((sum[i]+change)+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:28:18: note: mismatched types 'std::initializer_list<_Tp>' and 'long int'
28 | change -= max((sum[i]+change)+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:42:42: error: expected ';' before 'i'
42 | change += max(1-(sum[i]+change),zero)
| ^
| ;
43 | i++;
| ~
|
s355914894 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> sum(N,0);
int now;
cin >> now;
sum[0] = now;
for (int i=1; i<N; i++) {
cin >> now;
sum[i] = sum[i-1] + now;
}
long change = 0;
long ansp = 0;
int i = 0;
while (i<N) {
ansp += max(1-(sum[i]+change),0);
change += max(1-(sum[i]+change),0);
i++;
if (i==N) {
break;
}
ansp += max((sum[i]+change)+1,0);
change -= max((sum[i]+change)+1,0);
i++;
}
change = 0;
long ansm = 0;
i = 0;
while (i<N) {
ansm += max((sum[i]+change)+1,0);
change -= max((sum[i]+change)+1,0);
i++;
if (i==N) {
break;
}
ansm += max(1-(sum[i]+change),0);
change += max(1-(sum[i]+change),0);
i++;
}
cout << min(ansp,ansm) << endl;
} | a.cc: In function 'int main()':
a.cc:20:16: error: no matching function for call to 'max(long int, int)'
20 | ansp += max(1-(sum[i]+change),0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:20:16: note: deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
20 | ansp += max(1-(sum[i]+change),0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:20:16: note: mismatched types 'std::initializer_list<_Tp>' and 'long int'
20 | ansp += max(1-(sum[i]+change),0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:21:18: error: no matching function for call to 'max(long int, int)'
21 | change += max(1-(sum[i]+change),0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:21:18: note: deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
21 | change += max(1-(sum[i]+change),0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:21:18: note: mismatched types 'std::initializer_list<_Tp>' and 'long int'
21 | change += max(1-(sum[i]+change),0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:26:16: error: no matching function for call to 'max(long int, int)'
26 | ansp += max((sum[i]+change)+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:26:16: note: deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
26 | ansp += max((sum[i]+change)+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:26:16: note: mismatched types 'std::initializer_list<_Tp>' and 'long int'
26 | ansp += max((sum[i]+change)+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:27:18: error: no matching function for call to 'max(long int, int)'
27 | change -= max((sum[i]+change)+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:27:18: note: deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
27 | change -= max((sum[i]+change)+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:27:18: note: mismatched types 'std::initializer_list<_Tp>' and 'long int'
27 | change -= max((sum[i]+change)+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:34:16: error: no matching function for call to 'max(long int, int)'
34 | ansm += max((sum[i]+change)+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:34:16: note: deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
34 | ansm += max((sum[i]+change)+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:34:16: note: mismatched types 'std::initializer_list<_Tp>' and 'long int'
34 | ansm += max((sum[i]+change)+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:35:18: error: no matching function for call to 'max(long int, int)'
35 | change -= max((sum[i]+change)+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:35:18: note: deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
35 | change -= max((sum[i]+change)+1,0);
| ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/b |
s459200573 | p03739 | C++ | #include <cstdio>
#include <iostream>
#define ll long long
const int MAXN = 1e5 + 7;
const ll Inf = 1ll << 60;
using namespace std;
ll a[MAXN];
ll sum, ans = INF, res, n;
int main() {
bool flag = 0;
cin>>n;
for(int i = 1; i <= n; i++)
cin>>a[i];
for(int i = 1; i <= n; i++) {
sum += a[i];
if(!flag) { // if flag is 0 , means sum is postive
if(sum <= 0) {
res += 1 - sum;
sum = 1;
}
}else {
if(sum >= 0) {
res += sum + 1;
sum = -1;
}
}
flag ^= 1;
}
if(res < ans) ans = res;
flag = 0, res = sum = 0;
for(int i = 1; i <= n; i++) {
sum += a[i];
if(!flag) { // if flag is 0 , means sum is negative
if(sum >= 0) {
res += sum + 1;
sum = -1;
}
}else {
if(sum <= 0) {
res += 1 - sum;
sum = 1;
}
}
flag ^= 1;
}
if(res < ans) ans = res;
cout<<ans<<endl;
return 0;
} | a.cc:9:15: error: 'INF' was not declared in this scope; did you mean 'Inf'?
9 | ll sum, ans = INF, res, n;
| ^~~
| Inf
a.cc: In function 'int main()':
a.cc:13:14: error: 'n' was not declared in this scope
13 | cin>>n;
| ^
a.cc:21:33: error: 'res' was not declared in this scope
21 | res += 1 - sum;
| ^~~
a.cc:26:33: error: 'res' was not declared in this scope
26 | res += sum + 1;
| ^~~
a.cc:32:12: error: 'res' was not declared in this scope
32 | if(res < ans) ans = res;
| ^~~
a.cc:33:19: error: 'res' was not declared in this scope
33 | flag = 0, res = sum = 0;
| ^~~
|
s962686586 | p03739 | C++ | #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);
}
int ans1 = 0, ans2 = 0, sum1 = 0, sum2 = 0;
for (int i=0; i<N; i++) {
sum1 += a.at(i);
if (i%2 == 0 && sum <= 0) {
ans1 += 1-sum; //sumは負
sum1 = 1;
}
else if (i%2 != 0 && sum >= 0) {
ans1 += sum+1;
sum1 = -1;
}
}
for (int i=0; i<N; i++) {
sum2 += a.at(i);
if (i%2 == 0 && sum >= 0) {
ans2 += sum+1;
sum2 = -1;
}
else if (i%2 != 0 && sum <= 0) {
ans2 += 1-sum;
sum2 = 1;
}
}
cout << min(ans1, ans2) << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:14:25: error: 'sum' was not declared in this scope; did you mean 'sum2'?
14 | if (i%2 == 0 && sum <= 0) {
| ^~~
| sum2
a.cc:25:25: error: 'sum' was not declared in this scope; did you mean 'sum2'?
25 | if (i%2 == 0 && sum >= 0) {
| ^~~
| sum2
|
s391183419 | p03739 | C++ | #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);
}
int ans1 = 0, ans2 = 0, sum1 = 0, sum2 = 0;
for (int i=0; i<N; i++) {
sum += a.at(i);
if (i%2 == 0 && sum <= 0) {
ans1 += 1-sum; //sumは負
sum1 = 1;
}
else if (i%2 != 0 && sum >= 0) {
ans1 += sum+1;
sum1 = -1;
}
}
for (int i=0; i<N; i++) {
sum += a.at(i);
if (i%2 == 0 && sum >= 0) {
ans2 += sum+1;
sum2 = -1;
}
else if (i%2 != 0 && sum <= 0) {
ans2 += 1-sum;
sum2 = 1;
}
}
cout << min(ans1, ans2) << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:13:9: error: 'sum' was not declared in this scope; did you mean 'sum2'?
13 | sum += a.at(i);
| ^~~
| sum2
a.cc:24:9: error: 'sum' was not declared in this scope; did you mean 'sum2'?
24 | sum += a.at(i);
| ^~~
| sum2
|
s620697140 | p03739 | C++ | #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);
}
int ans1 = 0, ans2 = 0; sum = 0;
for (int i=0; i<N; i++) {
sum += a.at(i);
if (i%2 == 0 and sum <= 0) {
ans1 += -sum+1; //sumは負
sum = 1;
}
else if (i%2 == 1 and sum >= 0) {
ans1 += sum+1;
sum = -1;
}
}
sum = 0;
for (int i=0; i<N; i++) {
ans2 += a.at(i);
if (i%2 == 0 and sum >= 0) {
ans2 += sum+1;
sum = -1;
}
else if (i%2 == 1 and sum <= 0) {
ans2 += -sum+1;
sum = 1;
}
}
int ans = min(ans1, ans2);
cout << ans << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:11:29: error: 'sum' was not declared in this scope
11 | int ans1 = 0, ans2 = 0; sum = 0;
| ^~~
|
s449197702 | p03739 | C++ | #include <iostream>
#include <algorithm>
#include <string>
#define int long long
using namespace std;
int main() {
int n;
int A[100001];
cin >> n;
for(int i = 0; i < n; i++) {
cin >> A[i];
}
int sum = 0;
int counter = 0;
// 偶数番目が正
for(int i = 0; i < n; i++) {
sum += A[i];
if(i % 2 == 0) {
while(sum <= 0){
sum++;
counter++;
}
} else {
while(sum >= 0){
sum--;
counter++;
}
}
}
int counterNeg = 0;
sum = 0;
for(int i = 0; i < n; i++) {
sum += A[i];
if(i % 2 == 1) {
while(sum <= 0){
sum++;
counterNeg++;
}
} else {
while(sum >= 0){
sum--;
counterNeg++;
}
}
}
cout << min(counter, counterNeg) << endl;
return 0;
}
| cc1plus: error: '::main' must return 'int'
|
s060704035 | p03739 | C++ | #include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long
int main() {
int n;
int A[100001];
cin >> n;
for(int i = 0; i < n; i++) {
cin >> A[i];
}
int sum = 0;
int counter = 0;
// 偶数番目が正
for(int i = 0; i < n; i++) {
sum += A[i];
if(i % 2 == 0) {
while(sum <= 0){
sum++;
counter++;
}
} else {
while(sum >= 0){
sum--;
counter++;
}
}
}
int counterNeg = 0;
sum = 0;
for(int i = 0; i < n; i++) {
sum += A[i];
if(i % 2 == 1) {
while(sum <= 0){
sum++;
counterNeg++;
}
} else {
while(sum >= 0){
sum--;
counterNeg++;
}
}
}
cout << min(counter, counterNeg) << endl;
return 0;
}
| cc1plus: error: '::main' must return 'int'
|
s499948199 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
int main (int argc, char *argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
int n, a[100001];
cin >> n;
rep(i, n) {
cin >> a[i];
}
llong res_even = 0, sum_a = 0;
rep(i, n) {
sum_a += a[i];
if (i % 2 == 0 && sum_a <= 0) {
res_even += abs(sum_a) + 1;
sum_a = 1;
}
if (i % 2 == 1 && sum_a >= 0) {
res_even += sum_a + 1;
sum_a = -1;s
}
}
llong res_odd = 0;
sum_a = 0;
rep(i, n) {
sum_a += a[i];
if (i % 2 == 0 && sum_a >= 0) {
res_odd += sum_a + 1;
sum_a = -1;
}
if (i % 2 == 1 && sum_a <= 0) {
res_odd += abs(sum_a) + 1;
sum_a += 1;
}
}
cout << min(res_even, res_odd) << endl;
return 0;
} | a.cc: In function 'int main(int, char**)':
a.cc:29:24: error: 's' was not declared in this scope
29 | sum_a = -1;s
| ^
|
s782323627 | p03739 | C++ | #include "bits/stdc++.h"
#define readInt(x) scanf_s("%d", &x)
#define readStr(x) scanf("%s", x)
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmax(x, y) (x > (y) ? x : x = (y))
#define chmin(x, y) (x < (y) ? x : x = (y))
#define write(x) cout << (x) << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = INT32_MAX / 2;
const int MAX = 1e5 + 10;
int n;
int a[MAX];
int main()
{
readInt(n);
int sump = 0, sumn = 0;
ll cntp = 0, cntn = 0;
rep(i, n) {
cin >> a[i];
sump += a[i];
sumn += a[i];
if (i % 2) {
int r = max(sump + 1, 0);
sump -= r;
cntp += r;
r = max(1 - sumn, 0);
sumn += r;
cntn += r;
}
else {
int r = max(1 - sump, 0);
sump += r;
cntp += r;
r = max(sumn + 1, 0);
sumn -= r;
cntn += r;
}
}
write(min(cntp, cntn));
} | a.cc: In function 'int main()':
a.cc:2:20: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
2 | #define readInt(x) scanf_s("%d", &x)
| ^~~~~~~
a.cc:19:5: note: in expansion of macro 'readInt'
19 | readInt(n);
| ^~~~~~~
|
s786918566 | p03739 | C++ | #include <bits/stdc++.h>
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI acos(-1)
using ll = long long;
using ull = unsigned long long;
int main(int argc, char *argv[])
{
int n;
std::cin >> n;
std::vector<int> a(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
ll sum1 = 0;
ll ans1 = 0;
for (int i = 0; i < N; i++) {
sum1 += a[i];
if (i%2 == 0) {
if (sum <= 0) {
ans1 += -sum1 + 1;
sum1 = 1;
}
} else {
if (sum1 >= 0) {
ans1 += sum1 + 1;
sum1 = -1;
}
}
}
ll sum2 = 0;
ll ans2 = 0;
for (int i = 0; i < N; i++) {
sum2 += a[i];
if (i%2 == 0) {
if (sum >= 0) {
ans2 += sum2 + 1;
sum2 = -1;
}
} else {
if (sum2 <= 0) {
ans2 += -sum2 + 1;
sum2 = 1;
}
}
}
std::cout << std::min(ans1, ans2) << std::endl;
return 0;
} | a.cc: In function 'int main(int, char**)':
a.cc:22:25: error: 'N' was not declared in this scope
22 | for (int i = 0; i < N; i++) {
| ^
a.cc:26:17: error: 'sum' was not declared in this scope; did you mean 'sum1'?
26 | if (sum <= 0) {
| ^~~
| sum1
a.cc:40:25: error: 'N' was not declared in this scope
40 | for (int i = 0; i < N; i++) {
| ^
a.cc:44:17: error: 'sum' was not declared in this scope; did you mean 'sum2'?
44 | if (sum >= 0) {
| ^~~
| sum2
|
s849650034 | p03739 | C++ | #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <cmath>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl
//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)
int n;
vector<long long int> v;
int solve(int first_pon){
long long int pon = first_pon, sum = 0, result = 0;
REP(i,n){
sum += v[i];
if(pon>0&&sum>=0){
result += sum + 1;
sum = -1;
}else if(pon<0&&sum<=0){
result += (-sum) + 1;
sum = 1;
}
if(sum>0){
pon = 1;
}else{
pon = -1;
}
}
return result;
}
int main(){
cin >> n ;
v = vector<long long int>(n);
REP(i,n){
cin >> v[i];
}
cout << long long min(solve(1), solve(-1)) << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:47:13: error: expected primary-expression before 'long'
47 | cout << long long min(solve(1), solve(-1)) << endl;
| ^~~~
|
s927865618 | p03739 | C++ | #include<iostream>
#include<algorithm>
typedef long long lint;
using namespace std;
int main()
{
int n;
lint A[100010]={};
bool flag=false;
lint tmp,sum;
lint ans[]={0,0};
cin >> n;
for(int i=0;i<n;i++)
cin >> A[i];
if(A[0]==0)
{
flag=true;
A[0]=1;
ans[0]++;
}
tmp=0,sum=0;
for(int i=0;i<n;i++)
{
tmp=sum+A[i];
if(tmp==0)
{
ans[0]++;
//cout << i << ":" << 1 << endl;
if(A[i]>0)tmp=1;else tmp=-1;
}
else
{
if((tmp>0&&sum>0) || (tmp<0&&sum<0))
{
if(tmp>0)tmp=-1;else tmp=1;
//cout << i << ":" << ((tmp-sum)-A[i]) << endl;
ans[0]+=abs((tmp-sum)-A[i]);
}
}
sum=tmp;
}
if(flag)
{
A[0]=-1;
ans[1]++;
}
else
{
if(A[0]>0)A[0]=-1;elseA[0]=1;
ans[1]+=abs(A[0])+1;
}
tmp=0,sum=0;
for(int i=0;i<n;i++)
{
tmp=sum+A[i];
if(tmp==0)
{
ans[1]++;
//cout << i << ":" << 1 << endl;
if(A[i]>0)tmp=1;else tmp=-1;
}
else
{
if((tmp>0&&sum>0) || (tmp<0&&sum<0))
{
if(tmp>0)tmp=-1;else tmp=1;
//cout << i << ":" << ((tmp-sum)-A[i]) << endl;
ans[1]+=abs((tmp-sum)-A[i]);
}
}
sum=tmp;
}
cout << min(ans[0],ans[1]) << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:53:35: error: 'elseA' was not declared in this scope
53 | if(A[0]>0)A[0]=-1;elseA[0]=1;
| ^~~~~
|
s521264896 | p03739 | C++ | #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <bitset>
#include <map>
#include <climits>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> an(n);
for (int i = 0; i < n; ++i)
{
cin >> an[i];
}
int cnt_min = INT_MAX;
for (int j = 0; j < 2; ++j)
{
int sign = j == 0 ? -1 : 1;
int accum = an[0];
int cnt = 0;
if (accum * sign <= 0)
{
// accum + x = sign
auto x = sign - accum;
accum += x;
cnt += abs(x);
}
for (int i = 1; i < n; ++i)
{
auto new_accum = accum + an[i];
if (new_accum * accum >= 0)
{
// new_accum + x = sign
int x = -sign - new_accum;
new_accum += x;
cnt += abs(x);
an[i] += x;
}
int new_sign = new_accum > 0 ? 1 : -1;
accum = new_accum;
assert(new_sign == -sign);
sign = new_sign;
}
if (cnt < cnt_min)
{
cnt_min = cnt;
}
}
cout << cnt_min << endl;
// int accum = 0;
// int sign = 0;
// bool non_zero = true;
// int cnt = 0;
// for (int i = 0; i < n; ++i)
// {
// auto new_accum = accum + an[i];
// if (i == 0)
// {
// if (new_accum == 0)
// {
// int next_sign = an[1] > 0 ? 1 : -1;
// new_accum -= next_sign;
// ++cnt;
// an[0] = -next_sign;
// }
// accum = new_accum;
// sign = accum > 0 ? 1 : -1;
// }
// else
// {
// if (new_accum * accum >= 0)
// {
// // new_accum + x = sign
// // 2 + x = (-1) , x=-3
// int x = -sign - new_accum;
// new_accum += x;
// cnt += abs(x);
// an[i] += x;
// }
// int new_sign = new_accum > 0 ? 1 : -1;
// accum = new_accum;
// assert(new_sign == -sign);
// sign = new_sign;
// }
// }
// cout << cnt << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:50:13: error: 'assert' was not declared in this scope
50 | assert(new_sign == -sign);
| ^~~~~~
a.cc:10:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
9 | #include <climits>
+++ |+#include <cassert>
10 |
|
s357236683 | p03739 | C++ | #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <bitset>
#include <map>
#include <climits>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> an(n);
for (int i = 0; i < n; ++i)
{
cin >> an[i];
}
int accum = 0;
int sign = 0;
bool non_zero = true;
int cnt = 0;
for (int i = 0; i < n; ++i)
{
auto new_accum = accum + an[i];
if (i == 0)
{
if (new_accum == 0)
{
int next_sign = an[1] > 0 ? 1 : -1;
new_accum -= next_sign;
++cnt;
an[0] = -next_sign;
}
accum = new_accum;
sign = accum > 0 ? 1 : -1;
}
else
{
if (new_accum * accum >= 0)
{
// new_accum + x = -sign
int x = -sign - new_accum;
new_accum += x;
cnt += abs(x);
an[i] += x;
}
int new_sign = new_accum > 0 ? 1 : -1;
accum = new_accum;
assert(new_sign == -sign);
sign = new_sign;
}
}
cout << endl;
cout << cnt << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:54:13: error: 'assert' was not declared in this scope
54 | assert(new_sign == -sign);
| ^~~~~~
a.cc:10:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
9 | #include <climits>
+++ |+#include <cassert>
10 |
|
s045908362 | p03739 | C++ | #include<bits/stdc++.h>
using namespace std;
int main(){
long n;
cin >> n;
long a[n],sum = 0;
for(long i = 0;i < n;i++){
cin >> a[i];
}
long kekka = 0;
for(long i = 0;i < n;i++){
sum += a[i];
if(i % 2 == 0 && sum >= 0){
kekkka += sum + 1;
sum = -1;
}
if(i % 2 == 1 && sum <= 0){
kekka += -sum + 1;
sum = 1;
}
}
long result = 0;
sum = 0;
for(long i = 0;i < n;i++){
sum += a[i];
if(i % 2 == 0 && sum <= 0){
result += -sum + 1;
sum = 1;
}
if(i % 2 == 1 && sum >= 0){
result += sum + 1;
sum = -1;
}
}
cout << min(kekka,result) << endl;
} | a.cc: In function 'int main()':
a.cc:15:7: error: 'kekkka' was not declared in this scope; did you mean 'kekka'?
15 | kekkka += sum + 1;
| ^~~~~~
| kekka
|
s472725288 | p03739 | C++ | #include<bits/stdc++.h>
using namespace std
const int MAX_N = 1e5;
int N, a[MAX_N+5];
int solve(int next){
int s = 0, cnt = 0;
for(int i=0;i<N;i++){
s += a[i];
if(next==1 && s<=0){
cnt += next - s; s = 1;
}else if(next==-1 && s>=0){
cnt += s - next; s = -1;
}
next *= -1;
}
return cnt;
}
int main(){
cin >> N;
for(int i=0;i<N;i++) cin >> a[i];
cout << min(solve(1), solve(-1)) << endl;
return 0;
} | a.cc:2:20: error: expected ';' before 'const'
2 | using namespace std
| ^
| ;
3 |
4 | const int MAX_N = 1e5;
| ~~~~~
|
s160731978 | p03739 | C++ |
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <queue>
using namespace std;
int main(){
int n;
cin >> n;
int64_t sum = 0;
vector<int64_t> arr;
for (int i = 0; i < n; ++i) {
int64_t ai;
cin >> ai;
sum += ai;
arr.push_back(sum);
}
int64_t b1 = 0;
int64_t s1 = 0;
int64_t b2 = 0;
int64_t s2 = 0;
for (int i = 0; i < n; ++i) {
if (i % 2 == 0) {
b1 += max(0LL, 1 - arr[i]-s1);
s1 += max(0LL, 1 - arr[i]-s1);
b2 += max(0LL, arr[i] +s2+ 1);
s2 -= max(0LL, arr[i] +s2+ 1);
}
else {
b1 += max(0LL, arr[i] + s1 + 1);
s1 -= max(0LL, arr[i] + s1 + 1);
b2 += max(0LL, 1 - arr[i] - s2);
s2 += max(0LL, 1 - arr[i] - s2);
}
}
cout << min(b1, b2) << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:28:34: error: no matching function for call to 'max(long long int, __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type)'
28 | b1 += max(0LL, 1 - arr[i]-s1);
| ~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:62,
from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:28:34: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
28 | b1 += max(0LL, 1 - arr[i]-s1);
| ~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:28:34: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
28 | b1 += max(0LL, 1 - arr[i]-s1);
| ~~~^~~~~~~~~~~~~~~~~~~~
a.cc:29:34: error: no matching function for call to 'max(long long int, __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type)'
29 | s1 += max(0LL, 1 - arr[i]-s1);
| ~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:29:34: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
29 | s1 += max(0LL, 1 - arr[i]-s1);
| ~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:29:34: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
29 | s1 += max(0LL, 1 - arr[i]-s1);
| ~~~^~~~~~~~~~~~~~~~~~~~
a.cc:30:34: error: no matching function for call to 'max(long long int, __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type)'
30 | b2 += max(0LL, arr[i] +s2+ 1);
| ~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:30:34: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
30 | b2 += max(0LL, arr[i] +s2+ 1);
| ~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:30:34: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
30 | b2 += max(0LL, arr[i] +s2+ 1);
| ~~~^~~~~~~~~~~~~~~~~~~~
a.cc:31:34: error: no matching function for call to 'max(long long int, __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type)'
31 | s2 -= max(0LL, arr[i] +s2+ 1);
| ~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:31:34: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
31 | s2 -= max(0LL, arr[i] +s2+ 1);
| ~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:31:34: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
31 | s2 -= max(0LL, arr[i] +s2+ 1);
| ~~~^~~~~~~~~~~~~~~~~~~~
a.cc:34:34: error: no matching function for call to 'max(long long int, __gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type)'
34 | b1 += max(0LL, arr[i] + s1 + 1);
| ~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:34:34: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type' {aka 'long int'})
34 | b1 += max(0LL, arr[i] + s1 + 1);
| ~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:571 |
s368044228 | p03739 | C++ | #include<bits/stdc++.h>
int main(){
int n,chk;
long long ans=0;
scanf("%d %d",&n,&m);
vector<int> a(n);
for (auto&e:a) scanf("%d"&e);
chk=a[0];
for (int i=1;i<n;i++) {
if (i%2) {
chk+=a[i];
if (chk>=0) {
ans+=chk+1;
chk=-1;
}
} else {
chk+=a[i];
if (chk<=0) {
ans+=-1*chk+1;
chk=1;
}
}
}
print("%lld",ans);
return 0;
}
| a.cc: In function 'int main()':
a.cc:6:23: error: 'm' was not declared in this scope
6 | scanf("%d %d",&n,&m);
| ^
a.cc:7:5: error: 'vector' was not declared in this scope
7 | vector<int> a(n);
| ^~~~~~
a.cc:7:5: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
from /usr/include/c++/14/functional:64,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:428:11: note: 'std::vector'
428 | class vector : protected _Vector_base<_Tp, _Alloc>
| ^~~~~~
/usr/include/c++/14/vector:93:13: note: 'std::pmr::vector'
93 | using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
| ^~~~~~
a.cc:7:12: error: expected primary-expression before 'int'
7 | vector<int> a(n);
| ^~~
a.cc:8:17: error: 'a' was not declared in this scope
8 | for (auto&e:a) scanf("%d"&e);
| ^
a.cc:9:9: error: 'a' was not declared in this scope
9 | chk=a[0];
| ^
a.cc:25:5: error: 'print' was not declared in this scope; did you mean 'rint'?
25 | print("%lld",ans);
| ^~~~~
| rint
|
s595197106 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
typedef long long ll;
int main(){
int n;
cin >> n;
vector<int> a(n);
rep(i,n) cin >> a[i];
ll prevArraySum = a[0];
ll currentArraySum = a[0];
ll res = 0;
if(a[0] == 0){
res = 1;
prevArraySum = 1;
currentArraySum = 1;
FOR(i,1,n){
if(prevArraySum > 0){
currentArraySum = prevArraySum + a[i];
if(currentArraySum >= 0){
res += abs(-1 - currentArraySum);
prevArraySum = -1;
}else{
prevArraySum = currentArraySum;
}
}else{
currentArraySum = prevArraySum + a[i];
if(currentArraySum <= 0){
res += abs(1 - currentArraySum);
prevArraySum = 1;
}else{
prevArraySum = currentArraySum;
}
}
}
int res1 = res;
res = 1;
FOR(i,1,n){
if(prevArraySum > 0){
currentArraySum = prevArraySum + a[i];
if(currentArraySum >= 0){
res += abs(-1 - currentArraySum);
prevArraySum = -1;
}
}else{
currentArraySum = prevArraySum + a[i];
if(currentArraySum <= 0){
res += abs(1 - currentArraySum);
prevArraySum = 1;
}else{
prevArraySum = currentArraySum;
}
}
}
res = min(res,res1);
}else{
FOR(i,1,n){
if(prevArraySum > 0){
currentArraySum = prevArraySum + a[i];
if(currentArraySum >= 0){
res += abs(-1 - currentArraySum);
prevArraySum = -1;
}else{
prevArraySum = currentArraySum;
}
}else{
currentArraySum = prevArraySum + a[i];
if(currentArraySum <= 0){
res += abs(1 - currentArraySum);
prevArraySum = 1;
}else{
prevArraySum = currentArraySum;
}
}
}
}
cout << res << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:59:14: error: no matching function for call to 'min(ll&, int&)'
59 | res = min(res,res1);
| ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:59:14: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
59 | res = min(res,res1);
| ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:59:14: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
59 | res = min(res,res1);
| ~~~^~~~~~~~~~
|
s901809520 | p03739 | C++ | #include <iostream>
#include <vector>
using namespace std;
int main()
{
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; i++) {
cin >> a[i];
}
ll ans = 0;
while (ans < N && a[ans] == 0) ans++;
ll sum;
if (ans == 0) sum = a[0];
else if (ans < N && a[ans + 1] > 0) sum = -1;
else sum = 1;
for (int i = ans + 1; i < N; i++) {
//cout << sum << ' ' << (sum + a[i]) << endl;
if (sum * (sum + a[i]) >= 0) {
if (sum + a[i] >= 0) {
// sum > 0, sum + a[i] >= 0
// sum + a[i] = -1になるように変える
// sum + (-sum - 1) = -1
// a[i] -> -sum - 1
ans += abs(sum + a[i] + 1);
//cout << "cost : " << abs(sum + a[i] + 1) << endl;
a[i] = -sum - 1;
} else {
// sum < 0, sum + a[i] < 0
// sum + a[i] = 1 になるように変える
// sum + (-sum + 1) = 1
// a[i] -> -sum + 1
ans += abs(sum + a[i] - 1);
//cout << "cost : " << abs(sum + a[i] - 1) << endl;
a[i] = -sum + 1;
}
}
sum += a[i];
}
cout << ans << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:15:3: error: 'll' was not declared in this scope
15 | ll ans = 0;
| ^~
a.cc:16:10: error: 'ans' was not declared in this scope; did you mean 'abs'?
16 | while (ans < N && a[ans] == 0) ans++;
| ^~~
| abs
a.cc:18:5: error: expected ';' before 'sum'
18 | ll sum;
| ^~~~
| ;
a.cc:19:7: error: 'ans' was not declared in this scope; did you mean 'abs'?
19 | if (ans == 0) sum = a[0];
| ^~~
| abs
a.cc:19:17: error: 'sum' was not declared in this scope
19 | if (ans == 0) sum = a[0];
| ^~~
a.cc:20:39: error: 'sum' was not declared in this scope
20 | else if (ans < N && a[ans + 1] > 0) sum = -1;
| ^~~
a.cc:21:8: error: 'sum' was not declared in this scope
21 | else sum = 1;
| ^~~
a.cc:23:16: error: 'ans' was not declared in this scope; did you mean 'abs'?
23 | for (int i = ans + 1; i < N; i++) {
| ^~~
| abs
a.cc:25:9: error: 'sum' was not declared in this scope
25 | if (sum * (sum + a[i]) >= 0) {
| ^~~
a.cc:45:5: error: 'sum' was not declared in this scope
45 | sum += a[i];
| ^~~
a.cc:47:11: error: 'ans' was not declared in this scope; did you mean 'abs'?
47 | cout << ans << endl;
| ^~~
| abs
|
s762128932 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
ll n, ans = 1ll << 60;
ll a[maxx];
int main() {
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
int flag = 0;
LL sum = 0;
LL res = 0;
for(int i = 1; i <= n; i++) {
sum += a[i];
if(flag == 0){
if(sum <= 0) {
res = res + 1 - sum;
sum = 1;
}
}
else {
if(sum >= 0){
res = res + sum + 1;
sum = -1;
}
}
flag ^= 1;
}
ans = min(ans, res);
res = 0;
sum = 0;
flag = 0;
for(int i = 1; i <= n; i++) {
sum += a[i];
if(flag == 1){
if(sum <= 0) {
res = res + 1 - sum;
sum = 1;
}
}
else {
if(sum >= 0){
res = res + sum + 1;
sum = -1;
}
}
flag ^= 1;
}
ans = min(ans, res);
cout << ans << endl;
} | a.cc: In function 'int main()':
a.cc:12:9: error: 'LL' was not declared in this scope; did you mean 'll'?
12 | LL sum = 0;
| ^~
| ll
a.cc:13:11: error: expected ';' before 'res'
13 | LL res = 0;
| ^~~~
| ;
a.cc:15:17: error: 'sum' was not declared in this scope
15 | sum += a[i];
| ^~~
a.cc:18:33: error: 'res' was not declared in this scope
18 | res = res + 1 - sum;
| ^~~
a.cc:24:33: error: 'res' was not declared in this scope
24 | res = res + sum + 1;
| ^~~
a.cc:30:24: error: 'res' was not declared in this scope
30 | ans = min(ans, res);
| ^~~
a.cc:32:9: error: 'sum' was not declared in this scope
32 | sum = 0;
| ^~~
|
s918938696 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
long long s1,s2,c1,c2,a;
for(int i=1; i <= n; i++){
cin >> a;
s1 += a;
s2 += a;
if(i % 2){ //奇数桁目
if (s1 <= 0) c1 += 1 - s1,s1 = 1; //総和が負
if (s2 >= 0) c2 += 1 + s2,s2 = -1; //総和が正
}
else { //偶数桁目
if (s1 >= 0) c1 += 1 + s1,s1 = -1; //同上
if (s2 <= 0) c2 += 1 - s2,s2 = 1;
}
}
cout << min(c1, c2) << endl;
return 0;
} | a.cc:10:19: error: extended character is not valid in an identifier
10 | if(i % 2){ //奇数桁目
| ^
a.cc:14:15: error: extended character is not valid in an identifier
14 | else { //偶数桁目
| ^
a.cc:15:47: error: extended character is not valid in an identifier
15 | if (s1 >= 0) c1 += 1 + s1,s1 = -1; //同上
| ^
a.cc: In function 'int main()':
a.cc:10:19: error: '\U00003000' was not declared in this scope
10 | if(i % 2){ //奇数桁目
| ^~
a.cc:14:15: error: '\U00003000' was not declared in this scope
14 | else { //偶数桁目
| ^~
a.cc:15:49: error: expected ';' before 'if'
15 | if (s1 >= 0) c1 += 1 + s1,s1 = -1; //同上
| ^
| ;
16 | if (s2 <= 0) c2 += 1 - s2,s2 = 1;
| ~~
|
s389716527 | p03739 | C++ | #include<iostream>
using namespace std;
int main(){
int n, ans=0, d=0;
cin >> n;
int a[n];
cin >> a[0];
int sum[0]=a[0];
for(int i=1; i<n; i++){
cin >> a[i];
sum[i] = sum[i-1] + a[i];
}
for(int i=1; i<n; i++){
if((sum[i-1]+d)*(sum[i]+d)>=0){
d -= sum[i]+1;
ans += abs(sum[i]+1);
}
}
cout << ans << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:8:17: error: array must be initialized with a brace-enclosed initializer
8 | int sum[0]=a[0];
| ~~~^
|
s707638255 | p03739 | Java | import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.function.IntFunction;
import java.util.function.Supplier;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner();
int n=scanner.nextInt();
long[] a=new long[n+1];
for(int i=1;i<=n;i++){
a[i]=scanner.nextInt();
}
Arrays.parallelPrefix(a,(c,b)->c+b);
//put(Arrays.toString(a));
long ans=0;
long ruiseki=0;
for(int i=1;i<=n;i++){
//put(format("i=%d",i));
//put(format("ruiseki=%d",ruiseki));
long val=a[i]+ruiseki;
long val_=a[i-1]+ruiseki;
//put(format("val=%d",val));
//put(format("val_=%d",val_));
if(val==0){
int bit=a[i-1]/Math.abs(a[i-1]);
ruiseki+=bit*1;
ans+=Math.abs(bit);
}else if(val>0&&val_>0){
ruiseki-=(val+1);
ans+=Math.abs(val+1);
}else if(val<0&&val_<0){
ruiseki+=Math.abs(val)+1;
ans+=Math.abs(val)+1;
}
//put(ans);
//put();
}
put(ans);
}
public static void print(Object object){
System.out.print(object);
}
public static void put(Object object) {
System.out.println(object);
}
public static void put(){
System.out.println();
}
public static String format(String string, Object... args) {
return String.format(string, args);
}
}
final class Scanner {
private final InputStream in = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
} else {
ptr = 0;
try {
buflen = in.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0) {
return false;
}
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[ptr++];
else
return -1;
}
private boolean isPrintableChar(int c) {
return 33 <= c && c <= 126;
}
public boolean hasNext() {
while (hasNextByte() && !isPrintableChar(buffer[ptr]))
ptr++;
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while (true) {
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
} else if (b == -1 || !isPrintableChar(b)) {
return minus ? -n : n;
} else {
throw new NumberFormatException();
}
b = readByte();
}
}
public int nextInt() {
long nl = nextLong();
if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
throw new NumberFormatException();
return (int) nl;
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
final class Pair {
final public int x, y;
Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int hashCode() {
return x+y;
}
@Override
public boolean equals(Object obj) {
boolean result=super.equals(obj);
if(obj.getClass()!=this.getClass()){
return false;
}
Pair pair=(Pair)obj;
if(this.x==pair.x&&this.y==pair.y) return true;
return false;
}
@Override
public String toString() {
return String.format("(%d,%d)", x, y);
}
}
final class Tuple<T,V>{
//immutabl1でないことに注意(T,Vがmutableの場合変更可能)
final public T t;
final public V v;
Tuple(T t,V v){
this.t=t;
this.v=v;
}
@Override
public int hashCode() {
return (t.hashCode()+v.hashCode());
}
@Override
public boolean equals(Object obj) {
if(obj.getClass()!=this.getClass()){
return false;
}
Tuple<T,V> tuple=(Tuple)obj;
return tuple.t.equals(this.t)&&tuple.v.equals(this.v);
}
@Override
public String toString() {
return String.format("<Tuple>=<%s,%s>",t,v);
}
}
final class LowerBoundComparator<T extends Comparable<? super T>>
implements Comparator<T>
{
public int compare(T x, T y)
{
return (x.compareTo(y) >= 0) ? 1 : -1;
}
}
final class UpperBoundComparator<T extends Comparable<? super T>>
implements Comparator<T>
{
public int compare(T x, T y)
{
return (x.compareTo(y) > 0) ? 1 : -1;
}
}
final class Util {
static long gcd(long a,long b){
if(a%b==0)return b;
return gcd(b,a%b);
}
static long lcm(long a,long b){
long gcd=gcd(a,b);
long result=b/gcd;
return a*result;
}
static int kaijoMod(int n,int mod){
if(n<1) return -1;
long result=1;
for(int i=n;i>1;i--){
result*=i;
result%=mod;
}
return (int)result;
}
static <T extends Comparable> Map<T,Integer> count(List<T> list){
//副作用
Collections.sort(list);
Map<T,Integer> result=new HashMap<>();
int l=0,r=0;
while(l<list.size()){
while(r<list.size()-1&&list.get(r).equals(r+1)){
r++;
}
result.put(list.get(r),r-l+1);
r++;
l=r;
}
return result;
}
static Map<Integer,Integer> count(int[] array){
//副作用
Arrays.sort(array);
Map<Integer,Integer> result=new HashMap<>();
int l=0,r=0;
while(l<array.length){
while(r<array.length-1&&array[r]==array[r+1]){
r++;
}
result.put(array[l],r-l+1);
r++;
l=r;
}
return result;
}
static String toStringBWS(Iterable iterable){
Iterator ite=iterable.iterator();
return toStringBWS(ite);
}
static String toStringBWS(Iterator ite){
StringBuilder sb=new StringBuilder();
sb.append(ite.next());
while(ite.hasNext()){
sb.append(" ");
sb.append(ite.next());
}
return sb.toString();
}
static String toStringBWS(int[] array){
StringBuilder sb=new StringBuilder();
for(int i=0;i<array.length-1;i++){
sb.append(array[i]);
sb.append(" ");
}
sb.append(array[array.length-1]);
return sb.toString();
}
static String toStringBWS(long[] array){
StringBuilder sb=new StringBuilder();
for(int i=0;i<array.length-1;i++){
sb.append(array[i]);
sb.append(" ");
}
sb.append(array[array.length-1]);
return sb.toString();
}
}
| Main.java:30: error: incompatible types: possible lossy conversion from long to int
int bit=a[i-1]/Math.abs(a[i-1]);
^
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
|
s435882480 | p03739 | C++ | #include<cstdio>
using namespace std;
int main(){
int n, d, a = 0, b = 0, cnta = 0, cntb = 0, i, ans;
scnaf("%d", &n);
for(i = 0; i < n; i++){
scanf("%d", &d);
a += d; b += d;
if(i%2){
if(a > -1){cnta += a + 1; a = -1;}
if(b < 1){cntb += 1 - b; b = 1;}
}else{
if(b > -1){cntb += b + 1; b = -1;}
if(a < 1){cnta += 1 - a; a = 1;}
}
}
ans = (cnta > cntb) ? cnta : cntb;
cout << ans << endl;
} | a.cc: In function 'int main()':
a.cc:6:3: error: 'scnaf' was not declared in this scope; did you mean 'scanf'?
6 | scnaf("%d", &n);
| ^~~~~
| scanf
a.cc:19:3: error: 'cout' was not declared in this scope
19 | cout << ans << endl;
| ^~~~
a.cc:2:1: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
1 | #include<cstdio>
+++ |+#include <iostream>
2 | using namespace std;
a.cc:19:18: error: 'endl' was not declared in this scope
19 | cout << ans << endl;
| ^~~~
a.cc:2:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
1 | #include<cstdio>
+++ |+#include <ostream>
2 | using namespace std;
|
s398836705 | p03739 | C++ | include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a)
#define lcoutln(a)
#define lcerr(a)
#define lcerrln(a)
#endif
vector<int> a;
int N;
signed main()
{
cin >> N;
rep(i, N) {
CIN(int, t);
a.PB(t);
}
int res = 0;
int cnt = 0;
int sum = 0;
rep(i, N) {
sum += a[i];
if (sum <= 0) {
cnt += -sum + 1;
sum = 1;
}
i++;
if (i == N) break;
sum += a[i];
if (sum >= 0) {
cnt += sum + 1;
sum = -1;
}
}
res = cnt;
sum = 0;
cnt = 0;
rep (i, N) {
sum += a[i];
if (sum >= 0) {
cnt += sum + 1;
sum = -1;
}
i++;
if (i == N) break;
sum += a[i];
if (sum <= 0) {
cnt += -sum + 1;
sum = 1;
}
}
res = min(res, cnt);
cout << res << endl;
} | a.cc:1:1: error: 'include' does not name a type
1 | include <bits/stdc++.h>
| ^~~~~~~
a.cc:34:1: error: 'vector' does not name a type
34 | vector<int> a;
| ^~~~~~
a.cc: In function 'int main()':
a.cc:39:9: error: 'cin' was not declared in this scope
39 | cin >> N;
| ^~~
a.cc:42:17: error: 'a' was not declared in this scope
42 | a.PB(t);
| ^
a.cc:48:24: error: 'a' was not declared in this scope
48 | sum += a[i];
| ^
a.cc:65:24: error: 'a' was not declared in this scope
65 | sum += a[i];
| ^
a.cc:78:15: error: 'min' was not declared in this scope; did you mean 'main'?
78 | res = min(res, cnt);
| ^~~
| main
a.cc:79:9: error: 'cout' was not declared in this scope; did you mean 'lcout'?
79 | cout << res << endl;
| ^~~~
| lcout
a.cc:79:24: error: 'endl' was not declared in this scope
79 | cout << res << endl;
| ^~~~
|
s181225304 | p03739 | C++ | #include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
signed main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int n; cin >> n;
int a[n];
rep(i, n) cin >> a[i];
int ans1 = 0, ans2 = 0;
int sum1 = 0, sum2 = 0;
rep(i, n) {
sum1 += a[i];
sum2 += a[i];
if (i % 2 == 0) {
ans1 += max(0, -sum1 + 1);
ans2 += max(0, sum2+ 1);
sum1 += max(0, -sum1 + 1);
sum2 -= max(0, sum2 + 1);
}
else {
ans1 += max(0, sum1 + 1);
ans2 += max(0, -sum2 + 1);
sum1 -= max(0, sum1 + 1);
sum2 += max(0, -sum2 + 1);
}
//cout << sum1 << " " << sum2 << endl;
}
cout << min(ans1, ans2) << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:28:36: error: no matching function for call to 'max(int, long long int)'
28 | ans1 += max(0, -sum1 + 1);
| ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:28:36: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
28 | ans1 += max(0, -sum1 + 1);
| ~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:28:36: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
28 | ans1 += max(0, -sum1 + 1);
| ~~~^~~~~~~~~~~~~~
a.cc:29:36: error: no matching function for call to 'max(int, long long int)'
29 | ans2 += max(0, sum2+ 1);
| ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:29:36: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
29 | ans2 += max(0, sum2+ 1);
| ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:29:36: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
29 | ans2 += max(0, sum2+ 1);
| ~~~^~~~~~~~~~~~
a.cc:30:36: error: no matching function for call to 'max(int, long long int)'
30 | sum1 += max(0, -sum1 + 1);
| ~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:30:36: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
30 | sum1 += max(0, -sum1 + 1);
| ~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:30:36: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
30 | sum1 += max(0, -sum1 + 1);
| ~~~^~~~~~~~~~~~~~
a.cc:31:36: error: no matching function for call to 'max(int, long long int)'
31 | sum2 -= max(0, sum2 + 1);
| ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:31:36: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
31 | sum2 -= max(0, sum2 + 1);
| ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:31:36: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
31 | sum2 -= max(0, sum2 + 1);
| ~~~^~~~~~~~~~~~~
a.cc:34:36: error: no matching function for call to 'max(int, long long int)'
34 | ans1 += max(0, sum1 + 1);
| ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:34:36: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
34 | ans1 += max(0, sum1 + 1);
| ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:34:36: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
34 | ans1 += max(0, sum1 + 1);
| ~~~^~~~~~~~~~~~~
a.cc:35:36: error: no matching function for call to 'max(int, long long int)'
35 | ans2 += max(0, -sum2 + 1);
| ~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:35:36: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
35 | ans2 += max(0, -sum2 + 1);
|
s054557640 | p03739 | C++ | //Sequence.cpp (C)
#include <iostream>
using namespace std;
long long ans(int n, int*, int change);
int main(){
int n;
int a[110000];
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
long long pAns,nAns;
pAns = ans(n,a,1);
nAns = ans(n,a,-1);
printf("%d\n",min(pAns,nAns));
}
int ans(int n, int *a, int change){
long long Ans = 0;
long long sum = 0;
for(int i = 0; i < n; i++){
sum += a[i];
switch (change) {
case -1:
if(sum > -1) Ans += 1 + sum, sum = -1;
change *= -1;
break;
case 1:
if(sum < 1) Ans += 1 - sum, sum = 1;
change *= -1;
break;
}
}
return Ans;
}
| a.cc:18:5: error: ambiguating new declaration of 'int ans(int, int*, int)'
18 | int ans(int n, int *a, int change){
| ^~~
a.cc:5:11: note: old declaration 'long long int ans(int, int*, int)'
5 | long long ans(int n, int*, int change);
| ^~~
|
s512666543 | p03739 | C++ | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n; cin >> n;
vector<int> a(n + 1); for (int i = 1; i <= n; i++) cin >> a[i];
vector<int> a1; a1 = a;
long long int sum1 = 0, ans1 = ;
for (int i = 1; i <= n; i++) {
sum1 += a1[i];
if (i % 2 == 1 && sum1 <= 0) {
int plus = 1 - sum1;
sum1 = 1;
ans1 += plus;
continue;
} if (i % 2 == 0 && sum1 >= 0) {
int minus = 1 + sum1;
sum1 = -1;
ans1 += minus;
}
}
vector<int> a2; a2 = a;
long long int sum2 = 0, ans2 = 0;
for (int i = 1; i <= n; i++) {
sum2 += a2[i];
if (i % 2 == 1 && sum2 >= 0) {
int minus = 1 + sum2;
sum2 = -1;
ans2 += minus;
continue;
} else if (i % 2 == 0 && sum2 <= 0) {
int plus = 1 - sum2;
sum2 = 1;
ans2 += plus;
}
}
cout << min(ans1, ans2) << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:10:34: error: expected primary-expression before ';' token
10 | long long int sum1 = 0, ans1 = ;
| ^
|
s390380247 | p03739 | C++ | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n; cin >> n;
vector<int> a(n + 1); for (int i = 1; i <= n; i++) cin >> a[i];
vector<int> a1; a1 = a;
long long int sum1 = 0, ans1 = ;;
for (int i = 1; i <= n; i++) {
sum1 += a1[i];
if (i % 2 == 1 && sum1 <= 0) {
int plus = 1 - sum1;
sum1 = 1;
ans1 += plus;
continue;
} if (i % 2 == 0 && sum1 >= 0) {
int minus = 1 + sum1;
sum1 = -1;
ans1 += minus;
}
}
vector<int> a2; a2 = a;
long long int sum2 = 0, ans2 = 0;
for (int i = 1; i <= n; i++) {
sum2 += a2[i];
if (i % 2 == 1 && sum2 >= 0) {
int minus = 1 + sum2;
sum2 = -1;
ans2 += minus;
continue;
} else if (i % 2 == 0 && sum2 <= 0) {
int plus = 1 - sum2;
sum2 = 1;
ans2 += plus;
}
}
cout << min(ans1, ans2) << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:10:34: error: expected primary-expression before ';' token
10 | long long int sum1 = 0, ans1 = ;;
| ^
|
s688199118 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> vector;
long long temp;
for(int i=0; i<n; i++) {
cin >> temp;
vector.push_back(temp);
}
long long answer1=0;
long long answer2=0;
long long sum1=0;
long long sum2=0;
for(int i=0; i<n; i++) {
if(i == 0) {
if(vector[0] > 0)
sum1 = vector[0]; //初項
else {
sum1 = 1;
answer += abs(1-vector[0]);
}
}
else if(sum1 < 0) {
if(sum1 + vector[i] > 0){ //和の符号がデフォルトで異なるとき
// answer -> そのまま
sum1 += vector[i];
}
else {
answer1 += abs((-1)*sum1+1 - vector[i]); // vector[i] -> -sum1+1 までincrimentすると和は1
sum1 = 1;
}
}
else {
if(sum1 + vector[i] < 0) {
//answer->そのまま
sum1 += vector[i];
}
else {
answer1 += abs((-1)*sum1-1 - vector[i]); // vector[i] -> -sum1-1 までincrimentすると和は-1
sum1 = -1;
}
}
}
for(int i=0; i<n; i++) {
if(i==0) {
if(vector[0] > 0) {
sum2 = -1;
answer2 += abs(-1-vector[0]);
}
else {
sum2 = vector[0];
}
}
else if(sum2 < 0) {
if(sum2 + vector[i] > 0){ //和の符号がデフォルトで異なるとき
// answer-> そのまま
sum2 += vector[i];
}
else {
answer2 += abs((-1)*sum2+1 - vector[i]); // vector[i] -> -sum1+1 までincrimentすると和は1
sum2 = 1;
}
}
else {
if(sum2 + vector[i] < 0) {
//answer->そのまま
sum2 += vector[i];
}
else {
answer2 += abs((-1)*sum2-1 - vector[i]); // vector[i] -> -sum1-1 までincrimentすると和は-1
sum2 = -1;
}
}
}
cout << min(answer1,answer2) << endl;
}
| a.cc: In function 'int main()':
a.cc:27:9: error: 'answer' was not declared in this scope; did you mean 'answer2'?
27 | answer += abs(1-vector[0]);
| ^~~~~~
| answer2
|
s599981525 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> vector;
long long temp;
for(int i=0; i<n; i++) {
cin >> temp;
vector.push_back(temp);
}
long long answer1=0;
long long answer2=0;
long long sum1=0;
long long sum2=0;
for(int i=0; i<n; i++) {
if(i == 0) {
sum1 = vector[0]; //初項
}
else if(sum1 < 0) {
if(sum1 + vector[i] > 0){ //和の符号がデフォルトで異なるとき
// answer -> そのまま
sum1 += vector[i];
}
else {
answer1 += abs((-1)*sum1+1 - vector[i]); // vector[i] -> -sum1+1 までincrimentすると和は1
sum1 = 1;
}
}
else {
if(sum1 + vector[i] < 0) {
//answer->そのまま
sum1 += vector[i];
}
else {
answer1 += abs((-1)*sum1-1 - vector[i]); // vector[i] -> -sum1-1 までincrimentすると和は-1
sum1 = -1;
}
}
}
for(int i=0; i<n; i++) {
if(i==0) {
if(vector[0] > 0) {
sum2 = -1;
answer2 += abs(-1-vector[0]);
}
else {
sum2 = 1;
answer2 += abs(1-vector[0]);
}
}
else if(sum2 < 0) {
if(sum2 + vector[i] > 0){ //和の符号がデフォルトで異なるとき
// answer-> そのまま
sum2 += vector[i];
}
else {
answer2 += abs((-1)*sum2+1 - vector[i]); // vector[i] -> -sum1+1 までincrimentすると和は1
sum2 = 1;
}
}
else {
if(sum2 + vector[i] < 0) {
//answer->そのまま
sum2 += vector[i];
}
else {
answer2 += abs((-1)*sum2-1 - vector[i]); // vector[i] -> -sum1-1 までincrimentすると和は-1
sum2 = -1;
}
}
cout << min(answer1,answer2) << endl;
}
| a.cc: In function 'int main()':
a.cc:81:4: error: expected '}' at end of input
81 | }
| ^
a.cc:4:12: note: to match this '{'
4 | int main() {
| ^
|
s062601921 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> vector;
long long temp;
for(int i=0; i<n; i++) {
cin >> temp;
vector.push_back(temp);
}
long long answer1=0;
long long answer2=0;
long long sum1=0;
long long sum2=0;
for(int i=0; i<n; i++) {
if(i == 0) {
sum1 = vector[0]; //初項
}
else if(sum1 < 0) {
if(sum1 + vector[i] > 0){ //和の符号がデフォルトで異なるとき
// answer -> そのまま
sum1 += vector[i];
}
else {
answer1 += abs((-1)*sum1+1 - vector[i]); // vector[i] -> -sum1+1 までincrimentすると和は1
sum1 = 1;
}
}
else {
if(sum1 + vector[i] < 0) {
//answer->そのまま
sum1 += vector[i];
}
else {
answer1 += abs((-1)*sum1-1 - vector[i]); // vector[i] -> -sum1-1 までincrimentすると和は-1
sum1 = -1;
}
}
}
for(int i=0; i<n; i++) {
if(i==0) {
if(vector[0] > 0) {
sum2 = -1;
answer2 += abs(-1-vector[0]);
}
else {
sum2 = 1;
answer2 += abs(1-vector[0]);
}
}
}
else if(sum2 < 0) {
if(sum2 + vector[i] > 0){ //和の符号がデフォルトで異なるとき
// answer-> そのまま
sum2 += vector[i];
}
else {
answer2 += abs((-1)*sum2+1 - vector[i]); // vector[i] -> -sum1+1 までincrimentすると和は1
sum2 = 1;
}
}
else {
if(sum2 + vector[i] < 0) {
//answer->そのまま
sum2 += vector[i];
}
else {
answer2 += abs((-1)*sum2-1 - vector[i]); // vector[i] -> -sum1-1 までincrimentすると和は-1
sum2 = -1;
}
}
cout << min(answer1,answer2) << endl;
}
| a.cc: In function 'int main()':
a.cc:58:3: error: 'else' without a previous 'if'
58 | else if(sum2 < 0) {
| ^~~~
a.cc:59:24: error: 'i' was not declared in this scope
59 | if(sum2 + vector[i] > 0){ //和の符号がデフォルトで異なるとき
| ^
a.cc:69:24: error: 'i' was not declared in this scope
69 | if(sum2 + vector[i] < 0) {
| ^
|
s992510017 | p03739 | C++ | #include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int inf = 1e9;
int main() {
int n; cin >> n;
vector<int> a(n);
for(int i=0; i<n; i++) cin >> a[i];
int ans = inf;
long long int tmp = 0;
long long int cnt = 0;
for(int i=0; i<n; i++){
tmp += a[i];
if( i % 2 == 0 && tmp <= 0 ){
cnt += (1 - tmp);
tmp = 1;
}else if( i % 2 == 1 && tmp >= 0 ){
cnt += (1 + tmp);
tmp = -1;
}
}
ans = min(ans, cnt);
tmp = 0;
cnt = 0;
for(int i=0; i<n; i++){
tmp += a[i];
if( i % 2 == 1 && tmp <= 0 ){
cnt += (1 - tmp);
tmp = 1;
}else if( i % 2 == 0 && tmp >= 0 ){
cnt += (1 + tmp);
tmp = -1;
}
}
ans = min(ans, cnt);
cout << ans << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:35:12: error: no matching function for call to 'min(int&, long long int&)'
35 | ans = min(ans, cnt);
| ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:35:12: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
35 | ans = min(ans, cnt);
| ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:35:12: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
35 | ans = min(ans, cnt);
| ~~~^~~~~~~~~~
a.cc:48:12: error: no matching function for call to 'min(int&, long long int&)'
48 | ans = min(ans, cnt);
| ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:48:12: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
48 | ans = min(ans, cnt);
| ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:48:12: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
48 | ans = min(ans, cnt);
| ~~~^~~~~~~~~~
|
s121502514 | p03739 | C++ | #include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
int a[N+2];
for(int i=1;i<=N;i++){
cin >> a[i];
}
int cnt1=0,cnt2=0;
sum=0;
for(int i=1,s=1;i<=N;i++,s*=-1){
sum+=a[i];
if(sum*s<=0) cnt1+=abs(sum-s),sum=s;
}
sum=0;
for(int i=1,s=-1;i<=N;i++,s*=-1){
sum+=a[i];
if(sum*s<=0) cnt2+=abs(sum-s),sum=s;
}
cout << min(cnt1,cnt2) << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:31:3: error: 'sum' was not declared in this scope
31 | sum=0;
| ^~~
|
s757331796 | p03739 | C++ | #include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
int a[N+2];
for(int i=1;i<=N;i++){
cin >> a[i];
}
cnt1=0,cnt2=0;
sum=0;
for(int i=1,s=1;i<=N;i++,s*=-1){
sum+=a[i];
if(sum*s<=0) cnt1+=abs(sum-s),sum=s;
}
sum=0;
for(int i=1,s=-1;i<=N;i++,s*=-1){
sum+=a[i];
if(sum*s<=0) cnt2+=abs(sum-s),sum=s;
}
cout << min(cnt1,cnt2) << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:30:3: error: 'cnt1' was not declared in this scope
30 | cnt1=0,cnt2=0;
| ^~~~
a.cc:30:10: error: 'cnt2' was not declared in this scope
30 | cnt1=0,cnt2=0;
| ^~~~
a.cc:31:3: error: 'sum' was not declared in this scope
31 | sum=0;
| ^~~
|
s341789444 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
#define forx(i,a,b) for(int i=(a);i<(b);i++)
#define rep(j,n) for(int j=0;j<(n);j++)
typedef long long ll;
int main()
{
int n,ansa=0,ansb=0,suma=0,sumb=0;
cin>>n;
rep(i,n){
int a,b;
cin>>b;
a=b;
if(i%2==0){
if(suma+a<=0){
ansa=1-a-suma
a=1-suma;
}
if(sumb+b>=0){
ansb=sumb+b+1;
b=-1-sumb;
}
}
else{
if(suma+a>=0){
ansa=suma+a+1;
a=-1-suma;
}
if(sumb+b<=0){
ansb=1-b-sumb;
b=1-sumb;
}
}
suma+=a;
sumb+=b;
}
cout<<min(ansa,ansb)<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:21:22: error: expected ';' before 'a'
21 | ansa=1-a-suma
| ^
| ;
22 | a=1-suma;
| ~
|
s862212213 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
#define forx(i,a,b) for(int i=(a);i<(b);i++)
#define rep(j,n) for(int j=0;j<(n);j++)
typedef long long ll;
int main()
{
int n,ansa=0,ansb=0,suma=0;sumb=0,cin>>n;
bool plus=true;
rep(i,n){
int a,b;
cin>>b;
a=b;
while(plus&&suma+a<=0){
a++;
ansa++;
}
while(!plus&&suma+a>=0){
a--;
ansa++;
}
while(plus&&sumb+b>=0){
b++;
ansb++;
}
while(!plus&&sumb+b<=0){
b--;
ansb++;
}
suma+=a;
sumb+=b;
plus=!plus;
}
cout<<min(ansa,ansb)<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:10:32: error: 'sumb' was not declared in this scope; did you mean 'suma'?
10 | int n,ansa=0,ansb=0,suma=0;sumb=0,cin>>n;
| ^~~~
| suma
|
s400940927 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
#define forx(i,a,b) for(int i=(a);i<(b);i++)
#define rep(j,n) for(int j=0;j<(n);j++)
typedef long long ll;
int main()
{
int n,ansa=0,ansb=0,suma=0;sumb=0,cin>>n;
bool plus=true;
rep(i,n){
int a,b;
cin>>b;
a=b;
while(plus&&suma+a<=0){
a++;
ansa++;
}
while(!plus&&suma+a>=0){
a--;
ansa++;
}
while(plus&&sumb+b>=0){
b++;
ansb++;
}
while(!plus&&sumb+b<=0){
b--;
ansb++;
}
suma+=a;
sumb+=b;
plus=!plus;
}
cout<<min(ansa,ansb)<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:10:32: error: 'sumb' was not declared in this scope; did you mean 'suma'?
10 | int n,ansa=0,ansb=0,suma=0;sumb=0,cin>>n;
| ^~~~
| suma
|
s932090730 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
#define forx(i,a,b) for(int i=(a);i<(b);i++)
#define rep(j,n) for(int j=0;j<(n);j++)
typedef long long ll;
int main()
{
int n,ansa=0,ansb=0,suma=0;sumb=0;
cin>>n;
bool plus=true;
rep(i,n){
int a,b;
cin>>b;
a=b;
while(plus&&suma+a<=0){
a++;
ansa++;
}
while(!plus&&suma+a>=0){
a--;
ansa++;
}
while(plus&&sumb+b>=0){
b++;
ansb++;
}
while(!plus&&sumb+b<=0){
b--;
ansb++;
}
suma+=a;
sumb+=b;
plus=!plus;
}
cout<<min(ansa,ansb)<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:10:32: error: 'sumb' was not declared in this scope; did you mean 'suma'?
10 | int n,ansa=0,ansb=0,suma=0;sumb=0;
| ^~~~
| suma
|
s162461985 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
#define forx(i,a,b) for(int i=(a);i<(b);i++)
#define rep(j,n) for(int j=0;j<(n);j++)
typedef long long ll;
int main()
{
int n,ansa=0,ansb=0,suma=0;sumb=0;
cin>>n;
bool plus=true;
vector<int>a(n);
rep(i,n){
int a,b;
cin>>t[i];
a=b=t[i];
while(plus&&suma+a<=0){
a++;
ansa++;
}
while(!plus&&suma+a>=0){
a--;
ansa++;
}
while(plus&&sumb+b>=0){
b++;
ansb++;
}
while(!plus&&sumb+b<=0){
b--;
ansb++;
}
suma+=a;
sumb+=b;
plus=!plus;
}
cout<<min(ansa,ansb)<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:10:32: error: 'sumb' was not declared in this scope; did you mean 'suma'?
10 | int n,ansa=0,ansb=0,suma=0;sumb=0;
| ^~~~
| suma
a.cc:18:12: error: 't' was not declared in this scope
18 | cin>>t[i];
| ^
|
s083729982 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
#define forx(i,a,b) for(int i=(a);i<(b);i++)
#define rep(j,n) for(int j=0;j<(n);j++)
typedef long long ll;
int main()
{
int n,ansa=0,ansb=0,sum=0;
cin>>n;
bool plus=true;
vector<int>t(n);
rep(i,n){
int a;
cin>>t(i);
a=t(i);
while(plus&&sum+a<=0){
a++;
ansa++;
}
while(!plus&&sum+a>=0){
a--;
ansa++;
}
sum+=a;
plus=!plus;
}
plus=false;
sum=0;
rep(i,n){
int a;
a=t(i);
while(plus&&sum+a>=0){
a++;
ansb++;
}
while(!plus&&sum+a<=0){
a--;
ansb++;
}
sum+=a;
plus=!plus;
}
cout<<min(ansa,ansb)<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:16:13: error: no match for call to '(std::vector<int>) (int&)'
16 | cin>>t(i);
| ~^~~
a.cc:17:10: error: no match for call to '(std::vector<int>) (int&)'
17 | a=t(i);
| ~^~~
a.cc:35:10: error: no match for call to '(std::vector<int>) (int&)'
35 | a=t(i);
| ~^~~
|
s543467610 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
#define forx(i,a,b) for(int i=(a);i<(b);i++)
#define rep(j,n) for(int j=0;j<(n);j++)
typedef long long ll;
int main()
{
int n,ansa=0,ansb=0,sum=0;
cin>>n;
bool plus=true;
rep(i,n){
int a;
cin>>a;
while(plus&&sum+a<=0){
a++;
ansa++;
}
while(!plus&&sum+a>=0){
a--;
ansa++;
}
sum+=a;
plus=!plus
}
plus=false;
sum=0;
rep(i,n){
int a;
cin>>a;
while(plus&&sum+a>=0){
a++;
ansb++;
}
while(!plus&&sum+a<=0){
a--;
ansb++;
}
sum+=a;
plus=!plus
}
cout<<min(ansa,ansb)<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:26:17: error: expected ';' before '}' token
26 | plus=!plus
| ^
| ;
27 | }
| ~
a.cc:44:17: error: expected ';' before '}' token
44 | plus=!plus
| ^
| ;
45 | }
| ~
|
s070156303 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
#define forx(i,a,b) for(int i=(a);i<(b);i++)
#define rep(j,n) for(int j=0;j<(n);j++)
typedef long long ll;
int main()
{
int n,ansa=0,ansb=0;
cin>>n;
bool plus=true;
rep(i,n){
int a;
cin>>a;
while(plus&&sum+a<=0){
a++;
ansa++;
}
while(!plus&&sum+a>=0){
a--;
ansa++;
}
sum+=a;
plus=!plus
}
plus=false;
rep(i,n){
int a;
cin>>a;
while(plus&&sum+a>=0){
a++;
ansb++;
}
while(!plus&&sum+a<=0){
a--;
ansb++;
}
sum+=a;
plus=!plus
}
cout<<min(ansa,ansb)<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:17:19: error: 'sum' was not declared in this scope
17 | while(plus&&sum+a<=0){
| ^~~
a.cc:21:20: error: 'sum' was not declared in this scope
21 | while(!plus&&sum+a>=0){
| ^~~
a.cc:25:7: error: 'sum' was not declared in this scope
25 | sum+=a;
| ^~~
a.cc:26:17: error: expected ';' before '}' token
26 | plus=!plus
| ^
| ;
27 | }
| ~
a.cc:34:19: error: 'sum' was not declared in this scope
34 | while(plus&&sum+a>=0){
| ^~~
a.cc:38:20: error: 'sum' was not declared in this scope
38 | while(!plus&&sum+a<=0){
| ^~~
a.cc:42:7: error: 'sum' was not declared in this scope
42 | sum+=a;
| ^~~
a.cc:43:17: error: expected ';' before '}' token
43 | plus=!plus
| ^
| ;
44 | }
| ~
|
s114803863 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n,ans,sum;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++){
cin>>a.at(i);
}
sum=a.at(0);
for(int i=0;i<n-1;i++){
while(sum>0&&sum+a.at(i+1)>=0)||(sum<0&&sum+a.at(i+1)<=0)){
if(a.at(i)<0){
a.at(i+1)++;
ans++;
}
if(a.at(i)>0){
a.at(i+1)--;
ans++;
}
}
sum+=a.at(i+1);
}
cout<<ans<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:16:31: error: expected primary-expression before '||' token
16 | while(sum>0&&sum+a.at(i+1)>=0)||(sum<0&&sum+a.at(i+1)<=0)){
| ^~
|
s585839321 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n,ans;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++){
cin>>a.at(i);
}
for(int i=0;i<n-1;i++){
int sum=0;
for(int j=i;j>=0;j--)sum+=a.at(j);//sum
while(p*a.at(i+1)>=0||p+a.at(i+1)==0){
if(a.at(i)>0){
a.at(i+1)--;
ans++;
}
if(a.at(i)<0){
a.at(i+1)++;
ans++;
}
}
}
cout<<ans<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:18:13: error: 'p' was not declared in this scope
18 | while(p*a.at(i+1)>=0||p+a.at(i+1)==0){
| ^
|
s838397699 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n,ans;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++){
cin>>a.at(i);
}
for(int i=0;i<n-1;i++){
while(a.at(i)*a.at(i+1)>=0){
if(a.at(i)>0){
a.at(i+1)--;
ans++;
}
if(a.at(i)<0){
a.at(i+1)++;
ans++;
}
}
int p=0;
for(int j=i+1;j>=0;j--)p+=a.at(j);//sum
if(p==0){
if(a.at(i)>0)a.at(i+1)++;
else a.at(i+1)--;
ans++;
}
cout<<ans<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:37:2: error: expected '}' at end of input
37 | }
| ^
a.cc:5:1: note: to match this '{'
5 | {
| ^
|
s838179672 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n,ans;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++){
cin>>a.at(i);
}
for(int i=0;i<n-1;i++){
while(a.at(i)*a.at(i+1)>=0){
if(a.at(i)>0){
a.at(i+1)--;
ans++;
if(p==0)p++;
}
if(a.at(i)<0){
a.at(i+1)++;
ans++;
if(p==0)p++;
}
}
int p=0;
for(int j=i+1;j>=0;j--)p+=a.at(j);//sum
if(p==0){
if(a.at(i)>0)a.at(i+1)++;
else a.at(i+1)--;
ans++;
}
cout<<ans<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:20:13: error: 'p' was not declared in this scope
20 | if(p==0)p++;
| ^
a.cc:25:13: error: 'p' was not declared in this scope
25 | if(p==0)p++;
| ^
a.cc:39:2: error: expected '}' at end of input
39 | }
| ^
a.cc:5:1: note: to match this '{'
5 | {
| ^
|
s197656881 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n,ans;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++){
cin>>a.at(i);
}
for(int i=0;i<n-1;i++){
int p=0;
for(int j=i+1;j>=0;j--)p+=a.at(j);
while(a.at(i)*a.at(i+1)<0||p=0){
if(a.at(i)>0){
a.at(i+1)--;
ans++;
continue;
}
if(a.at(i)<0){
a.at(i+1)++;
ans++;
continue;
}
}
}
cout<<ans<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:15:32: error: lvalue required as left operand of assignment
15 | while(a.at(i)*a.at(i+1)<0||p=0){
| ~~~~~~~~~~~~~~~~~~~^~~
|
s237191834 | p03739 | C++ | #define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
int main() {
int n;
cin >> n;
vector<ll> a(n);
REP(i,n) {
ll b;
cin >> b;
a[i] = b;
}
vector<ll> a2(a);
// a[0] > 0
ll res1 = 0, sum1 = 0;
REP(i, n) {
if(i%2 == 0) {
if (sum1 + a[i] <= 0) {
ll dif = -(sum1 + a[i]) + 1;
res1 += dif;
a[i] += dif;
}
sum1 += a[i];
} else {
if (sum1 + a[i] >= 0) {
ll dif = (sum1 + a[i]) + 1;
res1 += dif;
a[i] -= dif;
}
sum1 += a[i];
}
}
ll res2 = 0, sum2 = 0;
REP(i, n) {
if(i%2 == 1) {
if (sum2 + a2[i] <= 0) {
ll dif = -(sum2 + a2[i]) + 1;
res2 += dif;
a2[i] += dif;
}
sum2 += a2[i];
} else {
if (sum2 + a2[i] >= 0) {
ll dif = (sum2 + a2[i]) + 1;
res2 += dif;
a2[i] -= dif;
}
sum2 += a2m[i];
}
}
cout << min(res1, res2) << endl;
}
| a.cc: In function 'int main()':
a.cc:61:21: error: 'a2m' was not declared in this scope; did you mean 'a2'?
61 | sum2 += a2m[i];
| ^~~
| a2
|
s009561721 | p03739 | C++ | #include <bits/stdc++.h>
using namespace std;
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);i++)
int main(){
int n; cin >> n;
int a[n]; REP(i,n) cin >> a[i];
long long sum = 0;
long long count = 0;
long long tmp = 0;
REP(i,n){
if(i%2==0){
sum += a[i];
if(sum<=0){
count += abs(sum)+1;
sum += abs(sum)+1;
}
}
if(i%2==1){
sum += a[i];
if(sum>=0){
count += abs(sum)+1;
sum -= abs(sum)+1;
}
}
// cout << a[i] << ' ';
}
// cout << endl;
int count2 = 0;
sum = 0;
REP(i,n){
if(i%2==1){
sum += a[i];
if(sum<=0){
count2 += abs(sum)+1;
sum += abs(sum)+1;
}
}
if(i%2==0){
sum += a[i];
if(sum>=0){
count2 += abs(sum)+1;
sum -= abs(sum)+1;
}
}
// cout << a[i] << ' ';
}
// cout << count << endl;
cout << min(count,count2) << endl;
} | a.cc: In function 'int main()':
a.cc:55:16: error: no matching function for call to 'min(long long int&, int&)'
55 | cout << min(count,count2) << endl;
| ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:55:16: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
55 | cout << min(count,count2) << endl;
| ~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:55:16: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int'
55 | cout << min(count,count2) << endl;
| ~~~^~~~~~~~~~~~~~
|
s261515109 | p03739 | C++ | #include <iostream>
using namespace std;
typedef long long int lli
int main() {
int n;
cin >> n;
int a[100000];
for (int i = 0;i<n;i++) { cin >> a[i]; }
//最初が正のケース
lli Mp = 0;
int Sp = 0;
int dif = 0;
for (int i = 0;i<n;i++) {
Sp += a[i];
if (i % 2 == 0) {
if (Sp<=0) {
dif = 1 - Sp;
Mp += dif;
Sp += dif;
}
}
else {
if (Sp>=0) {
dif = Sp + 1;
Mp += dif;
Sp += -dif;
}
}
}
//最初が負のケース
lli Mn = 0;
int Sn = 0;
int di = 0;
for (int i = 0;i<n;i++) {
Sn += a[i];
if (i % 2 == 1) {
if (Sn<=0) {
di = 1 - Sp;
Mn += di;
Sn += di;
}
}
else {
if (Sn>=0) {
di = Sn + 1;
Mn += di;
Sn += -di;
}
}
}
if (Mp<Mn) { cout << Mp; }
else { cout << Mn; }
}
| a.cc:6:1: error: expected initializer before 'int'
6 | int main() {
| ^~~
|
s451488557 | p03739 | C++ | #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
#ifdef TESTING
#define DEBUG fprintf(stderr,"====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define DEBUG
#define VALUE(x)
#define debug(...)
#endif
inline string IntToString(ll a) {
char x[100];
sprintf_s(x, "%lld", a); string s = x;
return s;
}
inline ll StringToInt(string a) {
char x[100]; ll res;
strcpy_s(x, a.c_str()); sscanf_s(x, "%lld", &res);
return res;
}
inline string uppercase(string s) {
int n = SIZE(s);
rep(i, n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
return s;
}
inline string lowercase(string s) {
int n = SIZE(s);
rep(i, n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
return s;
}
int n;
ll d[100005];
ll solve() {
ll nans = 0;
ll nowsum = 0;
rep(i, n) {
if (i % 2 == 0) {
if (nowsum + d[i] <= 0) {
nans += llabs(nowsum + d[i] - 1);
nowsum = 1;
}
else {
nowsum += d[i];
}
}
else {
if (nowsum + d[i] >= 0){
nans += llabs(nowsum + d[i] - (-1));
nowsum = -1;
}
else
nowsum += d[i];
}
//cout << nans << endl;
}
return nans;
}
int main()
{
cin >> n;
rep(i, n) {
cin >> d[i];
}
ll ans = solve();
rep(i, n) d[i] *= -1;
ans = MIN(ans, solve());
cout << ans << endl;
return 0;
}
| a.cc: In function 'std::string IntToString(ll)':
a.cc:45:9: error: 'sprintf_s' was not declared in this scope; did you mean 'sprintf'?
45 | sprintf_s(x, "%lld", a); string s = x;
| ^~~~~~~~~
| sprintf
a.cc: In function 'll StringToInt(std::string)':
a.cc:51:9: error: 'strcpy_s' was not declared in this scope
51 | strcpy_s(x, a.c_str()); sscanf_s(x, "%lld", &res);
| ^~~~~~~~
a.cc:51:33: error: 'sscanf_s' was not declared in this scope; did you mean 'sscanf'?
51 | strcpy_s(x, a.c_str()); sscanf_s(x, "%lld", &res);
| ^~~~~~~~
| sscanf
|
s995719475 | p03739 | C++ | #include <iostream>
#include <cmath>
using namespace std;
int sign(int a){
if (a > 0)
return 1;
else
if (a < 0)
return -1;
else
return 0;
}
int main(void){
int n;
cin >> n;
int sum = 0, s = 1;
int a;
int num = 0;
for (int i = 0; i < n; i++){
cin >> a;
sum += a;
if (i != 0 && (sign(s) == sign(sum) || sum = 0)){
num += abs(sum) + 1;
sum = sign(s) * -1;
s *= -1;
}
else {
s = sign(sum);
}
}
cout << num << endl;
} | a.cc: In function 'int main()':
a.cc:31:53: error: lvalue required as left operand of assignment
31 | if (i != 0 && (sign(s) == sign(sum) || sum = 0)){
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~
|
s511706406 | p03739 | C++ | #include <iostream>
#include <algorithm>
using namespace std;
int main(void){
int n;
cin>>n;
vector<int> a(n);
cin>>a[0];
for(int i=1;i<n;i++){
cin>>a[i];
a[i]+=a[i-1];
}
if(a[0]<0){
for(int i=0;i<n;i++){
a[i]*=-1;
}
}
int ans=0,def=0;
if(a[0]==0){
ans++;
def++;
}
for(int i=1;i<n;i++){
if(i%2==0&&a[i]+def<=0){
ans+=1-(a[i]+def);
def+=1-(a[i]+def);
}
else if(i%2==1&&a[i]+def>=0){
ans+=a[i]+def+1;
def-=a[i]+def+1;
}
}
cout<<ans<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:7:5: error: 'vector' was not declared in this scope
7 | vector<int> a(n);
| ^~~~~~
a.cc:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
2 | #include <algorithm>
+++ |+#include <vector>
3 | using namespace std;
a.cc:7:12: error: expected primary-expression before 'int'
7 | vector<int> a(n);
| ^~~
a.cc:8:10: error: 'a' was not declared in this scope
8 | cin>>a[0];
| ^
|
s751768559 | p03739 | C++ | #include<iostream>
#include<cstdlib>
using namespace std;
int main(void){
int n,a;
unsigned long long sum= 0,ans=0;
int s;
cin>>n;
cin>>sum;
if(sum>0)
s = 1;
else
s = -1;
for(int i=1;i<n;i++){
cin>>a;
sum+=a;
if(sum*s>0){
ans+=abs(sum)+1;
sum = -s;
}
if(sum>0)
s = 1;
else
s = -1;
}
if(sum==0) ans++;
cout<<ans<<endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:22:15: error: call of overloaded 'abs(long long unsigned int&)' is ambiguous
22 | ans+=abs(sum)+1;
| ~~~^~~~~
In file included from /usr/include/c++/14/cstdlib:79,
from /usr/include/c++/14/ext/string_conversions.h:43,
from /usr/include/c++/14/bits/basic_string.h:4154,
from /usr/include/c++/14/string:54,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
| ^~~
In file included from /usr/include/c++/14/cstdlib:81:
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
137 | abs(__float128 __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
85 | abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
| ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
79 | abs(long double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
75 | abs(float __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
71 | abs(double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
61 | abs(long long __x) { return __builtin_llabs (__x); }
| ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
56 | abs(long __i) { return __builtin_labs(__i); }
| ^~~
|
s209627399 | p03739 | C++ | #include <iostream>
#include <algorithm>
using namespace std;
int main(){
bool ch = false;//falseの時は和が一個前で負
long long N,i;
long long ans=0,count=0;
cin >> N;
long long a[N];
cin >> a[0];
ans+=a;
if(ans>0)ch = true;
else ch = false;
for(i=1;i<N;i++){
cin >> a[i];
if(ch/*ans > 0*/){
if(ans>=-a[i]){
count += ans+a[i]+1;
ans = -1;
}
else ans += a[i];
ch = false;
}else /*if(ans < 0)*/{
if(ans<=-a[i]){
count += -ans-a[i]+1;
ans = 1;
}
else ans += a[i];
ch = true;
}
//else if(ans == 0)ans=a;
//cout << ans << " " << count << endl;
}
long long con=0;
if(a[0]>0){
ans = -1;
ch = false;
}
else {
ans = 1;
ch = true;
}
con = a[0]+1;
for(i=1;i<N;i++){
if(ch/*ans > 0*/){
if(ans>=-a[i]){
count += ans+a[i]+1;
ans = -1;
}
else ans += a[i];
ch = false;
}else /*if(ans < 0)*/{
if(ans<=-a[i]){
count += -ans-a[i]+1;
ans = 1;
}
else ans += a[i];
ch = true;
}
//else if(ans == 0)ans=a;
//cout << ans << " " << count << endl;
}
cout << min(count,con) << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:12:6: error: invalid conversion from 'long long int*' to 'long long int' [-fpermissive]
12 | ans+=a;
| ~~~^~~
| |
| long long int*
|
s619750186 | p03739 | C++ | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007
# define INF (1 < <29)
#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define MODADDSET(d) if ((d) >= MOD) d -= MOD;
#define MODADDWHILESET(d) while ((d) >= MOD) d -= MOD;
//defines
#define FILE_IO freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);
#define sc1(a,type) type a; cin>>a;
#define sc2(a,b,type) type a,b; cin>>a>>b;
#define sc3(a, b, c,type) type a,b,c; cin>>a>>b>>c;
#define sc4(a, b, c, d,type) type a ,b,c,d; cin>>a>>b>>c>>d;
#define nl cout<<"\n";
#define foreach(v, c) for(__typeof( (c).begin()) v = (c).begin(); v != (c).end(); ++v)
#define revforeach(v, c) for(__typeof( (c).rbegin()) v = (c).rbegin(); v != (c).rend(); ++v)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define re(i,b) for(int i=0;i<int(b);i++)
#define re1(i,b) for(int i=1;i<=int(b);i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(),c.rend()
#define mpresent(container, element) (container.find(element) != container.end()) //for map,set..etc (returns true/false value)
#define vpresent(container, element) (find(all(container),element) != container.end()) //for vectors,strings,list,deque (returns true/false value)
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define ins insert
#define F first
#define S second
#define clr clear()
#define sz(x) ((int)x.size())
#define dt distance
#define test(t) int t; cin>>t; while(t--)
#define csb(i) __builtin_popcount(i)
#define csbll(i) __builtin_popcountll(i)
#define clz(x) __builtin_clz(x)
#define clzl(x) __builtin_clzl(x)
#define cp(x) __builtin_parity(x)
#define adv(v,num) advance(v,num)//used for lists and other structures that use iterators,when you can't access elements randomly ( iterator moves num positions)
#define mod 1000000007
#define MAX_ARR 1000000
#define v2d(rowsize,colsize,type,name) vector<vector<type>> name(rowsize,vector<type>(colsize));
#define digits_in(i) (ll)log10(i)+1 // gives no of digits in a number
#define sqr(x) (x)*(x)
//does not apply for i==0 , add an excetion contition for n==0 ( cust return count 1 for that inseted of using this function)
//typedef
typedef string str;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<str> vs;
typedef vector<char> vc;
typedef pair<int,int> pii;
typedef pair<str,int> psi;
typedef pair<int,str> pis;
typedef vector<pii> vii;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef map<str,int> msi;
typedef map<char,int> mci;
typedef map<int,str> mis;
typedef unordered_map<int,int> umii;
typedef unordered_map<str,int> umsi;
typedef unordered_map<int,str> umis;
typedef unordered_map<str,str> umss;
typedef unordered_map<char,int> umci;
typedef set<str> ss;
typedef set<int> si;
typedef unordered_set<str> uss;
typedef unordered_set<int> usi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define debug(args...)
#endif
int main(){fastio
#ifndef ONLINE_JUDGE
FILE_IO
#endif
vi v;
test(t){
int temp;cin>>temp;
v.pb(temp);
}
int ct=0;
re(i,sz(v)-1){
debug(v[i] ,v[i]+v[i+1]);
if( (v[i]<0 && v[i]+v[i+1]<0) || (v[i]>0 && v[i]+v[i+1]>0 || v[i]+v[i+1]==0) ){
if( v[i]>0 && v[i]+v[i+1]>0){
ct+=v[i]+v[i+1]+1;
}
else if(v[i]<0 && v[i]+v[i+1]<0 ){
ct+=abs(v[i]+v[i+1])+1;
}
else{
ct+=1;
}
v[i+1]= v[i]>0?-1:1;
}
else{
v[i+1]+=v[i];
}
debug(ct);
}
cout<<ct;
return 0;
}
| a.cc:95:14: fatal error: debug.h: No such file or directory
95 | #include "debug.h"
| ^~~~~~~~~
compilation terminated.
|
s909914532 | p03739 | C++ | x = input().split(" ")
a = int(x[0])
b = int(x[1])
if (a>b):
print("GREATER")
elif(a==b):
print("EQUAL")
else:
print("LESS")
| a.cc:1:1: error: 'x' does not name a type
1 | x = input().split(" ")
| ^
|
s100607750 | p03739 | C++ | #include <iostream>
#include <cassert>
#include <queue>
#define INF 922337203685477580
typedef long long ll;
using namespace std;
int main() {
int n;
cin >> n;
ll a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
ll op = 0LL;
ll sum = 0LL;
sum = a[i];
for (int i = 1; i < n; i++) {
ll a;
cin >> a;
if (!(sum * (sum + a) < 0)) {
ll tmp_a = sum < 0 ? abs(sum) + 1 : -1 *(abs(sum) + 1);
op += abs(tmp_a - a);
sum = sum + tmp_a;
} else {
sum += a;
}
}
ll op_m = op;
if (a[0] > 0) {
sum = -1;
op = a[0] + 1;
} else {
sum = 1;
op = -1 * a[0] + 1;
}
for (int i = 1; i < n; i++) {
ll a;
cin >> a;
if (!(sum * (sum + a) < 0)) {
ll tmp_a = sum < 0 ? abs(sum) + 1 : -1 *(abs(sum) + 1);
op += abs(tmp_a - a);
sum = sum + tmp_a;
} else {
sum += a;
}
}
op = min(op, op_m);
cout << op << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:21:11: error: 'i' was not declared in this scope
21 | sum = a[i];
| ^
|
s595269629 | p03739 | C++ | #include <iostream>
#include <string>
using namespace std;
int main(){
int n,i,c=0;
cin >> n;
int a[n],s[2];
//入力
for (i=0;i<n;i++){
cin >> a[i];
}
//操作
s[0] = a[0],s[1]=0;
for (i=1;i<n;i++){
s[1] = s[0]+a[i];
if (s[0]*s[1] >=0){//符号一致(または0)していたら符号を一致させない方向へ動かす
for (;s[0]*s[1]>=0;){
if (s[0]>0) s[1] -=1;
else s[1] +=1;
c += 1;//カウントを増やす
}
}
s[0] = s[1];
// cout <<"Sum=" <<s[0]<<endl;
}
cout <<c<<;
return 0;
}
| a.cc: In function 'int main()':
a.cc:27:15: error: expected primary-expression before ';' token
27 | cout <<c<<;
| ^
|
s503249745 | p03739 | Java | import java.util.ArrayList;
import java.util.Scanner;
public class ABC {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
// 整数の入力
int n = sc.nextInt();
int a[] = new int[n];
for(int i = 0;i<a.length;i++)
{
a[i] = sc.nextInt();
}
int b[] = new int[n];
b[0] = a[0];
int count = 0;
for(int i = 0;i<a.length-1;i++)
{
b[i+1] = b[i] + a[i+1];
if(b[i+1]*b[i]>0)
{
count += Math.abs(b[i+1])+1;
if(b[i+1]>0) b[i+1]=-1;
else b[i+1] = 1;
}
else if(b[i+1] == 0)
{
if(b[i]>0) b[i+1]=-1;
else b[i+1] = 1;
count++;
}
}
System.out.println(count);
}
}
| Main.java:5: error: class ABC is public, should be declared in a file named ABC.java
public class ABC {
^
1 error
|
s164361653 | p03739 | C++ | #include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define VS vector<string>
#define ll long long int
#define debug(x) cout << x << " :" <<#x << endl
int main(void) {
int n;
cin >> n;
vector<ll> a(100001);
ll s;
REP(i,n) {
cin >{ s;
a[i] = s;
a[i] = s;
}
ll oddsum = 0, evensum = 0;
bool odd = true, even = false;
REP(i,n) {
oddsum += a[i];
evensum += a[i];
if(odd && oddsum <= 0) {
oddcount += 1 - oddsum;
oddsum = 1;
}
if(even && oddsum >= 0) {
oddcount += 1 + oddsum;
oddsum = -1;
}
if(even && evensum <= 0) {
evencount += 1 - evensum;
evensum = 1;
}
if(odd && evensum >= 0) {
evencount += 1 + evensum;
evensum = -1;
}
odd = !odd;
even = !even;
//debug(a[i]);
//debug(oddsum);
//debug(oddcount);
//debug(evensum);
//debug(evencount);
//cout << endl;
}
cout << fmin(oddcount, evencount) << endl;
}
| a.cc: In function 'int main()':
a.cc:12:9: error: 'i' was not declared in this scope
12 | REP(i,n) {
| ^
a.cc:12:5: error: 'REP' was not declared in this scope
12 | REP(i,n) {
| ^~~
a.cc:48:2: error: expected '}' at end of input
48 | }
| ^
a.cc:7:16: note: to match this '{'
7 | int main(void) {
| ^
|
s714040355 | p03739 | C++ | #include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define VS vector<string>
#define ll long long int
#define debug(x) cout << x << " :" <<#x << endl
int main(void) {
int n;
cin >> n;
vector<ll> a(100001);
ll s;
REP(i,n) {
cin >{ s;
a[i] = s;
a[i] = s;
}
ll oddsum = 0, evensum = 0;
bool odd = true, even = false;
REP(i,n) {
oddsum += a[i];
evensum += a[i];
if(odd && oddsum <= 0) {
oddcount += 1 - oddsum;
oddsum = 1;
}
if(even && oddsum >= 0) {
oddcount += 1 + oddsum;
oddsum = -1;
}
if(even && evensum <= 0) {
evencount += 1 - evensum;
evensum = 1;
}
if(odd && evensum >= 0) {
evencount += 1 + evensum;
evensum = -1;
}
odd = !odd;
even = !even;
//debug(a[i]);
//debug(oddsum);
//debug(oddcount);
//debug(evensum);
//debug(evencount);
//cout << endl;
}
cout << fmin(oddcount, evencount) << endl;
}
| a.cc: In function 'int main()':
a.cc:12:9: error: 'i' was not declared in this scope
12 | REP(i,n) {
| ^
a.cc:12:5: error: 'REP' was not declared in this scope
12 | REP(i,n) {
| ^~~
a.cc:48:2: error: expected '}' at end of input
48 | }
| ^
a.cc:7:16: note: to match this '{'
7 | int main(void) {
| ^
|
s780624808 | p03739 | C++ | #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
#define int ll
signed main(){
int n; cin>>n;
vi v(n);
bool flag = false;
rep(i,n)cin>>v[i];
vi sum(n);
int ans=0;
rep(i,n)sum[i]=v[i];
rep(i,n){
if(!i){
if(sum[0]>0)flag=true;
else if(sum[0]<0)flag=false;
else {
sum[0]=1;
ans++;
flag=true;
}
continue;
}
sum[i]+=sum[i-1];
if(flag){
if(sum[i]<0)flag=false;a
else{
ans+=(abs(sum[i])+1);
sum[i]= -1;
flag=false;
}
}else{
if(sum[i]>0)flag=true;
else {
ans+=(abs(sum[i])+1);
sum[i]= 1;
flag=true;
}
}
}
//rep(i,n)cout<<sum[i]<<" ";
//cout<<endl;
cout<<ans<<endl;
} | a.cc: In function 'int main()':
a.cc:67:36: error: 'a' was not declared in this scope
67 | if(sum[i]<0)flag=false;a
| ^
|
s057332894 | p03739 | C++ | #include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stdlib.h>
#include <list>
#include <queue>
#include <map>
#include <stack>
#include <set>
#define inf 0x3f3f3f3f
#define PI acos(double(-1))
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int a[maxn];
int main()
{
int n;
ll sum,num=1e18;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
sum=a[0];
ll cnt=0;
if(sum==0)
{
int i=1;
while(a[i]==0&&i<n)
i++;
if(i==n)
{
cnt=(n-1)*2+1;
printf("%lld\n",cnt);
return 0;
}
for(int i=1;i<n;i++)
{
sum=1;
// scanf("%d",&a[i]);
if(sum>0)
{
ll t=sum+a[i];
if(t<0)
sum=t;
else
{
ll b=abs(t+1);
cnt+=b;
sum=-1;
}
}
else if(sum<0)
{
ll t=sum+a[i];
if(t>0)
sum=t;
else
{
ll b=abs(1-t);
cnt+=b;
sum=1;
}
}
num=min(num,cnt);
}
for(int i=1;i<n;i++)
{
sum=-1;
// scanf("%d",&a[i]);
if(sum>0)
{
ll t=sum+a[i];
if(t<0)
sum=t;
else
{
ll b=abs(t+1);
cnt+=b;
sum=-1;
}
}
else if(sum<0)
{
ll t=sum+a[i];
if(t>0)
sum=t;
else
{
ll b=abs(1-t);
cnt+=b;
sum=1;
}
}
num=min(num,cnt)
}
printf("%lld\n",num);
return 0;
}
for(int i=1;i<n;i++)
{
// scanf("%d",&a[i]);
if(sum>0)
{
ll t=sum+a[i];
if(t<0)
sum=t;
else
{
ll b=abs(t+1);
cnt+=b;
sum=-1;
}
}
else if(sum<0)
{
ll t=sum+a[i];
if(t>0)
sum=t;
else
{
ll b=abs(1-t);
cnt+=b;
sum=1;
}
}
}
printf("%lld\n",cnt);
return 0;
}
| a.cc: In function 'int main()':
a.cc:100:25: error: expected ';' before '}' token
100 | num=min(num,cnt)
| ^
| ;
101 | }
| ~
|
s829845496 | p03739 | C++ | #include <stdio.h>
#include<math.h>
int main(void) {
// your code goes here
long int a[100000];
int n,count= 0;
scanf("%d",&n);
int i;
for(i = 0;i<n;i++)
{
scanf("%ld",&a[i]);
};
int new = a[0]+a[1];
int pos;
if(new <0)
pos= 0;
else
pos = 1;
for(i = 2;i<n;i++)
{
new = a[i]+new;
// printf("%d",new);
pos = !pos;
if(new>0&& pos==0)
{count+=abs(new)+1;
new= -1;}
else if(new<0 && pos )
{count+=abs(new)+1;
new = 1;
}
else if(new ==0)
{
count++;
if(pos==0)
new = -1;
else
new = 1;
}
}
printf("%d",count);
return 0;
}
| a.cc: In function 'int main()':
a.cc:13:21: error: expected unqualified-id before 'new'
13 | int new = a[0]+a[1];
| ^~~
a.cc:15:24: error: expected type-specifier before '<' token
15 | if(new <0)
| ^
a.cc:21:21: error: expected type-specifier before '=' token
21 | new = a[i]+new;
| ^
a.cc:21:31: error: expected type-specifier before ';' token
21 | new = a[i]+new;
| ^
a.cc:24:23: error: expected type-specifier before '>' token
24 | if(new>0&& pos==0)
| ^
a.cc:25:32: error: expected type-specifier before ')' token
25 | {count+=abs(new)+1;
| ^
a.cc:26:20: error: expected type-specifier before '=' token
26 | new= -1;}
| ^
a.cc:27:28: error: expected type-specifier before '<' token
27 | else if(new<0 && pos )
| ^
a.cc:28:26: error: expected type-specifier before ')' token
28 | {count+=abs(new)+1;
| ^
a.cc:29:15: error: expected type-specifier before '=' token
29 | new = 1;
| ^
a.cc:31:21: error: expected type-specifier before '==' token
31 | else if(new ==0)
| ^~
a.cc:35:17: error: expected type-specifier before '=' token
35 | new = -1;
| ^
a.cc:37:21: error: expected type-specifier before '=' token
37 | new = 1;
| ^
|
s198499402 | p03739 | C++ | if(a[0]==0){
ans1++;
sum0=1;
}else{
sum0=a[0];
}
REP(i,1,n){
sum1=sum0+a[i];
if(sum1*sum0<0){
}else if(sum1*sum0>0){
ans1+=abs(sum1)+1;
sum1=-1*sum0/abs(sum0);
}else{
ans1++;
sum1=-1*sum0/abs(sum0);
}
sum0=sum1;
} | a.cc:1:3: error: expected unqualified-id before 'if'
1 | if(a[0]==0){
| ^~
a.cc:4:4: error: expected unqualified-id before 'else'
4 | }else{
| ^~~~
a.cc:7:6: error: expected constructor, destructor, or type conversion before '(' token
7 | REP(i,1,n){
| ^
|
s181583568 | p03739 | C++ | #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
int n;
vector<long long> A;
long long ans1 = 0;
long long ans2 = 0;
long long sum = 0;
cin >> n;
for ( int i = 0; i < n; i++ ) {
long long a;
cin >> a;
A.push_back(a);
}
is_plus = true;
for ( int i = 0; i < n; i++ ) {
if ( i ) { is_plus = sum > 0; }
sum += A[i];
if ( sum == 0 ) {
ans1++;
sum = is_plus ? -1 : 1;
}
else if ( is_plus == (sum > 0) ) {
ans1 += abs(sum)+1;
sum = is_plus ? -1 : 1;
}
}
is_plus = false;
for ( int i = 0; i < n; i++ ) {
if ( i ) { is_plus = sum > 0; }
sum += A[i];
if ( sum == 0 ) {
ans2++;
sum = is_plus ? -1 : 1;
}
else if ( is_plus == (sum > 0) ) {
ans2 += abs(sum)+1;
sum = is_plus ? -1 : 1;
}
}
cout << min( ans1, ans2 ) << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:31:5: error: 'is_plus' was not declared in this scope
31 | is_plus = true;
| ^~~~~~~
|
s076154503 | p03739 | C++ | #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
int n;
vector<long long> A;
int j;
bool is_plus;
long long ans = 0;
long long sum = 0;
cin >> n;
for ( int i = 0; i < n; i++ ) {
long long a;
cin >> a;
A.push_back(a);
}
// for ( j = 0; j < n; j++ ) {
// if ( abs(A[j]) ) { break; }
// }
// if ( j == n ) {
// cout << A.size()*2-1 << endl;
// return 0;
// }
// if ( j ) {
// ans += ( j+1 )*2 - 1;
// sum = ( A[j] > 0 ) ? -1: 1;
// }
// else {
// sum = 0;
// ans = 0;
// }
for ( int i = 0; i < n; i++ ) {
if ( !i ) {
if ( A[i] == 0 ) {
if ( A[i+1] >= 0 ) { sum = -1; }
else { sum = 1; }
ans+;;
}
else {
sum = A[i];
}
continue;
}
bool is_plus = sum > 0;
sum += A[i];
if ( sum == 0 ) {
ans += 1;
sum = is_plus ? -1 : 1;
}
else if ( is_plus == (sum > 0) ) {
ans += abs(sum)+1;
sum = is_plus ? -1 : 1;
}
}
cout << ans << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:57:21: error: expected primary-expression before ';' token
57 | ans+;;
| ^
|
s249807114 | p03739 | C++ | #include <cstdio>
#include <algorithm>
using namespace std;
int main(){
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) scanf(" %d", &a[i]);
int S = a[0];
int j = 0;
for (int i = 1; i < n; i++){
if (S * (S+a[i]) < 0){
S += a[i];
}
else if (S+a[i] == 0){
j += 1;
if (S > 0) S = -1;
else (S < 0) S = 1;
}
else {
j += abs(S + a[i]) + 1;
if (S < 0) S = 1;
else if (S > 0) S = -1;
}
}
}
printf("%d\n", j);
} | a.cc: In function 'int main()':
a.cc:21:24: error: expected ';' before 'S'
21 | else (S < 0) S = 1;
| ^~
| ;
a.cc: At global scope:
a.cc:31:11: error: expected constructor, destructor, or type conversion before '(' token
31 | printf("%d\n", j);
| ^
a.cc:32:1: error: expected declaration before '}' token
32 | }
| ^
|
s456732795 | p03739 | C++ | #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
int n;
vector<long long> A;
int j;
bool is_plus;
long long ans = 0;
long long sum = 0;
cin >> n;
S.push_back(0);
for ( int i = 0; i < n; i++ ) {
long long a;
cin >> a;
A.push_back(a);
}
// for ( j = 0; j < n; j++ ) {
// if ( abs(A[j]) ) { break; }
// }
// if ( j == n ) {
// cout << A.size()*2-1 << endl;
// return 0;
// }
// if ( j ) {
// ans += ( j+1 )*2 - 1;
// sum = ( A[j] > 0 ) ? -1: 1;
// }
// else {
// sum = 0;
// ans = 0;
// }
for ( int i = 0; i < n; i++ ) {
if ( !i ) {
sum = A[i];
continue;
}
bool is_plus = sum > 0;
sum += A[i];
if ( sum == 0 ) {
ans += 1;
sum = is_plus ? -1 : 1;
}
else if ( is_plus == (sum > 0) ) {
ans += abs(sum)+1;
sum = is_plus ? -1 : 1;
}
}
cout << ans << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:25:5: error: 'S' was not declared in this scope
25 | S.push_back(0);
| ^
|
s834354286 | p03739 | C++ | #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
int n;
vector<long long> S;
vector<long long> A;
bool is_plus;
int ans;
int ans1 = 0;
int ans2 = 0;
long long sum = 0;
cin >> n;
for ( int i = 0; i < n; i++ ) {
long long a;
cin >> a;
A.push_back(a);
}
for ( int i = 0; i < n; i++ ) {
if ( !i ) {
if ( A[i] == 0 ) {
}
else if ( A[i] < 0 ) {#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
int n;
vector<long long> S;
vector<long long> A;
int j;
bool is_plus;
long long ans = 0;
long long sum = 0;
cin >> n;
S.push_back(0);
for ( int i = 0; i < n; i++ ) {
long long a;
cin >> a;
A.push_back(a);
}
for ( j = 0; j < n; j++ ) {
if ( abs(A[j]) ) { break; }
}
if ( j == n ) {
cout << A.size()*2-1 << endl;
return 0;
}
if ( j ) {
ans += ( j+1 )*2 - 1;
sum = ( A[j] > 0 ) ? -1: 1;
}
else {
sum = 0;
ans = 0;
}
for ( int i = j; i < n; i++ ) {
if ( !i ) {
sum = A[i];
continue;
}
bool is_plus = sum > 0;
sum += A[i];
if ( sum == 0 ) {
ans += 1;
sum = is_plus ? -1 : 1;
}
else if ( is_plus == (sum > 0) ) {
ans += abs(sum)+1;
sum = is_plus ? -1 : 1;
}
}
cout << ans << endl;
return 0;
}
ans1 += abs(A[i]) + 1;
}
}
else {
if ( i%2 && A[i] > 0 )
}
}
for ( int i = 0; i < n; i++ ) {
}
cout << ans << endl;
return 0;
} | a.cc:38:35: error: stray '#' in program
38 | else if ( A[i] < 0 ) {#include <iostream>
| ^
a.cc: In function 'int main()':
a.cc:38:36: error: 'include' was not declared in this scope
38 | else if ( A[i] < 0 ) {#include <iostream>
| ^~~~~~~
a.cc:38:53: error: expected primary-expression before '>' token
38 | else if ( A[i] < 0 ) {#include <iostream>
| ^
a.cc:47:1: error: expected primary-expression before 'using'
47 | using namespace std;
| ^~~~~
a.cc:49:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
49 | int main() {
| ^~
a.cc:49:9: note: remove parentheses to default-initialize a variable
49 | int main() {
| ^~
| --
a.cc:49:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:49:12: error: a function-definition is not allowed here before '{' token
49 | int main() {
| ^
a.cc:127:9: error: expected primary-expression before '}' token
127 | }
| ^
|
s440798248 | p03739 | C++ | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INFF=0x3f3f3f3f3f3f3f3f;
int a[100010];
int n;
ll solve()
{
ll ans=0;
ll t=a[0];
for(int i=1;i<n;i++)
{
if(t<0)
{
t+=a[i];
if(t<=0)
{
ans+=1-t;
t=1;
}
continue;
}
t+=a[i];
if(t>=0)
{
ans+=t+1;
t=-1;
}
}
return ans;
}
int main()
{
scanf("%d",&n);
ll sum=0;
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
ll sum=0,t=a[0];
if(t==0)
{
a[0]=1;
ll sum1=solve();
a[0]=-1;
ll sum2=solve();
sum=min(sum1,sum2)+1;
}
else
{
ll sum0=solve();
a[0]=1;
ll sum1=solve()+abs(1-t);
a[0]=-1;
ll sum2=solve()+abs(-1-t);
sum=min(sum0,min(sum1,sum2));
}
printf("%lld\n",sum);
return 0;
}
| a.cc: In function 'int main()':
a.cc:54:12: error: redeclaration of 'll sum'
54 | ll sum=0,t=a[0];
| ^~~
a.cc:49:12: note: 'll sum' previously declared here
49 | ll sum=0;
| ^~~
|
s564708361 | p03739 | C++ | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INFF=0x3f3f3f3f3f3f3f3f;
ll a[1000010];
int n;
ll solve()
{
ll sum=0;
ll oo=a[0];
for(int i=1;i<n;i++)
{
if(oo<0)
{
oo+=a[i];
if(oo<=0)
{
sum+=1-oo;
oo=1;
}
continue;
}
else
{
oo+=a[i];
if(oo>=0)
{
sum+=oo+1;
oo=-1;
}
}
}
return sum;
}
int main()
{
scanf("%d",&n);
ll sum=0;
for(int i=0;i<n;i++)
{
scanf("%lld",&a[i]);
}
if(a[0]==0)
{
a[0]=1;
ll sum1=solve();
a[0]=-1;
ll sum2=solve();
sum=min(sum1,sum2)+1;
}
else
{
ll sum0=solve();
a[0]=1;
ll sum1=solve()+abs(1-a[0]);
a[0]=-1;
ll sum2=solve()+abs(-1-a[0]);
sum=min(sum0,min(sum1,sum2));
}
printf("%lld\n",sum);
}
return 0;
}
| a.cc:76:5: error: expected unqualified-id before 'return'
76 | return 0;
| ^~~~~~
a.cc:77:1: error: expected declaration before '}' token
77 | }
| ^
|
s840860108 | p03739 | C++ | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INFF=0x3f3f3f3f3f3f3f3f;
ll a[1000010];
int n;
ll solve()
{
ll sum=0;
ll oo=a[0];
for(int i=1;i<n;i++)
{
if(oo<0)
{
oo+=a[i];
if(oo<=0)
{
sum+=1-oo;
oo=1;
}
continue;
}
else
{
oo+=a[i];
if(oo>=0)
{
sum+=oo+1;
oo=-1;
}
}
}
return sum;
}
int main()
{
scanf("%d",&n);
ll sum=0;
for(int i=0;i<n;i++)
{
scanf("%lld",&a[i]);
}
if(a[0]==0)
{
a[0]=1;
ll sum1=solve();
a[0]=-1;
ll sum2=solve();
sum=min(sum1,sum2)+1;
}
else
{
ll sum0=solve();
a[0]=1;
ll sum1=solve()+abs(1-a[0]);
a[0]=-1;
ll sum2=solve()+abs(-1-a[0]);
sum=min(sum0,min(sum1,sum2));
}
printf("%lld\n",sum);
}
return 0;
}
| a.cc:76:5: error: expected unqualified-id before 'return'
76 | return 0;
| ^~~~~~
a.cc:77:1: error: expected declaration before '}' token
77 | }
| ^
|
s868270635 | p03739 | C++ | #include <cstdio>
using namespace std;
int main(){
long double n;
scanf("%Lf", &n);
long double a[n];
for (int i = 0; i < n; i++) scanf(" %Lf", &a[i]);
int S = a[0];
int j = 0;
for (int i = 1; i < n; i++){
if (S * (S+a[i]) < 0){
S += a[i];
}
else {
if (S < 0){
j += 1 - S - a[i];
S = 1;
} else{
j += S + a[i] + 1;
S = -1;
}
}
}
printf("%d\n", j);
} | a.cc: In function 'int main()':
a.cc:7:19: error: conversion from 'long double' to 'long unsigned int' in a converted constant expression
7 | long double a[n];
| ^
a.cc:7:19: error: could not convert 'n' from 'long double' to 'long unsigned int'
7 | long double a[n];
| ^
| |
| long double
a.cc:7:19: error: size of array 'a' has non-integral type 'long double'
|
s103036923 | p03739 | C++ | #include <iostream>
#include <math.h>
using namespace std;
int a(long long int z) {
if (z > 0) return 1;
else if (z < 0) return -1;
else return 0;
}
int main(){
long long int n, sum = 0, in, ans = 0;
cin >> n >> sum;
for(int i = 1;i<n;i++){
cin >> in;
if(i == 1){
if(sum == 0){
sum = -1 * a(in);
ans++;
}
}
if(a(sum) * a(in) < 0 && abs(sum) < abs(in)){
sum += in;
continue;
}
else if(a(sum) * a(in) < 0){
ans += abs(sum+in) + 1;
sum = -1 * a(sum);
continue;
}
ans += abs(sum+in) + 1;
sum = 1 * a(sum);
}
}
if (sum == 0) ans++;
cout << ans << endl;
return 0;
} | a.cc:35:9: error: expected unqualified-id before 'if'
35 | if (sum == 0) ans++;
| ^~
a.cc:36:9: error: 'cout' does not name a type
36 | cout << ans << endl;
| ^~~~
a.cc:37:9: error: expected unqualified-id before 'return'
37 | return 0;
| ^~~~~~
a.cc:38:1: error: expected declaration before '}' token
38 | }
| ^
|
s393083299 | p03739 | Java | import java.util.*;
// ABC 6-C
// http://abc006.contest.atcoder.jp/tasks/abc006_3
public class Main {
public static void main (String[] args) throws java.lang.Exception {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] nums = new int[n];
for (int i = 0; i < n; i++) {
nums[i] = in.nextInt();
}
int answer = 0;
if (nums[0] == 0) {
answer = solve(nums, 0, 0);
} else {
answer = solve(nums, nums[0], 1);
}
System.out.println(answer);
//
// long sum = 0;
// long answer = 0;
//
// for (int i = 0; i < n; i++) {
// int a = in.nextInt();
//
// if (sum < 0 && sum + a < 0) {
// answer += 1 + Math.abs(sum + a);
// sum = 1;
// } else if (sum > 0 && sum + a > 0) {
// answer += 1 + sum + a;
// sum = -1;
// } else if (sum + a == 0) {
// answer++;
// if (sum < 0) {
// sum = 1;
// } else {
// sum = -1;
// }
// } else {
// sum += a;
// }
// }
// System.out.println(answer);
}
public static long solve(int[] nums, long sum, int index) {
if (index == nums.length) {
return 0;
}
if (sum < 0 && sum + nums[index] < 0) {
return 1 + Math.abs(sum + nums[index]) + solve(nums, 1, index + 1);
} else if (sum > 0 && sum + nums[index] > 0) {
return 1 + sum + nums[index] + solve(nums, -1, index + 1);
} else if (sum + nums[index] == 0) {
return 1 + Math.min(solve(nums, 1, index + 1), solve(nums, -1, index + 1));
} else {
return solve(nums, sum + nums[index], index + 1);
}
}
} | Main.java:20: error: incompatible types: possible lossy conversion from long to int
answer = solve(nums, 0, 0);
^
Main.java:22: error: incompatible types: possible lossy conversion from long to int
answer = solve(nums, nums[0], 1);
^
2 errors
|
s323434467 | p03739 | C++ | #include<iostream>
using namespace std;
long int abs(long int a){
if(a<0)return -a;
else return a;
}
bool isDifAbs(long int a,long int b){
if(a*b<0)return true;
return false;
}
int main(){
int n;
long int sum,tmp,ttmp,ans=0;
cin >> n;
cin >> sum;
for(int i=1;i<n;i++){
cin >> tmp;
if(!isDifAbs(sum,sum+tmp)){
ttmp=tmp;
if(sum<0)tmp=abs(tmp)+1;
else if(sum>0)tmp=-(abs(tmp)+1);
ans+=abs(tmp-ttmp);
}
else if(sum+tmp==0){
if(sum<0)tmp++;
if(sum>0)tmp--;
ans++;
}
sum+=tmp;
}
cout << ans << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:23:29: error: call of overloaded 'abs(long int&)' is ambiguous
23 | if(sum<0)tmp=abs(tmp)+1;
| ~~~^~~~~
In file included from /usr/include/c++/14/cstdlib:79,
from /usr/include/c++/14/ext/string_conversions.h:43,
from /usr/include/c++/14/bits/basic_string.h:4154,
from /usr/include/c++/14/string:54,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
| ^~~
a.cc:4:10: note: candidate: 'long int abs(long int)'
4 | long int abs(long int a){
| ^~~
In file included from /usr/include/c++/14/cstdlib:81:
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
137 | abs(__float128 __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
85 | abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
| ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
79 | abs(long double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
75 | abs(float __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
71 | abs(double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
61 | abs(long long __x) { return __builtin_llabs (__x); }
| ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
56 | abs(long __i) { return __builtin_labs(__i); }
| ^~~
a.cc:24:36: error: call of overloaded 'abs(long int&)' is ambiguous
24 | else if(sum>0)tmp=-(abs(tmp)+1);
| ~~~^~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
| ^~~
a.cc:4:10: note: candidate: 'long int abs(long int)'
4 | long int abs(long int a){
| ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
137 | abs(__float128 __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
85 | abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
| ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
79 | abs(long double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
75 | abs(float __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
71 | abs(double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
61 | abs(long long __x) { return __builtin_llabs (__x); }
| ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
56 | abs(long __i) { return __builtin_labs(__i); }
| ^~~
a.cc:25:21: error: call of overloaded 'abs(long int)' is ambiguous
25 | ans+=abs(tmp-ttmp);
| ~~~^~~~~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
| ^~~
a.cc:4:10: note: candidate: 'long int abs(long int)'
4 | long int abs(long int a){
| ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
137 | abs(__float128 __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
85 | abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
| ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
79 | abs(long double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
75 | abs(float __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
71 | abs(double __x)
| ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
61 | abs(long long __x) { return __builtin_llabs (__x); }
| ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
56 | abs(long __i) { return __builtin_labs(__i); }
| ^~~
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.