답안 #935013

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
935013 2024-02-28T11:31:30 Z PagodePaiva 말 (IOI15_horses) C++17
17 / 100
24 ms 14676 KB
#include <bits/stdc++.h>
#include "horses.h"
#define N 500010

using namespace std;

int n;
long long v[N][2];
long long dp[N];
const int mod = 1e9+7;
long long p = 1;

long long binpow(long long a, long long b, long long m){
	a %= m;
	if(b == 0) return 1;
	long long t = binpow(a, b/2, m);
	if(b % 2 == 0) return (t*t) % m;
	else return ((((t*t) % m)*a) % m);
}

int solve(){
	if(n >= 40){
		return (p*v[n][1]) % mod;
	}
	else{
		long long aux = 1;
		for(int i = 1;i <= n;i++){
			aux *= v[i][0];
			if(aux > 1e9){
				return (p*v[n][1]) % mod;
			}
		}
	}
	dp[0] = 0;
	long long res = 0;
	for(int i = 1;i <= n;i++){
		dp[i] = 0;
		int prod = 1;
		for(int j = i;j > 0;j--){
			prod *= v[j][0];
			dp[i] = max(dp[i], dp[j-1] + ((prod-1)*v[i][1]));
			res = max(res, dp[j-1] + prod*v[i][1]);
		}
		// cout << dp[i] << ' ';
	}
	return res % mod;
}

int init(int NN, int X[], int Y[]) {
	n = NN;
	for(int i = 1;i <= n;i++){
		v[i][0] = X[i-1];
		p *= v[i][0];
		p %= mod;
		v[i][1] = Y[i-1];
	}
	return solve();
}

int updateX(int pos, int val) {
	p *= binpow(v[pos+1][0], mod-2, mod);	
	p %= mod;
	v[pos+1][0] = val;
	p *= val;
	p %= mod;
	return solve();
}

int updateY(int pos, int val) {
	v[pos+1][1] = val;
	return solve();
}

Compilation message

horses.cpp: In function 'int solve()':
horses.cpp:23:22: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   23 |   return (p*v[n][1]) % mod;
      |          ~~~~~~~~~~~~^~~~~
horses.cpp:29:7: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   29 |    if(aux > 1e9){
      |       ^~~
horses.cpp:30:24: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   30 |     return (p*v[n][1]) % mod;
      |            ~~~~~~~~~~~~^~~~~
horses.cpp:40:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   40 |    prod *= v[j][0];
      |    ~~~~~^~~~~~~~~~
horses.cpp:46:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   46 |  return res % mod;
      |         ~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Incorrect 1 ms 2396 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 14676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2592 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Incorrect 1 ms 2396 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Incorrect 1 ms 2396 KB Output isn't correct
22 Halted 0 ms 0 KB -