Submission #929079

# Submission time Handle Problem Language Result Execution time Memory
929079 2024-02-17T16:26:49 Z OAleksa Horses (IOI15_horses) C++14
0 / 100
1500 ms 10076 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9 + 69;
const int N = 5e5 + 69;
int n, a[N], b[N], c[N];
int mul(int a, int b) {
   long long r = 1ll * a * b;
   if (r >= mod)
      r %= mod;
   return r;
}
int Solve() {
   int ptr = n - 1, s = a[n - 1];
   c[n - 1] = n - 1;
   for (int i = n - 2;i >= 0;i--) {
      if (a[i] > inf / s) {
         while (a[i] > inf / s) {
            s /= a[ptr];
            ptr--;
         }
         c[i] = ptr;
      }
      else {
         c[i] = c[i + 1];
         s *= a[i];
      }
   }
   long long ans = 1, x = a[0];
   int bst = 0;
   for (int i = 1;i < n;i++) {
      if (x > inf / a[i]) {
         x = a[i];
         bst = i;
      }
      else {
         x *= a[i];
         if (b[i] > b[bst] / x) {
            x = a[i];
            bst = i;
         }
      }
   }
   for (int i = 0;i <= bst;i++)
      ans = mul(ans, a[i]);
   return mul(ans, b[bst]);
}
int init(int N, int X[], int Y[]) {
   n = N;
   for (int i = 0;i < n;i++)
      a[i] = X[i], b[i] = Y[i];
   return Solve();
}

int updateX(int pos, int val) {
   a[pos] = val;
	return Solve();
}

int updateY(int pos, int val) {
	b[pos] = val;
	return Solve();
}
/*
3
2 1 3
3 4 1
1
2 1 2

*/

Compilation message

horses.cpp: In function 'int mul(int, int)':
horses.cpp:8:20: warning: declaration of 'b' shadows a global declaration [-Wshadow]
    8 | int mul(int a, int b) {
      |                ~~~~^
horses.cpp:7:14: note: shadowed declaration is here
    7 | int n, a[N], b[N], c[N];
      |              ^
horses.cpp:8:13: warning: declaration of 'a' shadows a global declaration [-Wshadow]
    8 | int mul(int a, int b) {
      |         ~~~~^
horses.cpp:7:8: note: shadowed declaration is here
    7 | int n, a[N], b[N], c[N];
      |        ^
horses.cpp:12:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   12 |    return r;
      |           ^
horses.cpp: In function 'int Solve()':
horses.cpp:46:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   46 |       ans = mul(ans, a[i]);
      |                 ^~~
horses.cpp:47:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   47 |    return mul(ans, b[bst]);
      |               ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:49:14: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   49 | int init(int N, int X[], int Y[]) {
      |          ~~~~^
horses.cpp:6:11: note: shadowed declaration is here
    6 | const int N = 5e5 + 69;
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1578 ms 10076 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -