# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
597017 |
2022-07-15T11:47:10 Z |
PiejanVDC |
Horses (IOI15_horses) |
C++17 |
|
1500 ms |
8336 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
vector<int>x,y;
long long mod = (long long)1e9+7;
int init(int n, int X[], int Y[]) {
for(int i = 0 ; i < n ; i++)
x.push_back(X[i]), y.push_back(Y[i]);
int last = -1;
long long got = 1;
long long ans = 0;
long long curr = 0;
long long prev = -1;
while(last < n-1) {
for(int i = last+1 ; i < n ; i++) {
got *= x[i];
got %= mod;
if((y[i] * (got-1))%mod > prev%mod)
last = i, prev = y[i] * (got-1);
prev %= mod;
// + case where you sell all of them
ans = max(ans, (curr + y[i] * got)%mod);
ans %= mod;
}
curr += prev;
curr %= mod;
prev = -1;
got = 1;
}
ans = max(ans, curr);
return ans;
}
int updateX(int p, int val) {
int n = (int)x.size();
x[p] = val;
int last = -1;
long long got = 1;
long long ans = 0;
long long curr = 0;
long long prev = -1;
while(last < n-1) {
for(int i = last+1 ; i < n ; i++) {
got *= x[i];
got %= mod;
if((y[i] * (got-1))%mod > prev%mod)
last = i, prev = y[i] * (got-1);
prev %= mod;
// + case where you sell all of them
ans = max(ans, (curr + y[i] * got)%mod);
ans %= mod;
}
curr += prev;
curr %= mod;
prev = -1;
got = 1;
}
ans = max(ans, curr);
return ans;
}
int updateY(int p, int val) {
int n = (int)x.size();
y[p] = val;
int last = -1;
long long got = 1;
long long ans = 0;
long long curr = 0;
long long prev = -1;
while(last < n-1) {
for(int i = last+1 ; i < n ; i++) {
got *= x[i];
got %= mod;
if((y[i] * (got-1))%mod > prev%mod)
last = i, prev = y[i] * (got-1);
prev %= mod;
// + case where you sell all of them
ans = max(ans, (curr + y[i] * got)%mod);
ans %= mod;
}
curr += prev;
curr %= mod;
prev = -1;
got = 1;
}
ans = max(ans, curr);
return ans;
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:36:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
36 | return ans;
| ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:67:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
67 | return ans;
| ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:98:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
98 | return ans;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
224 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1576 ms |
8336 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |