Submission #1303809

#TimeUsernameProblemLanguageResultExecution timeMemory
1303809trinm01Robots (APIO13_robots)C++20
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i, l, r) for(int i=l; i<=r; i++)
#define FOD(i, r, l) for(int i=r; i>=l; i--)
#define pii pair<int, int>
#define fi first
#define se second
const int MAXN=1e6+5;
const int oo=1e18+7;
const int mod=1e9+7;



signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	
//	freopen("test.txt", "r", stdin);
//	freopen("o2.out", "w", stdout);
	
	if(fopen(".inp", "r")){
		freopen(".inp", "r", stdin);
		freopen(".out", "w", stdout);
	}
	
	
	
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i, l, r) for(int i=l; i<=r; i++)
#define FOD(i, r, l) for(int i=r; i>=l; i--)
#define pii pair<int, int>
#define fi first
#define se second
const int MAXN=1e6+5;
const int oo=1e18+7;
const int mod=1e9+7;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r){
	return uniform_int_distribution<int>(l, r)(rng);
}


signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	
	freopen("test.txt", "w", stdout);
	
	int n=10;
	cout << n << '\n';
	int sum=0;
	FOR(i, 1, n-1){
		int x=rnd(-10, 10);
		cout << x << ' ';
		sum+=x;
	}
	cout << rnd(1-sum, 100);
	
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i, l, r) for(int i=l; i<=r; i++)
#define FOD(i, r, l) for(int i=r; i>=l; i--)
#define pii pair<int, int>
#define fi first
#define se second
const int MAXN=1e6+5;
const int oo=1e18+7;
const int mod=1e9+7;

int n;
int a[MAXN];

int f[1005][1005];
int dp(int i, int last){
	if(i>n){
		return 0;
	}
	if(f[i][last]!=-1){
		return f[i][last];
	}

	int sum=0;
	int ans=-oo;
	FOR(j, i, n){
		sum+=a[j];
		if(sum>=last){
			ans=max(ans, dp(j+1, sum)+1);
		}
	}
	return f[i][last]=ans;
}

void solve(){
	
	cin >> n;
	FOR(i, 1, n){
		cin >> a[i];
	}

	memset(f, -1, sizeof f);
	cout << dp(1, 1);
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	
	freopen("test.txt", "r", stdin);
	freopen("o1.out", "w", stdout);
	
	if(fopen(".inp", "r")){
		freopen(".inp", "r", stdin);
		freopen(".out", "w", stdout);
	}
	
	int T;
	cin >> T;
	while(T--){
		solve();
	}
	
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i, l, r) for(int i=l; i<=r; i++)
#define FOD(i, r, l) for(int i=r; i>=l; i--)
#define pii pair<int, int>
#define fi first
#define se second
const int MAXN=1e6+5;
const int oo=1e18+7;
const int mod=1e9+7;

int n;
int a[MAXN];

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	
//	freopen("test.txt", "r", stdin);
//	freopen("o2.out", "w", stdout);
	
	if(fopen(".inp", "r")){
		freopen(".inp", "r", stdin);
		freopen(".out", "w", stdout);
	}
	
	cin >> n;
	FOR(i, 1, n){
		cin >> a[i];
	}

	int ans=0;
	int last=1;
	for(int i=1; i<=n; ){
		int j=i;
		int sum=0;
		while(j<=n && sum<last){
			sum+=a[j];
			j++;
		}
		while(j<=n && a[j]<0 && sum+a[j]>=last){
			sum+=a[j];
			j++;
		}
		if(sum>=last){
			ans++;
		}
		last=sum;
		i=j;
	}
	cout << ans;
	
	return 0;
}

Compilation message (stderr)

robots.cpp:44:11: error: redefinition of 'const long long int MAXN'
   44 | const int MAXN=1e6+5;
      |           ^~~~
robots.cpp:10:11: note: 'const long long int MAXN' previously defined here
   10 | const int MAXN=1e6+5;
      |           ^~~~
