Submission #304849

#TimeUsernameProblemLanguageResultExecution timeMemory
304849jainbot27Horses (IOI15_horses)C++17
17 / 100
74 ms32248 KiB
#include <bits/stdc++.h>
// #include "horses.h"
using namespace std;

#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()

#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, z, y) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, 0, z)
#define trav(x, y) for(auto&x:y)

using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
using ld = long double;

template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const char nl = '\n';
const int mxN = 2e5 + 10;
const int MOD = 1e9 + 7;
const long long infLL = 1e18;

// modulo class
int fact[mxN];
int add(int x, int y){ x += y; while(x >= MOD) x -= MOD; while(x < 0) x += MOD; return x; } void ad(int &x, int y) {x = add(x, y);}
int sub(int x, int y){ x -= y; while(x >= MOD) x -= MOD; while(x < 0) x += MOD; return x; } void sb(int &x, int y) {x = sub(x, y);}
int mul(int x, int y){ return ((int64_t)x * (int64_t)y) % MOD; } void ml(int &x, int y) {x = mul(x, y);}
int binpow(int x, int y){ int z = 1; while(y > 0) { if(y % 2 == 1) z = mul(z, x); x = mul(x, x); y /= 2; } return z; }
int inv(int x){ return binpow(x, MOD - 2); }
int divide(int x, int y){ return mul(x, inv(y)); }
void precalc(){ fact[0] = 1; for(int i = 1; i < mxN; i++) fact[i] = mul(i, fact[i - 1]); }
int choose(int n, int k){ if(k > n) return 0; return divide(fact[n], mul(fact[n - k], fact[k])); }

int n; vi x, y; vector<ld> lg;

int init(int _n, int _x[], int _y[]){
    n = _n; x.resize(n); y.resize(n); lg.resize(n);
    F0R(i, n) x[i] = _x[i];
    F0R(i, n) y[i] = _y[i];
    F0R(i, n){
        lg[i] = log(x[i]) + (i==0?log(1):lg[i-1]);
    }
    F0R(i, n){
        lg[i] = lg[i] + log(y[i]);
        // cerr << lg[i] << endl;
    }
    int pos = 0; ld best = 0;
    F0R(i, n){
        if(ckmax(best, lg[i])){
            pos = i;
        } 
    }
        // cerr << pos << endl;
    int amt = 1;
    F0R(i, pos+1){
        ml(amt, x[i]);
    }
    // cerr << amt << endl;
    return mul(amt, y[pos]);
}
int updateX(int pos, int val){
    throw;
}
int updateY(int pos, int val){
    throw;
}
// int main(){
//     int _x[] = {2, 1, 3};
//     int _y[] = {3, 4, 1};
//     int n =3;
//     cout << init(n, _x, _y) << nl;
// }

Compilation message (stderr)

horses.cpp: In function 'int mul(int, int)':
horses.cpp:38:57: warning: conversion from 'int64_t' {aka 'long int'} to 'int' may change value [-Wconversion]
   38 | int mul(int x, int y){ return ((int64_t)x * (int64_t)y) % MOD; } void ml(int &x, int y) {x = mul(x, y);}
      |                               ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:72:17: warning: unused parameter 'pos' [-Wunused-parameter]
   72 | int updateX(int pos, int val){
      |             ~~~~^~~
horses.cpp:72:26: warning: unused parameter 'val' [-Wunused-parameter]
   72 | int updateX(int pos, int val){
      |                      ~~~~^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:75:17: warning: unused parameter 'pos' [-Wunused-parameter]
   75 | int updateY(int pos, int val){
      |             ~~~~^~~
horses.cpp:75:26: warning: unused parameter 'val' [-Wunused-parameter]
   75 | int updateY(int pos, int val){
      |                      ~~~~^~~
#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...