Submission #428193

#TimeUsernameProblemLanguageResultExecution timeMemory
428193haxormanHorses (IOI15_horses)C++14
17 / 100
1576 ms37572 KiB
#include "horses.h"
#include "bits/stdc++.h"
using namespace std;

const int mxN = 5e5 + 7;
const int MOD = 1e9 + 7;

int n;
long long x[mxN], y[mxN];

int rec(int i, long long horses) {
	horses *= x[i];
	if (i == n - 1) {
		return (y[i] * horses) % MOD;
	}

	long long keep = rec(i + 1, horses);
	long long sell = rec(i + 1, 1) + y[i] * (horses - 1);
	long long finish = y[i] * horses;

	return max({keep, sell, finish}) % MOD;
}

int init(int N, int X[], int Y[]) {
	n = N;
	for (int i = 0; i < n; ++i) {
		x[i] = X[i];
		y[i] = Y[i];
	}
	return rec(0, 1);
}

int updateX(int pos, int val) {
	x[pos] = val;
	return rec(0, 1);
}

int updateY(int pos, int val) {
	y[pos] = val;
	return rec(0, 1);
}

Compilation message (stderr)

horses.cpp: In function 'int rec(int, long long int)':
horses.cpp:14:26: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   14 |   return (y[i] * horses) % MOD;
      |          ~~~~~~~~~~~~~~~~^~~~~
horses.cpp:21:35: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   21 |  return max({keep, sell, finish}) % MOD;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...