| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1038344 | SonicML | 말 (IOI15_horses) | C++14 | 1034 ms | 16024 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include "horses.h"
#include <cmath>
using namespace std;
int const MODULO = 1e9+7;
int n, bucketSize, bucketNum;
int const NMAX = 5e5;
int x[1 + NMAX];
int y[1 + NMAX];
int preX[1 + NMAX];
int sufX[1 + NMAX];
int const BMAX = 750;
int bbest[1 + BMAX];
int prod[1 + BMAX];
bool compare(int a, int b) {
if(b == -1 || a <= b) {
return true;
}
return false;
}
int multiply(int a, int b) {
if(a == -1 || b == -1 || (1LL * a * b >= MODULO )) {
return -1;
}
return (a * b);
}
void buildBucket(int index) {
int from = 1 + (index-1)*bucketSize, to = index*bucketSize;
int pre = 1, suf = 1;
prod[index] = 1;
for(int i = from;i <= to;i++) {
pre = multiply(pre, x[i]);
prod[index] = (1LL * prod[index] * x[i]) % MODULO;
preX[i] = pre;
}
for(int i = to;i >= from;i--) {
suf = multiply(suf, x[i]);
sufX[i] = suf;
}
int best = from, multBest = y[from], multAux = 1;
for(int i = from+1;i <= to;i++) {
multAux = multiply(multAux, x[i]);
if(compare(multBest, multiply(multAux, y[i]))) {
best = i;
multBest = y[best];
multAux = 1;
}
}
bbest[index] = best;
}
int computeSol() {
int best = bbest[1], multBest = y[bbest[1]], multAux = 1;
int prev = best;
for(int index = 2;index <= bucketNum;index++) {
int suf = 1, pre = 1;
if(prev % bucketSize != 0) {
suf = sufX[prev+1];
}
pre = preX[bbest[index]];
multAux = multiply(multAux, multiply(suf, pre));
if(compare(multBest, multiply(multAux, y[bbest[index]]))) {
best = bbest[index];
multBest = y[best];
multAux = 1;
}
prev = bbest[index];
}
int ans = 1, start = 1;
for(int index = 1;index * bucketSize < best;index++) {
ans = (1LL * ans * prod[index]) % MODULO;
start = index * bucketSize + 1;
}
for(int i = start;i <= best;i++) {
ans = (1LL * ans * x[i]) % MODULO;
}
ans = (1LL * ans * y[best]) % MODULO;
return ans;
}
int init(int N, int X[], int Y[]) {
n = N;
bucketSize = sqrt(n);
bucketNum = (n-1)/bucketSize+1;
for(int i = 1;i <= n;i++) {
x[i] = X[i-1];
y[i] = Y[i-1];
}
for(int i = 1;i <= bucketNum;i++) {
buildBucket(i);
}
return computeSol();
}
int updateX(int pos, int val) {
int bucketIndex = (pos-1)/bucketSize+1;
x[pos] = val;
buildBucket(bucketIndex);
return computeSol();
}
int updateY(int pos, int val) {
int bucketIndex = (pos-1)/bucketSize+1;
y[pos] = val;
buildBucket(bucketIndex);
return computeSol();
}컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