robots.cpp:45:11: error: redefinition of 'const long long int oo'
   45 | const int oo=1e18+7;
      |           ^~
robots.cpp:11:11: note: 'const long long int oo' previously defined here
   11 | const int oo=1e18+7;
      |           ^~
robots.cpp:46:11: error: redefinition of 'const long long int mod'
   46 | const int mod=1e9+7;
      |           ^~~
robots.cpp:12:11: note: 'const long long int mod' previously defined here
   12 | const int mod=1e9+7;
      |           ^~~
robots.cpp:54:8: error: redefinition of 'int main()'
   54 | signed main(){
      |        ^~~~
robots.cpp:16:8: note: 'int main()' previously defined here
   16 | signed main(){
      |        ^~~~
robots.cpp:84:11: error: redefinition of 'const long long int MAXN'
   84 | const int MAXN=1e6+5;
      |           ^~~~
robots.cpp:10:11: note: 'const long long int MAXN' previously defined here
   10 | const int MAXN=1e6+5;
      |           ^~~~
robots.cpp:85:11: error: redefinition of 'const long long int oo'
   85 | const int oo=1e18+7;
      |           ^~
robots.cpp:11:11: note: 'const long long int oo' previously defined here
   11 | const int oo=1e18+7;
      |           ^~
robots.cpp:86:11: error: redefinition of 'const long long int mod'
   86 | const int mod=1e9+7;
      |           ^~~
robots.cpp:12:11: note: 'const long long int mod' previously defined here
   12 | const int mod=1e9+7;
      |           ^~~
robots.cpp:122:8: error: redefinition of 'int main()'
  122 | signed main(){
      |        ^~~~
robots.cpp:16:8: note: 'int main()' previously defined here
   16 | signed main(){
      |        ^~~~
robots.cpp:154:11: error: redefinition of 'const long long int MAXN'
  154 | const int MAXN=1e6+5;
      |           ^~~~
robots.cpp:10:11: note: 'const long long int MAXN' previously defined here
   10 | const int MAXN=1e6+5;
      |           ^~~~
robots.cpp:155:11: error: redefinition of 'const long long int oo'
  155 | const int oo=1e18+7;
      |           ^~
robots.cpp:11:11: note: 'const long long int oo' previously defined here
   11 | const int oo=1e18+7;
      |           ^~
robots.cpp:156:11: error: redefinition of 'const long long int mod'
  156 | const int mod=1e9+7;
      |           ^~~
robots.cpp:12:11: note: 'const long long int mod' previously defined here
   12 | const int mod=1e9+7;
      |           ^~~
robots.cpp:158:5: error: redefinition of 'long long int n'
  158 | int n;
      |     ^
robots.cpp:88:5: note: 'long long int n' previously declared here
   88 | int n;
      |     ^
robots.cpp:159:5: error: redefinition of 'long long int a [1000005]'
  159 | int a[MAXN];
      |     ^
robots.cpp:89:5: note: 'long long int a [1000005]' previously declared here
   89 | int a[MAXN];
      |     ^
robots.cpp:161:8: error: redefinition of 'int main()'
  161 | signed main(){
      |        ^~~~
robots.cpp:16:8: note: 'int main()' previously defined here
   16 | signed main(){
      |        ^~~~
robots.cpp: In function 'int main()':
robots.cpp:25:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |                 freopen(".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~
robots.cpp:26:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |                 freopen(".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
robots.cpp: In function 'int main()':
robots.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen("test.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
robots.cpp: In function 'int main()':
robots.cpp:127:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  127 |         freopen("test.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
robots.cpp:128:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  128 |         freopen("o1.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
robots.cpp:131:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |                 freopen(".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~
robots.cpp:132:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  132 |                 freopen(".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
robots.cpp: In function 'int main()':
robots.cpp:170:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  170 |                 freopen(".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~
robots.cpp:171:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  171 |                 freopen(".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~