Submission #1014617

# Submission time Handle Problem Language Result Execution time Memory
1014617 2024-07-05T08:09:10 Z MarwenElarbi Horses (IOI15_horses) C++17
17 / 100
16 ms 10588 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<int,int> 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*=X[i];
    }
    ll res=1;
    for (int i = 0; i < pos; ++i)
    {
        res*=X[i];
        res%=MOD;
    }
    res*=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*=tab[i].fi;
    }
    ll res=1;
    for (int i = 0; i < ps; ++i)
    {
        res*=tab[i].fi;
        res%=MOD;
    }
    res*=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*=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*=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*=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 0 ms 344 KB Output is correct
2 Correct 1 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 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 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 1 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 1 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 Incorrect 0 ms 348 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 10588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 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 1 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 344 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 Incorrect 0 ms 348 KB Output isn't correct
22 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 356 KB Output is correct
5 Correct 1 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 1 ms 344 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 1 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 Incorrect 0 ms 348 KB Output isn't correct
22 Halted 0 ms 0 KB -