Submission #355959

#TimeUsernameProblemLanguageResultExecution timeMemory
355959sean617Robots (IOI13_robots)C++98
Compilation error
0 ms0 KiB
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 1000005
using namespace std;

int n, m, T, l, r, md, cnta, cntb, nm, ans, a[50005], b[50005];
struct str {
    int c1, c2, mn, mx;
} c[N];

bool comp(str p, str q) {
    if (p.mx != q.mx) return p.mx < q.mx;
    return p.mn < q.mn;
}

int main()
{
    int i, j, k, t1, t2, w, sz;
    bool z;
    cin >> n >> m >> T;
    for (i = 0; i < n; i++) {
        scanf ("%d", &a[i]);
    }
    for (i = 0; i < m; i++) {
        scanf ("%d", &b[i]);
    }
    nm = max(n, m);
    sort(a, a + n);
    sort(b, b + m);
    for (i = 0; i < T; i++) {
        scanf ("%d %d", &w, &sz);
        t1 = upper_bound(a, a + n, w) - a;
        t2 = upper_bound(b, b + m, sz) - b;
        c[i].c1 = n - t1;
        c[i].c2 = m - t2;
        c[i].mn = min(c[i].c1, c[i].c2);
        c[i].mx = max(c[i].c1, c[i].c2);
        if (c[i].mx == 0) {
            cout << -1;
            return 0;
        }
    }
    sort(c, c + T, comp);
//    for (i = 0; i < T; i++) {
//        printf("%d %d\n", c[i].c1, c[i].c2);
//    }
    l = 1;
    r = T + 1;
    while (l < r){
        md = (l + r) / 2;
        j = 0;
        i = 0;
        cnta = cntb = 0;
        z = 1;
        for (k = 1; k <= nm; k++) {
            cnta += md;
            cntb += md;
            for (; i < T; i++) {
                if (c[i].mx > k) break;
            }
            for (; j < i; j++) {
                if (c[j].mx < k) {z = 0; break;}
                if (cnta > 0 && n >= k) cnta--;
                else if (cntb > 0 && m >= k) cntb--;
                else {z = 0; break;}
            }
            if (!z) break;
        }
        if (z) {r = md; ans = md;}
        else l = md+1;
    }
    cout << ans;
    return 0;
}

Compilation message (stderr)

robots.cpp: In function 'int main()':
robots.cpp:23:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |         scanf ("%d", &a[i]);
      |         ~~~~~~^~~~~~~~~~~~~
robots.cpp:26:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |         scanf ("%d", &b[i]);
      |         ~~~~~~^~~~~~~~~~~~~
robots.cpp:32:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |         scanf ("%d %d", &w, &sz);
      |         ~~~~~~^~~~~~~~~~~~~~~~~~
/tmp/ccoCfpg5.o: In function `main':
robots.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccH2PFog.o:grader.c:(.text.startup+0x0): first defined here
/tmp/ccH2PFog.o: In function `main':
grader.c:(.text.startup+0x1b1): undefined reference to `putaway'
collect2: error: ld returned 1 exit status