Submission #316190

#TimeUsernameProblemLanguageResultExecution timeMemory
316190mohamedsobhi777말 (IOI15_horses)C++14
17 / 100
24 ms16888 KiB
#include "horses.h"
#include <bits/stdc++.h>

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 (cnt > 30 || suf > 1e9)
                        break;
        }
        ret = eval(i - 1);
        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);
}

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:42:33: warning: conversion from 'll' {aka 'long long int'} to 'double' may change value [-Wconversion]
   42 |                 if (cnt > 30 || suf > 1e9)
      |                                 ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:66:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   66 |         return solve();
      |                ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:72:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   72 |         return solve();
      |                ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:78:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   78 |         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...