Submission #525760

# Submission time Handle Problem Language Result Execution time Memory
525760 2022-02-12T19:42:55 Z Leo121 Archery (IOI09_archery) C++14
57 / 100
2000 ms 65540 KB
#include <bits/stdc++.h>
#include <iostream>
#include <limits.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#define pb push_back
#define bg(v) v.begin()
#define all(v) bg(v), v.end()
#define mp make_pair
#define fi first
#define se second
#define forn(i, a, b) for(int i=int(a);i<=int(b);++i)
#define fora(i, a, b) for(int i=int(a);i>=int(b);--i)
#define lb lower_bound
#define ub upper_bound
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
const int mod = 1e9 + 7;
const int movi[4] = {1, -1, 0, 0};
const int movj[4] = {0, 0, -1, 1};
const int lim = 1e5;
struct ura{
    bool primero, segundo, numero1, actual;
};
int n, r, res, minimo;
int posiciones[2 * lim + 2];
bool ocupados[lim + 2];
vector<ura> casillas;
int menor(int pos){
    forn(i, 1, n){
        ocupados[i] = 0;
    }
    int llevados = 0;
    fora(i, n, 2){
        if(!casillas[i - 1].actual && !casillas[i - 1].primero){
            llevados ++;
        }
        if(!casillas[i - 1].segundo){
            llevados ++;
        }
        if(llevados){
            ocupados[i] = 1;
            llevados --;
        }
    }
    if(!casillas[0].actual && !casillas[0].primero){
        llevados ++;
    }
    if(!casillas[0].segundo){
        llevados ++;
    }
    fora(i, n, 2){
        if(!llevados){
            break;
        }
        if(!ocupados[i]){
            ocupados[i] = 1;
            llevados --;
        }
    }
    fora(i, pos, 2){
        if(!ocupados[i]){
            return i;
        }
    }
    fora(i, n, pos + 1){
        if(!ocupados[i]){
            return i;
        }
    }
}
int mayor(int pos){
    bool numero1 = 0, actual = 0;
    int unos = 1;
    bool primero, segundo;
    forn(i, 1, 2 * n){
        if(i == 1){
            primero = casillas[i - 1].primero;
            segundo = casillas[i - 1].segundo;
            if(primero == 1){
                unos ++;
            }
            if(segundo == 1){
                unos ++;
            }
            numero1 = casillas[i - 1].numero1;
            actual = casillas[i - 1].actual;
        } else{
            if(casillas[i - 1].primero){
                unos ++;
            }
            if(casillas[i - 1].segundo){
                unos ++;
            }
            if(casillas[i - 1].actual){
                actual = 1;
            }
            if(casillas[i - 1].numero1){
                numero1 = 1;
            }
        }
        if(unos > 1){
            casillas.pb({1, 0, 0, 0});
            unos --;
        }
        else if(unos == 1){
            if(actual){
                casillas.pb({0, 0, 0, 1});
                actual = 0;
                if(i >= n){
                    return (n - ((r - i) % n));
                }
            }
            else{
                casillas.pb({0, 0, 0, 0});
            }
        } else{
            casillas.pb({0, 0, 0, 0});
        }
    }
}
void ronda(int pos){
    casillas.clear();
    forn(i, 1, pos - 1){
        casillas.pb({(posiciones[i * 2] < posiciones[1]) ? 1 : 0, (posiciones[i * 2 + 1] < posiciones[1]) ? 1 : 0, (posiciones[i * 2] == 1 || posiciones[i * 2 + 1] == 1) ? 1 : 0, 0});
    }
    casillas.pb({0, (posiciones[pos * 2] < posiciones[1]) ? 1 : 0, (posiciones[pos * 2] == 1) ? 1 : 0, 1});
    forn(i, pos + 1, n){
        casillas.pb({(posiciones[i * 2 - 1] < posiciones[1]) ? 1 : 0, (posiciones[i * 2] < posiciones[1]) ? 1 : 0, (posiciones[i * 2 - 1] == 1 || posiciones[i * 2] == 1) ? 1 : 0, 0});
    }
    int aux;
    if(posiciones[1] >= n + 2){
        aux = menor(pos);
    }
    else{
        aux = mayor(pos);
    }
    if(aux <= minimo){
        minimo = aux;
        res = pos;
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> r;
    minimo = n;
    forn(i, 1, 2 * n){
        cin >> posiciones[i];
    }
    if(posiciones[1] == 1){
        cout << n;
        return 0;
    }
    forn(i, 1, n){
        ronda(i);
    }
    cout << res;
    return 0;
}

Compilation message

archery.cpp: In function 'int mayor(int)':
archery.cpp:89:10: warning: variable 'numero1' set but not used [-Wunused-but-set-variable]
   89 |     bool numero1 = 0, actual = 0;
      |          ^~~~~~~
archery.cpp: In function 'void ronda(int)':
archery.cpp:141:58: warning: narrowing conversion of '((posiciones[(i * 2)] < posiciones[1]) ? 1 : 0)' from 'int' to 'bool' [-Wnarrowing]
  141 |         casillas.pb({(posiciones[i * 2] < posiciones[1]) ? 1 : 0, (posiciones[i * 2 + 1] < posiciones[1]) ? 1 : 0, (posiciones[i * 2] == 1 || posiciones[i * 2 + 1] == 1) ? 1 : 0, 0});
      |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
archery.cpp:141:107: warning: narrowing conversion of '((posiciones[((i * 2) + 1)] < posiciones[1]) ? 1 : 0)' from 'int' to 'bool' [-Wnarrowing]
  141 |         casillas.pb({(posiciones[i * 2] < posiciones[1]) ? 1 : 0, (posiciones[i * 2 + 1] < posiciones[1]) ? 1 : 0, (posiciones[i * 2] == 1 || posiciones[i * 2 + 1] == 1) ? 1 : 0, 0});
      |                                                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
archery.cpp:141:171: warning: narrowing conversion of '(((posiciones[(i * 2)] == 1) || (posiciones[((i * 2) + 1)] == 1)) ? 1 : 0)' from 'int' to 'bool' [-Wnarrowing]
  141 |         casillas.pb({(posiciones[i * 2] < posiciones[1]) ? 1 : 0, (posiciones[i * 2 + 1] < posiciones[1]) ? 1 : 0, (posiciones[i * 2] == 1 || posiciones[i * 2 + 1] == 1) ? 1 : 0, 0});
      |                                                                                                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
archery.cpp:143:59: warning: narrowing conversion of '((posiciones[(pos * 2)] < posiciones[1]) ? 1 : 0)' from 'int' to 'bool' [-Wnarrowing]
  143 |     casillas.pb({0, (posiciones[pos * 2] < posiciones[1]) ? 1 : 0, (posiciones[pos * 2] == 1) ? 1 : 0, 1});
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
archery.cpp:143:95: warning: narrowing conversion of '((posiciones[(pos * 2)] == 1) ? 1 : 0)' from 'int' to 'bool' [-Wnarrowing]
  143 |     casillas.pb({0, (posiciones[pos * 2] < posiciones[1]) ? 1 : 0, (posiciones[pos * 2] == 1) ? 1 : 0, 1});
      |                                                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
archery.cpp:145:62: warning: narrowing conversion of '((posiciones[((i * 2) - 1)] < posiciones[1]) ? 1 : 0)' from 'int' to 'bool' [-Wnarrowing]
  145 |         casillas.pb({(posiciones[i * 2 - 1] < posiciones[1]) ? 1 : 0, (posiciones[i * 2] < posiciones[1]) ? 1 : 0, (posiciones[i * 2 - 1] == 1 || posiciones[i * 2] == 1) ? 1 : 0, 0});
      |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
archery.cpp:145:107: warning: narrowing conversion of '((posiciones[(i * 2)] < posiciones[1]) ? 1 : 0)' from 'int' to 'bool' [-Wnarrowing]
  145 |         casillas.pb({(posiciones[i * 2 - 1] < posiciones[1]) ? 1 : 0, (posiciones[i * 2] < posiciones[1]) ? 1 : 0, (posiciones[i * 2 - 1] == 1 || posiciones[i * 2] == 1) ? 1 : 0, 0});
      |                                                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
archery.cpp:145:171: warning: narrowing conversion of '(((posiciones[((i * 2) - 1)] == 1) || (posiciones[(i * 2)] == 1)) ? 1 : 0)' from 'int' to 'bool' [-Wnarrowing]
  145 |         casillas.pb({(posiciones[i * 2 - 1] < posiciones[1]) ? 1 : 0, (posiciones[i * 2] < posiciones[1]) ? 1 : 0, (posiciones[i * 2 - 1] == 1 || posiciones[i * 2] == 1) ? 1 : 0, 0});
      |                                                                                                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
archery.cpp: In function 'int menor(int)':
archery.cpp:87:1: warning: control reaches end of non-void function [-Wreturn-type]
   87 | }
      | ^
