Submission #719450

# Submission time Handle Problem Language Result Execution time Memory
719450 2023-04-05T22:58:00 Z thimote75 Horses (IOI15_horses) C++14
0 / 100
107 ms 55916 KB
#include "horses.h"

#include <bits/stdc++.h>
using namespace std;

#define ld long double
#define num long long

const num MOD = 1e9 + 7;

vector<num> X;
vector<num> Y;
vector<ld> lX;
vector<ld> lY;

int compute () {
	ld max_v = 0;
	ld sum_v = 0;

	num prod_v = 1;
	num mx_p_v = 0;

	for (int j = 0; j < lX.size(); j ++) {
		sum_v  += lX[j];
		ld cur_v = sum_v + lY[j];

		prod_v *= X[j];
		//prod_v %= MOD;

		if (cur_v > max_v) {
			max_v = cur_v;

			mx_p_v = prod_v * Y[j];
		}
	}

	int res0 = prod_v;
	int res1 = round(exp(max_v));
	if (res0 != res1) assert(false);
	return res0;
}

int init(int N, int _X[], int _Y[]) {
	X.resize(N);
	Y.resize(N);
	lX.resize(N);
	lY.resize(N);

	for (int i = 0; i < N; i ++) {
		X [i] = _X[i];
		Y [i] = _Y[i];
		lX[i] = log((ld) _X[i]);
		lY[i] = log((ld) _Y[i]);
	}

	return compute();
}

int updateX(int pos, int val) {
	X [pos] = val;
	lX[pos] = log((ld) val);
	return compute();
}

int updateY(int pos, int val) {
	Y [pos] = val;
	lY[pos] = log((ld) val);
	return compute();
}

Compilation message

horses.cpp: In function 'int compute()':
horses.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for (int j = 0; j < lX.size(); j ++) {
      |                  ~~^~~~~~~~~~~
horses.cpp:37:13: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   37 |  int res0 = prod_v;
      |             ^~~~~~
horses.cpp:38:18: warning: conversion from 'long double' to 'int' may change value [-Wfloat-conversion]
   38 |  int res1 = round(exp(max_v));
      |             ~~~~~^~~~~~~~~~~~
horses.cpp:21:6: warning: variable 'mx_p_v' set but not used [-Wunused-but-set-variable]
   21 |  num mx_p_v = 0;
      |      ^~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 107 ms 55916 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -