Submission #929085

# Submission time Handle Problem Language Result Execution time Memory
929085 2024-02-17T16:31:53 Z OAleksa Horses (IOI15_horses) C++14
17 / 100
1500 ms 10072 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 = 1;
         bst = i;
      }
      else {
         x *= a[i];
         if (b[i] > b[bst] / x) {
            x = 1;
            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 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4544 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4696 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4540 KB Output is correct
22 Runtime error 4 ms 8792 KB Execution killed with signal 8
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1512 ms 10072 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 Correct 1 ms 4696 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4544 KB Output is correct
22 Runtime error 4 ms 8796 KB Execution killed with signal 8
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Runtime error 4 ms 8796 KB Execution killed with signal 8
23 Halted 0 ms 0 KB -