Submission #609817

#TimeUsernameProblemLanguageResultExecution timeMemory
609817jairRSHorses (IOI15_horses)C++17
34 / 100
23 ms12288 KiB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAXN = 1000;
const ll MOD = 1'000'000'000LL + 7LL;
ll gN, gX[MAXN], gY[MAXN];

struct bignum{
	ll val = 0;
	bool overMOD = false;
	bignum(ll _val){
		overMOD = _val/MOD > 0;
		val = _val % MOD;
	}

	void scale(ll x){
		bignum newBignum = bignum(val * x);
		overMOD |= newBignum.overMOD;
		val = newBignum.val;
	}
};

int getAns(){
	bignum curAns(gY[gN - 1] * gX[gN - 1]);
	for (int i = gN - 2; i >= 0; i--)
	{
		if(!curAns.overMOD && gY[i] > curAns.val)
			curAns = bignum(gY[i] * gX[i]);
		else{
			curAns.scale(gX[i]);
		}
	}
	return curAns.val;
}

int init(int N, int X[], int Y[]) {
	gN = N;
	for (int i = 0; i < N; i++)
	{
		gX[i] = X[i];
		gY[i] = Y[i];
	}
	
	return getAns();
}

int updateX(int pos, int val) {	
	gX[pos] = val;
	return getAns();
}

int updateY(int pos, int val) {
	gY[pos] = val;
	return getAns();
}

Compilation message (stderr)

horses.cpp: In function 'int getAns()':
horses.cpp:27:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   27 |  for (int i = gN - 2; i >= 0; i--)
      |               ~~~^~~
horses.cpp:35:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   35 |  return curAns.val;
      |         ~~~~~~~^~~
#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...