답안 #1088727

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1088727 2024-09-14T22:14:58 Z gustavo_d 말 (IOI15_horses) C++17
0 / 100
28 ms 33552 KB
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MAXN = 500000;
const ll MOD = 1e9+7;
int n;
vector<ll> x(MAXN), y(MAXN), qtd(MAXN);

int init(int N, int X[], int Y[]) {
	n = N+1;
	y[0] = 0; x[0] = 1;
	for (int i=1; i<n; i++) x[i] = (ll)X[i-1];
	for (int i=1; i<n; i++) y[i] = (ll)Y[i-1];

	qtd[0] = 1;
	int pt = 0; ll since = 1;
	for (int i=1; i<n; i++) {
		qtd[i] = (qtd[i-1] * x[i]) % MOD;
		since *= x[i];
		while (since * y[i] > y[pt]) {
			since /= x[pt];
			pt++;
		}
	}
	ll mx = 0; int pt_mx = 0;
	ll ac = 1;
	for (; pt<n; pt++) {
		if (ac * y[pt] >= mx) pt_mx = pt;
		mx = max(mx, ac * y[pt]);
		ac *= x[pt];
	}
	return (qtd[pt_mx] * y[pt_mx]) % MOD;
	// int dp[n][MX_COW+1];
	// for (int i=1; i<=MX_COW; i++) {
	// 	dp[0][i] = -1e9;
	// }
	// dp[0][1] = 0;
	// for (int i=1; i<n; i++) {
	// 	for (int cow=0; cow<=MX_COW; cow++) {
	// 		dp[i][cow] = -1e9;
	// 		for (int v=0; v<=MX_COW; v++) {
	// 			if ((cow+v)/x[i] > MX_COW) continue;
	// 			if ((cow+v) % x[i] != 0) continue;
	// 			dp[i][cow] = max(
	// 				dp[i][cow],
	// 				dp[i-1][(cow + v) / x[i]] + v * y[i]
	// 			);
	// 		}
	// 	}
	// }
	// return dp[n-1][0];
}

int updateX(int pos, int val) {	
	x[pos+1] = val;
	qtd[0] = 1;
	int pt = 0; ll since = 1;
	for (int i=1; i<n; i++) {
		qtd[i] = (qtd[i-1] * x[i]) % MOD;
		since *= x[i];
		while (since * y[i] > y[pt]) {
			since /= x[pt];
			pt++;
		}
	}
	ll mx = 0; int pt_mx = 0;
	ll ac = 1;
	for (; pt<n; pt++) {
		if (ac * y[pt] >= mx) pt_mx = pt;
		mx = max(mx, ac * y[pt]);
		ac *= x[pt];
	}
	return (qtd[pt_mx] * y[pt_mx]) % MOD;
}

int updateY(int pos, int val) {
	y[pos+1] = val;
	qtd[0] = 1;
	int pt = 0; ll since = 1;
	for (int i=1; i<n; i++) {
		qtd[i] = (qtd[i-1] * x[i]) % MOD;
		since *= x[i];
		while (since * y[i] > y[pt]) {
			since /= x[pt];
			pt++;
		}
	}
	ll mx = 0; int pt_mx = 0;
	ll ac = 1;
	for (; pt<n; pt++) {
		if (ac * y[pt] >= mx) pt_mx = pt;
		mx = max(mx, ac * y[pt]);
		ac *= x[pt];
	}
	return (qtd[pt_mx] * y[pt_mx]) % MOD;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:35:33: 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]
   35 |  return (qtd[pt_mx] * y[pt_mx]) % MOD;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:76:33: 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]
   76 |  return (qtd[pt_mx] * y[pt_mx]) % MOD;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:98:33: 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]
   98 |  return (qtd[pt_mx] * y[pt_mx]) % MOD;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 24152 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 24152 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 28 ms 33552 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 24156 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 24176 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -