Submission #298744

#TimeUsernameProblemLanguageResultExecution timeMemory
298744Haunted_CppHorses (IOI15_horses)C++17
34 / 100
26 ms12288 KiB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 1e3 + 5;
const int MOD = 1e9 + 7;

vector<int> _X, _Y;

int _N;

int mult(int a, int b) {
  long long res = 1LL * a * b;
  if (res >= MOD) res %= MOD;
  return res;
}

int solve() {
  
  int where = 0;
  int best_multiplier = 0;
  long long road = 1;
  
  for (int i = 0; i < _N; i++) {
    long long nxt = 1LL * road * _X[i];
    if (nxt >= best_multiplier || (1LL * nxt * _Y[i] >= best_multiplier) ) {
      where = i;
      best_multiplier = _Y[i];
      road = 1;
      continue;
    }
    road = nxt;
  }
  
  int horses = 1;
  for (int i = 0; i <= where; i++) {
    horses = mult(horses, _X[i]);
  }
  return mult(horses, _Y[where]);

}

int init(int N, int X[], int Y[]) {
  assert(N <= MAX_N);
  _N = N;
  _X = _Y = vector<int>(N);
  for (int i = 0; i < N; i++) {
    _X[i] = X[i];
    _Y[i] = Y[i];
  }
	return solve();
}

int updateX(int pos, int val) {	
  _X[pos] = val;
	return solve();
}

int updateY(int pos, int val) {
  _Y[pos] = val;
	return solve();
}

Compilation message (stderr)

horses.cpp: In function 'int mult(int, int)':
horses.cpp:15:10: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   15 |   return res;
      |          ^~~
#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...