Submission #316210

#TimeUsernameProblemLanguageResultExecution timeMemory
316210mohamedsobhi777Horses (IOI15_horses)C++14
17 / 100
22 ms14732 KiB
#include "horses.h"
#include <bits/stdc++.h>
#pragma GCC optimize("trapv")

using namespace std;
using ll = long long;
using ld = long double;

const int _N = 2e5 + 7, mod = 1e9 + 7;
const ll inf = 2e18;
int n, m;
ll X[_N], Y[_N];

ll mul(ll x, ll y)
{
        return 1ll * x * y % mod;
}

ll eval(int x)
{
        ll ret = 1ll;
        for (int i = 0; i <= x; ++i)
        {
                ret = mul(ret, X[i]);
        }
        return ret;
}

ll add(ll x, ll y)
{
        return (x + y >= mod ? x + y - mod : x + y);
}
ll solve()
{
        ll ret = 1ll;
        ll suf = 1ll;
        int i = n - 1;
        int cnt = 0;
        for (; ~i; --i)
        {
                suf = 1ll * suf * X[i];
                //cnt += (X[i] > 1);
                if (suf >= 2e9)
                {
                        --i;
                        break;
                }
        }
        ret = eval(i);
        ll all = 1ll;
        ll Max = 1ll;
        for (++i; i < n; ++i)
        {
                //  cout << i << " " << all << " " << Y[i] << "*\n";
                all *= X[i];
                Max = max(Max, 1ll * all * Y[i]);
        }
        //cout << "\n";
        return mul(ret, Max % 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 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 'll solve()':
horses.cpp:43:21: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
   43 |                 if (suf >= 2e9)
      |                     ^~~
horses.cpp:38:13: warning: unused variable 'cnt' [-Wunused-variable]
   38 |         int cnt = 0;
      |             ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:70:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   70 |         return solve();
      |                ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:76:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   76 |         return solve();
      |                ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:82:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   82 |         return solve();
      |                ~~~~~^~
#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...