답안 #989035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
989035 2024-05-27T10:17:09 Z crafticat 말 (IOI15_horses) C++17
34 / 100
1500 ms 10564 KB
#include <bits/stdc++.h>

using namespace std;
constexpr int MOD = 1e9 + 7;
using ll = __int128;

vector<int> x, y;
int n;

int solve() {
    ll mult = 1;
    ll start = 0;
    ll ans = 0;

    for (int i = n - 1; i >= 0; --i) {
        mult *= x[i];
        if (mult >= MOD) {
            start = i;
            break;
        }
    }
    mult = 1;
    for (int i = 0; i < start; ++i) {
        mult *= x[i];
        mult %= MOD;
    }
    for (int i = start; i < n; ++i) {
        mult *= x[i];
        ans = max(ans, mult * y[i]);
    }
    return ans % MOD;
}

int init(int N, int X[], int Y[]) {
    n = N;
    x.resize(N);
    y.resize(N);
    for (int i = 0; i < N; ++i) {
        x[i] = X[i];
        y[i] = Y[i];
    }

    return solve();
}
int updateX(int pos, int val) {
    x[pos] = val;
    return solve();
}
int updateY(int pos, int val) {
    y[pos] = val;
    return solve();
}

#if DEBUG
static char _buffer[1024];
static int _currentChar = 0;
static int _charsNumber = 0;
static FILE *_inputFile, *_outputFile;

static inline int _read() {
    if (_charsNumber < 0) {
        exit(1);
    }
    if (!_charsNumber || _currentChar == _charsNumber) {
        _charsNumber = (int)fread(_buffer, sizeof(_buffer[0]), sizeof(_buffer), _inputFile);
        _currentChar = 0;
    }
    if (_charsNumber <= 0) {
        return -1;
    }
    return _buffer[_currentChar++];
}

static inline int _readInt() {
    int c, x, s;
    c = _read();
    while (c <= 32) c = _read();
    x = 0;
    s = 1;
    if (c == '-') {
        s = -1;
        c = _read();
    }
    while (c > 32) {
        x *= 10;
        x += c - '0';
        c = _read();
    }
    if (s < 0) x = -x;
    return x;
}


int main() {
	_inputFile = fopen("horses.in", "rb");

	int N; N = _readInt();

	int *X = (int*)malloc(sizeof(int)*(unsigned int)N);
	int *Y = (int*)malloc(sizeof(int)*(unsigned int)N);

	for (int i = 0; i < N; i++) {
		X[i] = _readInt();
	}

	for (int i = 0; i < N; i++) {
		Y[i] = _readInt();
	}

	cout << init(N,X,Y) << endl;

	int M; M = _readInt();

	for (int i = 0; i < M; i++) {
		int type; type = _readInt();
		int pos; pos = _readInt();
		int val; val = _readInt();

		if (type == 1) {
			cout << updateX(pos,val) << endl;
		} else if (type == 2) {
            cout << updateY(pos,val) << endl;
		}
	}

	return 0;
}
#endif

Compilation message

horses.cpp: In function 'int solve()':
horses.cpp:27:18: warning: conversion from 'll' {aka '__int128'} to 'int' may change value [-Wconversion]
   27 |     for (int i = start; i < n; ++i) {
      |                  ^~~~~
horses.cpp:31:16: warning: conversion from 'll' {aka '__int128'} to 'int' may change value [-Wconversion]
   31 |     return ans % MOD;
      |            ~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 352 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 360 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 356 KB Output is correct
14 Correct 1 ms 360 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 352 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 356 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 0 ms 360 KB Output is correct
23 Correct 6 ms 360 KB Output is correct
24 Correct 6 ms 360 KB Output is correct
25 Correct 8 ms 712 KB Output is correct
26 Correct 8 ms 492 KB Output is correct
27 Correct 6 ms 484 KB Output is correct
28 Correct 6 ms 456 KB Output is correct
29 Correct 6 ms 476 KB Output is correct
30 Correct 6 ms 352 KB Output is correct
31 Correct 6 ms 360 KB Output is correct
32 Correct 6 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1573 ms 8268 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 6 ms 348 KB Output is correct
24 Correct 6 ms 444 KB Output is correct
25 Correct 7 ms 348 KB Output is correct
26 Correct 8 ms 480 KB Output is correct
27 Correct 6 ms 348 KB Output is correct
28 Correct 7 ms 348 KB Output is correct
29 Correct 5 ms 444 KB Output is correct
30 Correct 6 ms 348 KB Output is correct
31 Correct 5 ms 348 KB Output is correct
32 Correct 6 ms 348 KB Output is correct
33 Execution timed out 1503 ms 10564 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 6 ms 348 KB Output is correct
24 Correct 6 ms 348 KB Output is correct
25 Correct 7 ms 484 KB Output is correct
26 Correct 7 ms 348 KB Output is correct
27 Correct 6 ms 348 KB Output is correct
28 Correct 6 ms 348 KB Output is correct
29 Correct 5 ms 440 KB Output is correct
30 Correct 6 ms 476 KB Output is correct
31 Correct 6 ms 344 KB Output is correct
32 Correct 5 ms 348 KB Output is correct
33 Execution timed out 1580 ms 9152 KB Time limit exceeded
34 Halted 0 ms 0 KB -