답안 #1017765

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017765 2024-07-09T10:03:50 Z Muhammet 말 (IOI15_horses) C++17
0 / 100
35 ms 38728 KB
#include <bits/stdc++.h>
#include "horses.h"

using namespace std;

#define ll long long

const ll M = 1e9 + 7;

int n;

vector <int> a, b;

int f(vector <int> a1, vector <int> b1){
	vector <int> a(1,0), b(1,0), p(1,1), mx(n+2,0);
	for(auto i : a1) a.push_back(i);
	for(auto i : b1) b.push_back(i);
	for(int i = 1; i <= n; i++){
		p[i] = p[i-1] * a[i];
	}
	for(int i = n; i >= 1; i--){
		mx[i] = max(mx[i+1], p[i] * b[i]);
	}
	int ind = 1;
	ll ans = 0, k = 0;
	for(int i = 1; i <= n; i++){
		if(p[i] * b[i] == mx[ind]){
			k = max(k,ans+((p[i] * (b[i])) / p[ind-1]));
			if(i == n) b[i]++;
			ans += ((p[i] * (b[i]-1)) / p[ind-1]);
			ind = i+1;
			ans %= M;
			k %= M;
		}
	}
	ans = max(ans,k);
	ans %= M;
	return ans;
}

int init(int N, int X[], int Y[]) {
	n = N;
	a.resize(n);
	b.resize(n);
	for(int i = 0; i < n; i++){
		a[i] = X[i];
		b[i] = Y[i];
	}
	return f(a,b);
}

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

int updateY(int pos, int val) {
	b[pos] = val;
	return f(a,b);
}

Compilation message

horses.cpp: In function 'int f(std::vector<int>, std::vector<int>)':
horses.cpp:15:15: warning: declaration of 'a' shadows a global declaration [-Wshadow]
   15 |  vector <int> a(1,0), b(1,0), p(1,1), mx(n+2,0);
      |               ^
horses.cpp:12:14: note: shadowed declaration is here
   12 | vector <int> a, b;
      |              ^
horses.cpp:15:23: warning: declaration of 'b' shadows a global declaration [-Wshadow]
   15 |  vector <int> a(1,0), b(1,0), p(1,1), mx(n+2,0);
      |                       ^
horses.cpp:12:17: note: shadowed declaration is here
   12 | vector <int> a, b;
      |                 ^
horses.cpp:38:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   38 |  return ans;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 1 ms 344 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Runtime error 1 ms 348 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 35 ms 38728 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Runtime error 1 ms 348 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 348 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -