제출 #288491

#제출 시각아이디문제언어결과실행 시간메모리
288491AaronNaidu말 (IOI15_horses)C++14
17 / 100
874 ms13392 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

ll mod = 1000000007;
ll startOffWith = 1;
ld logStartOffWith = 0;
int n;
vector<ll> x, y;
vector<ld> prefSums;

int divide(ll num, ll denom) {
    ll inv = 1;
    ll expo = denom;
    for (int i = 0; i < 32; i++)
    {
        if ((mod-2) & (1<<i))
        {
            inv *= expo;
            inv %= mod;
        }
        expo *= expo;
        expo %= mod;
    }
    ll ans = num * inv;
    ans %= mod;
    return ans;
}

int solveProblem() {
    //cout << "Starting\n";
    int maxInd = -1;
    ld maxAns = -1;
    ld currAns = 0;
    for (int i = 0; i < n; i++)
    {
        currAns += log10(x[i]);
        currAns += log10(y[i]);
        if (currAns > maxAns)
        {
            maxAns = currAns;
            maxInd = i;
        }
        currAns -= log10(y[i]);
    }
    for (int i = 0; i < n-40; i++)
    {
        startOffWith *= x[i];
        startOffWith %= mod;
        logStartOffWith += log10(x[i]);
    }
    //cout << "half\n";
    ll finAns = 1;
    for (int i = 0; i < maxInd; i++)
    {
        finAns *= x[i];
        finAns %= mod;
    }
    finAns *= x[maxInd];
    finAns %= mod;
    finAns *= y[maxInd];
    finAns %= mod;
    return finAns;
}

int solveNewProblem() {
    int maxInd = -1;
    ld maxAns = -1;
    ld currAns = logStartOffWith;
    for (int i = max(n-40, 0); i < n; i++)
    {
        currAns += log10(x[i]);
        currAns += log10(y[i]);
        //prefSums[i] = currAns;
        if (currAns > maxAns)
        {
            maxAns = currAns;
            maxInd = i;
        }
        currAns -= log10(y[i]);
    }
    ll finAns = startOffWith;
    for (int i = max(n-40, 0); i < maxInd; i++)
    {
        finAns *= x[i];
        finAns %= mod;
    }
    finAns *= x[maxInd];
    finAns %= mod;
    finAns *= y[maxInd];
    finAns %= mod;
    return finAns;
}

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

int updateX(int pos, int val) {
    if (pos < n-40)
    {
        logStartOffWith -= log10(x[pos]);
        logStartOffWith += log10(val);
        startOffWith *= val;
        startOffWith = divide(startOffWith, x[pos]);
    }
    x[pos] = val;
    return solveNewProblem();
}

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

컴파일 시 표준 에러 (stderr) 메시지

horses.cpp: In function 'int divide(ll, ll)':
horses.cpp:28:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   28 |     return ans;
      |            ^~~
horses.cpp: In function 'int solveProblem()':
horses.cpp:64:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   64 |     return finAns;
      |            ^~~~~~
horses.cpp: In function 'int solveNewProblem()':
horses.cpp:93:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   93 |     return finAns;
      |            ^~~~~~
#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...