Submission #1025116

# Submission time Handle Problem Language Result Execution time Memory
1025116 2024-07-16T16:10:58 Z YassirSalama Horses (IOI15_horses) C++17
17 / 100
301 ms 112760 KB
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ll long long
template<typename T> 
void dbg_out(const T& t){
	cout<<t<<endl;
}
template<typename T,typename... Args>
void dbg_out(const T& t,const Args&... args){
	cout<<t<<" , ";
	dbg_out(args...);
}
#define dbg(...) cout<<"("<<#__VA_ARGS__<<"): ";dbg_out(__VA_ARGS__);
const int mod=1e9+7;
const int maxn=5e5;
int n;
vector<ll> x;
vector<ll> y;
ll dp[maxn];
ll solve(int i){
	if(i==n) return 0LL;
	if(dp[i]!=-1) return dp[i];
	ll h=1;
	ll &ans=dp[i];
	ans=0;
	int t=0;
	for(int k=i;k<n&&t<=40;k++){
		h=(h%mod*x[k]%mod)%mod;
		if(x[k]!=1) t++;
		ans=max(ans,((ll)solve(k+1)%mod+(ll)(h-1)%mod*(ll)y[k]%mod)%mod);
		ans=max(ans,((ll)h%mod*(ll)y[k]%mod)%mod);
	}
	ans%=mod;
	return ans;
}
void clear(){
	for(int j=0;j<=n;j++){
		dp[j]=-1;
	}
}
int init(int N, int X[], int Y[]) {
	n=N;
	x.resize(n,0);
	y.resize(n,0);
	for(int i=0;i<n;i++){
		x[i]=X[i];
	}
	for(int i=0;i<n;i++){
		y[i]=Y[i];
	}
	// clear();
	memset(dp,-1,sizeof(dp));
	return (int)((ll)solve(0)%mod);
}

int updateX(int pos, int val) {	
	x[pos]=val;
	// clear();
	memset(dp,-1,sizeof(dp));
	return solve(0)%mod;
}

int updateY(int pos, int val) {
	y[pos]=val;
	clear();
	return solve(0)%mod;
}


#ifdef IOI


static char _buffer[1024];
static int _currentChar = 0;
static int _charsNumber = 0;
static FILE *_inputFile, *_outputFile;

static inline int _read() {
    if (_charsNumber < 0) {
        exit(1);
    }
    if (!_charsNumber || _currentChar == _charsNumber) {
        _charsNumber = (int)fread(_buffer, sizeof(_buffer[0]), sizeof(_buffer), _inputFile);
        _currentChar = 0;
    }
    if (_charsNumber <= 0) {
        return -1;
    }
    return _buffer[_currentChar++];
}

static inline int _readInt() {
    int c, x, s;
    c = _read();
    while (c <= 32) c = _read();
    x = 0;
    s = 1;
    if (c == '-') {
        s = -1;
        c = _read();
    }
    while (c > 32) {
        x *= 10;
        x += c - '0';
        c = _read();
    }
    if (s < 0) x = -x;
    return x;
}


int main() {
	// _inputFile = fopen("horses.in", "rb");
	// _outputFile = fopen("horses.out", "w");
	
	int N; 
	cin>>N;

	int *X = (int*)malloc(sizeof(int)*(unsigned int)N);
	int *Y = (int*)malloc(sizeof(int)*(unsigned int)N);

	for (int i = 0; i < N; i++) {
		cin>>X[i];
	}

	for (int i = 0; i < N; i++) {
		cin>>Y[i];
	}	
	cout<<init(N,X,Y)<<endl;


	int M; 
	// M = _readInt();
	cin>>M;

	for (int i = 0; i < M; i++) {
		int type; 
		int pos; 
		int val; 
		cin>>type>>pos>>val;
		if (type == 1) {
			cout<<updateX(pos,val)<<endl;
			// fprintf(_outputFile,"%d\n",updateX(pos,val));
		} else if (type == 2) {
			cout<<updateY(pos,val)<<endl;
			// fprintf(_outputFile,"%d\n",updateY(pos,val));
		}
	}

	return 0;
}

#endif 

Compilation message

horses.cpp: In function 'int updateX(int, int)':
horses.cpp:63:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   63 |  return solve(0)%mod;
      |         ~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:69:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   69 |  return solve(0)%mod;
      |         ~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4184 KB Output is correct
2 Correct 2 ms 4184 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4276 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4264 KB Output is correct
7 Correct 2 ms 4288 KB Output is correct
8 Correct 1 ms 4188 KB Output is correct
9 Correct 2 ms 4188 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 2 ms 4440 KB Output is correct
12 Correct 2 ms 4188 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 2 ms 4188 KB Output is correct
15 Correct 2 ms 4188 KB Output is correct
16 Correct 2 ms 4188 KB Output is correct
17 Correct 1 ms 4188 KB Output is correct
18 Correct 1 ms 4188 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 2 ms 4112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4184 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 2 ms 4140 KB Output is correct
5 Correct 2 ms 4288 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 2 ms 4184 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 2 ms 4188 KB Output is correct
12 Correct 2 ms 4160 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 2 ms 4188 KB Output is correct
15 Correct 2 ms 4188 KB Output is correct
16 Correct 2 ms 4188 KB Output is correct
17 Correct 2 ms 4188 KB Output is correct
18 Correct 2 ms 4188 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 2 ms 4188 KB Output is correct
21 Incorrect 2 ms 4240 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 301 ms 112760 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4444 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4184 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 1 ms 4188 KB Output is correct
9 Correct 2 ms 4188 KB Output is correct
10 Correct 3 ms 4188 KB Output is correct
11 Correct 2 ms 4288 KB Output is correct
12 Correct 1 ms 4188 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 2 ms 4188 KB Output is correct
15 Correct 1 ms 4188 KB Output is correct
16 Correct 2 ms 4188 KB Output is correct
17 Correct 2 ms 4280 KB Output is correct
18 Correct 2 ms 4188 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 2 ms 4184 KB Output is correct
21 Incorrect 3 ms 4188 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4184 KB Output is correct
2 Correct 2 ms 4184 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 2 ms 4188 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 2 ms 4188 KB Output is correct
12 Correct 1 ms 4188 KB Output is correct
13 Correct 1 ms 4188 KB Output is correct
14 Correct 2 ms 4260 KB Output is correct
15 Correct 2 ms 4188 KB Output is correct
16 Correct 2 ms 4288 KB Output is correct
17 Correct 2 ms 4192 KB Output is correct
18 Correct 2 ms 4188 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 2 ms 4188 KB Output is correct
21 Incorrect 2 ms 4188 KB Output isn't correct
22 Halted 0 ms 0 KB -