Submission #1348813

#TimeUsernameProblemLanguageResultExecution timeMemory
1348813ElayV13Horses (IOI15_horses)C++20
34 / 100
1595 ms12100 KiB
#include "horses.h"
#include "bits/stdc++.h"
using namespace std;

const int mod=1e9+7;
#define ll long long

int n;
vector<ll>x,y;

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];
      for(int bp=0;bp<N;bp++){
            ll cur=1;
            bool br=1;
            for(int j=bp+1;j<N;j++){
                  cur*=X[j];
                  if(cur*Y[j]>Y[bp]) br=0;
            }
            if(br){
                  ll res=1;
                  for(int j=0;j<=bp;j++){
                        res*=X[j];
                        res%=mod;
                        if(j==bp){
                              res*=Y[j];
                              res%=mod;
                        }
                  }
                  return res;
            }
      }
}

int updateX(int pos,int val)
{
      x[pos]=val;
      for(int bp=0;bp<n;bp++){
            ll cur=1;
            bool br=1;
            for(int j=bp+1;j<n;j++){
                  cur*=x[j];
                  if(cur>y[bp]){
                        br=0;
                        break;
                  }
                  if(cur*y[j]>y[bp]){
                        br=0;
                        break;
                  }
            }
            if(br){
                  ll res=1;
                  for(int j=0;j<=bp;j++){
                        res*=x[j];
                        res%=mod;
                        if(j==bp){
                              res*=y[j];
                              res%=mod;
                        }
                  }
                  return res;
            }
      }
}

int updateY(int pos,int val)
{
      y[pos]=val;
      for(int bp=0;bp<n;bp++){
            ll cur=1;
            bool br=1;
            for(int j=bp+1;j<n;j++){
                  cur*=x[j];
                  if(cur>y[bp]){
                        br=0;
                        break;
                  }
                  if(cur*y[j]>y[bp]){
                        br=0;
                        break;
                  }
            }
            if(br){
                  ll res=1;
                  for(int j=0;j<=bp;j++){
                        res*=x[j];
                        res%=mod;
                        if(j==bp){
                              res*=y[j];
                              res%=mod;
                        }
                  }
                  return res;
            }
      }
}

Compilation message (stderr)

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:37:1: warning: control reaches end of non-void function [-Wreturn-type]
   37 | }
      | ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:69:1: warning: control reaches end of non-void function [-Wreturn-type]
   69 | }
      | ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:101:1: warning: control reaches end of non-void function [-Wreturn-type]
  101 | }
      | ^
#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...