Submission #1014618

# Submission time Handle Problem Language Result Execution time Memory
1014618 2024-07-05T08:10:48 Z MarwenElarbi Horses (IOI15_horses) C++17
34 / 100
19 ms 12320 KB
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
#define ll long long
#define pb push_back
#define se second
#define fi first
const int MOD=1e9+7;
pair<ll,ll> tab[1005];
int n;
int init(int N, int X[], int Y[]){
    n=N;
    for (int i = 0; i < N; ++i)
    {
        tab[i]={X[i],Y[i]};
    }
    ll cur=0;
    ll pos;
    for (int i = N-1; i >= 0; --i)
    {
        if(cur<Y[i]){
            pos=i;
            cur=Y[i];
        }
        if(cur<=1e9) cur*=1ll*X[i];
    }
    ll res=1;
    for (int i = 0; i < pos; ++i)
    {
        res*=1ll*X[i];
        res%=MOD;
    }
    res*=1ll*X[pos]*Y[pos]%MOD;
    res%=MOD;
    return res;
}

int updateX(int pos, int val){
    tab[pos].fi=val;
    ll cur=0;
    ll ps;
    for (int i = n-1; i >= 0; --i)
    {
        if(cur<tab[i].se){
            ps=i;
            cur=tab[i].se;
        }
        if(cur<=1e9) cur*=1ll*tab[i].fi;
    }
    ll res=1;
    for (int i = 0; i < ps; ++i)
    {
        res*=tab[i].fi;
        res%=MOD;
    }
    res*=1ll*tab[ps].fi*tab[ps].se%MOD;
    res%=MOD;
    return res;
}

int updateY(int pos, int val) {
    tab[pos].se=val;
    ll cur=0;
    ll ps;
    for (int i = n-1; i >= 0; --i)
    {
        if(cur<tab[i].se){
            ps=i;
            cur=tab[i].se;
        }
        if(cur<=1e9) cur*=tab[i].fi;
    }
    ll res=1;
    for (int i = 0; i < ps; ++i)
    {
        res*=tab[i].fi;
        res%=MOD;
    }
    res*=1ll*tab[ps].fi*tab[ps].se%MOD;
    res%=MOD;
    return res;
}

/*
int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    
    int N; cin>>N;

    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++) {
        cin>>X[i];
    }

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

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

    int M; cin>>M;

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

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

    return 0;
}*/

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:25:12: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   25 |         if(cur<=1e9) cur*=1ll*X[i];
      |            ^~~
horses.cpp:35:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   35 |     return res;
      |            ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:48:12: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   48 |         if(cur<=1e9) cur*=1ll*tab[i].fi;
      |            ^~~
horses.cpp:58:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   58 |     return res;
      |            ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:71:12: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
   71 |         if(cur<=1e9) cur*=tab[i].fi;
      |            ^~~
horses.cpp:81:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   81 |     return res;
      |            ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:18:8: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   18 |     ll pos;
      |        ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:41:8: warning: 'ps' may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |     ll ps;
      |        ^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:64:8: warning: 'ps' may be used uninitialized in this function [-Wmaybe-uninitialized]
   64 |     ll ps;
      |        ^~
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 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 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 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 408 KB Output is correct
# Verdict Execution time Memory 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 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 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 344 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 344 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 352 KB Output is correct
25 Correct 6 ms 348 KB Output is correct
26 Correct 6 ms 348 KB Output is correct
27 Correct 5 ms 480 KB Output is correct
28 Correct 6 ms 348 KB Output is correct
29 Correct 6 ms 348 KB Output is correct
30 Correct 6 ms 348 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 5 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 8540 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 344 KB Output is correct
6 Correct 0 ms 344 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 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
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 460 KB Output is correct
25 Correct 6 ms 348 KB Output is correct
26 Correct 6 ms 348 KB Output is correct
27 Correct 6 ms 472 KB Output is correct
28 Correct 6 ms 348 KB Output is correct
29 Correct 6 ms 472 KB Output is correct
30 Correct 6 ms 460 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 5 ms 480 KB Output is correct
33 Runtime error 19 ms 12320 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 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 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 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 6 ms 472 KB Output is correct
24 Correct 6 ms 344 KB Output is correct
25 Correct 6 ms 348 KB Output is correct
26 Correct 6 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 6 ms 348 KB Output is correct
30 Correct 6 ms 476 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 5 ms 348 KB Output is correct
33 Runtime error 12 ms 10580 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -