Submission #137351

#TimeUsernameProblemLanguageResultExecution timeMemory
137351eohomegrownappsHorses (IOI15_horses)C++14
17 / 100
1573 ms12552 KiB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll md = 1000000007;
vector<ll> x;
vector<ll> y;
ll n;

vector<ll> mult(vector<ll> a, ll b){
	ll carry = 0;
	ll mult = b;
	for (ll i = 0; i<a.size(); i++){
		a[i]*=mult;
		a[i]+=carry;
		carry=a[i]/md;
		a[i]%=md;
	}
	if (carry>0){
		a.push_back(carry);
	}
	return a;
}

bool geq(vector<ll> &a, vector<ll> &b){
	if (a.size()>b.size()){
		return true;
	} else if (a.size()<b.size()){
		return false;
	} else {
		for (int i = a.size()-1; i>=0; i--){
			if (a[i]>b[i]){
				return true;
			} else if (a[i]<b[i]){
				return false;
			}
		}
	}
	return true;
}

int query(){
	vector<ll> mx=vector<ll>(1,1);
	vector<ll> current=vector<ll>(1,1);
	for (ll i = 0; i<n; i++){
		current=mult(current,x[i]);
		/*cout<<"current"<<endl;
		for (ll i : current){
			cout<<i<<" ";
		}cout<<endl;*/
		auto ans = mult(current,y[i]);
		/*cout<<"ans"<<endl;
		for (ll i : ans){
			cout<<i<<" ";
		}cout<<endl;*/
		if (geq(ans,mx)){
			mx=ans;
		}
		/*cout<<"mx"<<endl;
		for (ll i : mx){
			cout<<i<<" ";
		}cout<<endl;*/
	}
	return mx[0];
}

int init(int N, int X[], int Y[]) {
	n=N;
	x.resize(n);
	y.resize(n);
	for (ll i = 0; i<n; i++){
		x[i]=X[i];
		y[i]=Y[i];
	}
	return query();
}

int updateX(int pos, int val) {
	x[pos]=val;
	return query();
}

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

Compilation message (stderr)

horses.cpp: In function 'std::vector<long long int> mult(std::vector<long long int>, ll)':
horses.cpp:13:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (ll i = 0; i<a.size(); i++){
                 ~^~~~~~~~~
horses.cpp: In function 'bool geq(std::vector<long long int>&, std::vector<long long int>&)':
horses.cpp:31:24: warning: conversion to 'int' from 'std::vector<long long int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
   for (int i = a.size()-1; i>=0; i--){
                ~~~~~~~~^~
horses.cpp: In function 'int query()':
horses.cpp:64:13: warning: conversion to 'int' from '__gnu_cxx::__alloc_traits<std::allocator<long long int> >::value_type {aka long long int}' may alter its value [-Wconversion]
  return mx[0];
             ^
#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...