답안 #1003235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003235 2024-06-20T08:08:20 Z Ausp3x 말 (IOI15_horses) C++17
54 / 100
1500 ms 21704 KB
// 人外有人,天外有天
// author: Ausp3x
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include "horses.h"
typedef long long             lng;
typedef unsigned int          uint;
typedef unsigned long long    ulng;
using namespace std;
using namespace __gnu_pbds;
 
int const INF32 = 0x3f3f3f3f;
lng const INF64 = 0x3f3f3f3f3f3f3f3f;
 
int const MOD = 1000000007;
 
int N;
vector<int> X, Y;
 
lng modPow(lng x, lng y) {
    lng res = 1;
 
    while (y > 0) {
        if (y & 1) {
            res *= x;
            res %= MOD;
        }
 
        y >>= 1;
        x *= x;
        x %= MOD;
    }
 
    return (res + MOD) % MOD;
}
 
lng almostAllHorses = 1;
int getMaxValue(int opt) {
    if (opt == 1) {
        lng horses = 1;
        for (int i = 0; i < N; i++) {
            (horses *= X[i]) %= MOD;
            
            bool chk = true;
            lng cur = 1; 
            for (int j = i + 1; j < N; j++) {
                if (cur == INF32 || cur * X[j] > INF32) {
                    chk = false;
                    break;
                }
                cur *= X[j];
 
                if (cur * Y[j] > Y[i]) {
                    chk = false;
                    break;
                }
            }
                
            if (chk) {
                return horses * Y[i] % MOD;
            }
        }
    } else if (opt == 2) {
        lng horses = almostAllHorses;
        for (int i = max(N - 64, 0); i < N; i++) {
            (horses *= X[i]) %= MOD;
            
            bool chk = true;
            lng cur = 1; 
            for (int j = i + 1; j < N; j++) {
                if (cur == INF32 || cur * X[j] > INF32) {
                    chk = false;
                    break;
                }
                cur *= X[j];
 
                if (cur * Y[j] > Y[i]) {
                    chk = false;
                    break;
                }
            }
                
            if (chk) {
                return horses * Y[i] % MOD;
            }
        }
    }
 
    return -1;
}
 
bool allXG1 = true;
int init(int n, int x[], int y[]) {
    N = n;
    X.clear();
    X.resize(n);
    Y.clear();
    Y.resize(n);
    for (int i = 0; i < N; i++) {
        if (i < N - 64)
            (almostAllHorses *= x[i]) %= MOD;
        
        if (x[i] < 2)
            allXG1 = false;
 
        X[i] = x[i];
        Y[i] = y[i];
    }
 
	return (allXG1 ? getMaxValue(2) : getMaxValue(1));
}
 
bool allValG1 = true;
int updateX(int pos, int val) {
    if (pos < N - 64) {
        (almostAllHorses *= modPow(X[pos], MOD - 2)) %= MOD;
        (almostAllHorses *= val) %= MOD;
    }
 
    if (val < 2)
        allValG1 = false;
    
    X[pos] = val;
 
	return (allXG1 && allValG1 ? getMaxValue(2) : getMaxValue(1));
}
 
int updateY(int pos, int val) {    
    Y[pos] = val;
 
	return (allXG1 && allValG1 ? getMaxValue(2) : getMaxValue(1));
}

/*
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    // cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int x[n];
        for (int i = 0; i < n; i++) {
            cin >> x[i];
        }
        int y[n];
        for (int i = 0; i < n; i++) {
            cin >> y[i];
        }

        cout << init(n, x, y) << endl;

        int m;
        cin >> m;
        while (m--) {
            int opt, pos, val;
            cin >> opt >> pos >> val;
            if (opt == 1) {
                cout << opt << ' ' << pos << ' ' << val << ' ';
                cout << updateX(pos, val) << endl;
            } else if (opt == 2) {
                cout << opt << ' ' << pos << ' ' << val << ' ';
                cout << updateY(pos, val) << endl;
            }
        }
    }

    return 0;
}
//*/

Compilation message

horses.cpp: In function 'int getMaxValue(int)':
horses.cpp:61:38: warning: conversion from 'lng' {aka 'long long int'} to 'int' may change value [-Wconversion]
   61 |                 return horses * Y[i] % MOD;
      |                        ~~~~~~~~~~~~~~^~~~~
horses.cpp:85:38: warning: conversion from 'lng' {aka 'long long int'} to 'int' may change value [-Wconversion]
   85 |                 return horses * Y[i] % 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 432 KB Output is correct
5 Correct 0 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 348 KB Output is correct
9 Correct 0 ms 436 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 436 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 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 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 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 1 ms 348 KB Output is correct
22 Correct 0 ms 600 KB Output is correct
23 Correct 8 ms 348 KB Output is correct
24 Correct 6 ms 472 KB Output is correct
25 Correct 4 ms 444 KB Output is correct
26 Correct 5 ms 348 KB Output is correct
27 Correct 13 ms 348 KB Output is correct
28 Correct 4 ms 344 KB Output is correct
29 Correct 168 ms 444 KB Output is correct
30 Correct 60 ms 348 KB Output is correct
31 Correct 112 ms 448 KB Output is correct
32 Correct 278 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 12968 KB Output is correct
2 Correct 117 ms 21700 KB Output is correct
3 Correct 65 ms 12864 KB Output is correct
4 Correct 90 ms 16828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 436 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 1 ms 500 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 440 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 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 344 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 1 ms 348 KB Output is correct
23 Correct 6 ms 468 KB Output is correct
24 Correct 5 ms 348 KB Output is correct
25 Correct 5 ms 600 KB Output is correct
26 Correct 5 ms 348 KB Output is correct
27 Correct 11 ms 464 KB Output is correct
28 Correct 5 ms 344 KB Output is correct
29 Correct 171 ms 440 KB Output is correct
30 Correct 63 ms 476 KB Output is correct
31 Correct 115 ms 440 KB Output is correct
32 Correct 311 ms 348 KB Output is correct
33 Execution timed out 1535 ms 12124 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 344 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 348 KB Output is correct
12 Correct 1 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 1 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 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 6 ms 468 KB Output is correct
24 Correct 6 ms 348 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 5 ms 348 KB Output is correct
27 Correct 11 ms 348 KB Output is correct
28 Correct 6 ms 348 KB Output is correct
29 Correct 159 ms 348 KB Output is correct
30 Correct 62 ms 348 KB Output is correct
31 Correct 118 ms 352 KB Output is correct
32 Correct 320 ms 452 KB Output is correct
33 Correct 44 ms 12884 KB Output is correct
34 Correct 93 ms 21704 KB Output is correct
35 Correct 64 ms 12936 KB Output is correct
36 Correct 91 ms 16724 KB Output is correct
37 Execution timed out 1572 ms 12116 KB Time limit exceeded
38 Halted 0 ms 0 KB -