archery.cpp: In function 'int mayor(int)':
archery.cpp:137:1: warning: control reaches end of non-void function [-Wreturn-type]
  137 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Runtime error 67 ms 65540 KB Execution killed with signal 9
4 Correct 99 ms 408 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 38 ms 364 KB Output is correct
4 Execution timed out 2073 ms 976 KB Time limit exceeded
5 Execution timed out 2066 ms 3144 KB Time limit exceeded
6 Correct 2 ms 332 KB Output is correct
7 Incorrect 13 ms 368 KB Output isn't correct
8 Execution timed out 2091 ms 976 KB Time limit exceeded
9 Execution timed out 2037 ms 1104 KB Time limit exceeded
10 Incorrect 17 ms 332 KB Output isn't correct
11 Execution timed out 2086 ms 1100 KB Time limit exceeded
12 Correct 105 ms 332 KB Output is correct
13 Incorrect 690 ms 2772 KB Output isn't correct
14 Correct 373 ms 500 KB Output is correct
15 Execution timed out 2068 ms 1520 KB Time limit exceeded
16 Correct 1 ms 332 KB Output is correct
17 Correct 27 ms 380 KB Output is correct
18 Correct 56 ms 332 KB Output is correct
19 Correct 165 ms 460 KB Output is correct
20 Correct 313 ms 504 KB Output is correct
21 Execution timed out 2096 ms 1120 KB Time limit exceeded
22 Execution timed out 2052 ms 1456 KB Time limit exceeded
23 Runtime error 16 ms 3520 KB Execution killed with signal 11
24 Correct 1 ms 332 KB Output is correct
25 Correct 12 ms 332 KB Output is correct
26 Correct 312 ms 460 KB Output is correct
27 Execution timed out 2056 ms 844 KB Time limit exceeded
28 Runtime error 17 ms 3460 KB Execution killed with signal 11
29 Correct 24 ms 332 KB Output is correct
30 Correct 275 ms 464 KB Output is correct
31 Execution timed out 2086 ms 844 KB Time limit exceeded
32 Execution timed out 2028 ms 2888 KB Time limit exceeded
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 320 KB Output is correct
35 Correct 48 ms 332 KB Output is correct
36 Correct 68 ms 364 KB Output is correct
37 Execution timed out 2044 ms 828 KB Time limit exceeded
38 Execution timed out 2075 ms 972 KB Time limit exceeded
39 Correct 1 ms 324 KB Output is correct
40 Correct 11 ms 332 KB Output is correct
41 Correct 49 ms 332 KB Output is correct
42 Correct 62 ms 332 KB Output is correct
43 Correct 268 ms 460 KB Output is correct
44 Correct 1036 ms 612 KB Output is correct
45 Execution timed out 2083 ms 844 KB Time limit exceeded
46 Execution timed out 2054 ms 840 KB Time limit exceeded
47 Execution timed out 2058 ms 2888 KB Time limit exceeded