Submission #384714

# Submission time Handle Problem Language Result Execution time Memory
384714 2021-04-02T06:01:18 Z AdiZer0 Preokret (COCI18_preokret) C++17
50 / 50
1 ms 364 KB
#include <bits/stdc++.h>

#define pb push_back
#define whole(x) x.begin(), x.end()
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = (int)1e5 + 7;
const int INF = (int)1e9 + 7;
const ll linf = (ll)1e18 + 1;
 
int n, a[N];
int m, b[N];

int main() {
    scanf ("%d", &n);
    for (int i = 1; i <= n; ++i) scanf ("%d", a + i);
    scanf ("%d", &m);
    for (int i = 1; i <= m; ++i) scanf ("%d", b + i);
    int who = -1, p1 = 1;
    int half = 0, turn = 0;
    int numA = 0, numB = 0;
    b[m + 1] = INF;
    for (int i = 1; i <= n;) {
        if (a[i] < b[p1])  {
            if (a[i] <= 1440) ++half;
            numA++;
            ++i;
        } else { 
            if (b[p1] <= 1440) ++half;
            numB++;
            ++p1;
        }
        if (who == -1) {
            if (numA > numB) who = 0;
            else who = 1;
        } else { 
            if (who)  {
                if (numA > numB) who = 0, ++turn;
            } else {
                if (numA < numB) who = 1, ++turn;
            }
        }
    }
    while (p1 <= m) { 
        ++numB;
        if (b[p1] <= 1440) ++half;
        if (who == -1) {
            if (numA > numB) who = 0;
            else who = 1;
        } else { 
            if (who)  {
                if (numA > numB) who = 0, ++turn;
            } else { 
                if (numA < numB) who = 1, ++turn;
            }
        }
        ++p1;
    }
    printf ("%d\n%d\n", half, turn);
    return 0;
}

/*
6
15 30 35 55 60 2065
7
20 25 40 45 50 2070 2075
*/

Compilation message

preokret.cpp: In function 'int main()':
preokret.cpp:20:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |     scanf ("%d", &n);
      |     ~~~~~~^~~~~~~~~~
preokret.cpp:21:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |     for (int i = 1; i <= n; ++i) scanf ("%d", a + i);
      |                                  ~~~~~~^~~~~~~~~~~~~
preokret.cpp:22:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |     scanf ("%d", &m);
      |     ~~~~~~^~~~~~~~~~
preokret.cpp:23:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |     for (int i = 1; i <= m; ++i) scanf ("%d", b + i);
      |                                  ~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct