Submission #1013632

# Submission time Handle Problem Language Result Execution time Memory
1013632 2024-07-03T17:53:33 Z Mardonbekhazratov Horses (IOI15_horses) C++17
34 / 100
1500 ms 27076 KB
#include "horses.h"
#include<algorithm>
#include<vector>
#include<iostream>
const __int128_t INFLL=1e18;
const int INF=1e9;
const int MOD=1e9+7;

using namespace std;

int n;
vector<int>x,y;

int inv(int x){
	return x>1 ? MOD-(long long)(MOD/x)*inv(MOD%x)%MOD : x;
}

long long pref;

int get(){
	vector<__int128_t>suff(n+2);
	suff[n]=1;
	long long pr=pref;
	for(int i=n-1;i>=0;i--){
		suff[i]=max(suff[i+1]*x[i],suff[n]*x[i]*y[i]);
		pr=pr*inv(x[i])%MOD;
		if(suff[i]>=INFLL){
			long long ans=suff[i]%MOD;
			return pr*ans%MOD;
		}
	}
	return suff[0]%MOD;
}

int init(int N, int X[], int Y[]) {
	n=N;
	pref=1;
	x.resize(n);
	y.resize(n);
	for(int i=0;i<n;i++) x[i]=X[i],y[i]=Y[i],pref=pref*x[i]%MOD;
	return get();
}


int updateX(int pos, int val) {	
	pref=pref*inv(x[pos])%MOD*val%MOD;
	x[pos]=val;
	return get();
}

int updateY(int pos, int val) {
	y[pos]=val;
	return get();
}

Compilation message

horses.cpp: In function 'int inv(int)':
horses.cpp:14:13: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   14 | int inv(int x){
      |         ~~~~^
horses.cpp:12:12: note: shadowed declaration is here
   12 | vector<int>x,y;
      |            ^
horses.cpp:15:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   15 |  return x>1 ? MOD-(long long)(MOD/x)*inv(MOD%x)%MOD : x;
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int get()':
horses.cpp:28:25: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<__int128>, __int128>::value_type' {aka '__int128'} to 'long long int' may change value [-Wconversion]
   28 |    long long ans=suff[i]%MOD;
horses.cpp:29:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   29 |    return pr*ans%MOD;
      |           ~~~~~~^~~~
horses.cpp:32:16: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<__int128>, __int128>::value_type' {aka '__int128'} to 'int' may change value [-Wconversion]
   32 |  return suff[0]%MOD;
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 432 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 436 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 1 ms 448 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 4 ms 448 KB Output is correct
28 Correct 2 ms 448 KB Output is correct
29 Correct 6 ms 444 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 6 ms 348 KB Output is correct
32 Correct 6 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1587 ms 17372 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 432 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 4 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 7 ms 348 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 6 ms 348 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 1419 ms 20032 KB Output is correct
34 Correct 1355 ms 20336 KB Output is correct
35 Correct 1357 ms 27076 KB Output is correct
36 Correct 1335 ms 26860 KB Output is correct
37 Execution timed out 1566 ms 18132 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 3 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 6 ms 444 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 6 ms 348 KB Output is correct
32 Correct 6 ms 348 KB Output is correct
33 Execution timed out 1593 ms 18364 KB Time limit exceeded
34 Halted 0 ms 0 KB -