Submission #1011270

#TimeUsernameProblemLanguageResultExecution timeMemory
1011270MardonbekhazratovHorses (IOI15_horses)C++17
17 / 100
1548 ms18436 KiB
#include "horses.h" #include<algorithm> #include<vector> #include<iostream> const long long INFLL=1e18; const int INF=1e9; const int MOD=1e9+7; using namespace std; int n; vector<int>x,y; long long merge(long long a,long long b){ __int128_t f=a,g=b; if(f*g>INFLL) return INFLL; long long h=f*g; return h; } int get(){ vector<long long>pref(n+1),suff(n+2); pref[0]=suff[n+1]=1; for(int i=0;i<n;i++){ pref[i+1]=pref[i]*x[i]%MOD; suff[n-i]=max(merge(suff[n-i+1],x[n-i-1]),merge(x[n-i-1],y[n-i-1])); } int id=-1; long long ans=0,cur=1; for(int i=0;i<n;i++){ if(suff[i+1]!=INFLL){ if(i!=0 && x[i-1]*y[i-1]>suff[i+1]) return pref[i]*y[i-1]%MOD; return suff[i+1]%MOD*pref[i]%MOD; } } return -1; } int init(int N, int X[], int Y[]) { n=N; x.resize(n); y.resize(n); for(int i=0;i<n;i++) x[i]=X[i],y[i]=Y[i]; return get(); } int updateX(int pos, int val) { x[pos]=val; return get(); } int updateY(int pos, int val) { y[pos]=val; return get(); }

Compilation message (stderr)

horses.cpp: In function 'long long int merge(long long int, long long int)':
horses.cpp:17:15: warning: conversion from '__int128' to 'long long int' may change value [-Wconversion]
   17 |  long long h=f*g;
      |              ~^~
horses.cpp: In function 'int get()':
horses.cpp:32:61: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
   32 |    if(i!=0 && x[i-1]*y[i-1]>suff[i+1]) return pref[i]*y[i-1]%MOD;
horses.cpp:33:32: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
   33 |    return suff[i+1]%MOD*pref[i]%MOD;
horses.cpp:28:6: warning: unused variable 'id' [-Wunused-variable]
   28 |  int id=-1;
      |      ^~
horses.cpp:29:12: warning: unused variable 'ans' [-Wunused-variable]
   29 |  long long ans=0,cur=1;
      |            ^~~
horses.cpp:29:18: warning: unused variable 'cur' [-Wunused-variable]
   29 |  long long ans=0,cur=1;
      |                  ^~~
#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...