Submission #529798

# Submission time Handle Problem Language Result Execution time Memory
529798 2022-02-23T17:21:02 Z c28dnv9q3 Mixture (BOI20_mixture) C++17
0 / 100
0 ms 268 KB
#include <stdio.h>
#include <limits.h>

int sign(int x) { return (x < 0) ? -1 : (x > 0) ? 1 : 0; }

struct mixture {
    int a, b, c;
    int s;

    mixture() {}
    mixture(int a, int b, int c) : a(a), b(b), c(c), s(a+b+c) {}
} mixtures[100005];
bool mixtureValid[100005];

int line_side(const mixture& a, const mixture& b, const mixture& x) {
    return sign(
        (a.b*b.s - a.s*b.b) * (a.a*x.s - a.s*x.a) -
        (a.a*b.s - a.s*b.a) * (a.b*x.s - a.s*x.b)
    );
}

bool can_combine(const mixture& a, const mixture& x) {
    return
        a.a*x.s == a.s*x.a &&
        a.b*x.s == a.s*x.b &&
        a.c*x.s == a.s*x.c
    ;
}

bool can_combine(const mixture& a, const mixture& b, const mixture& x) {
    return line_side(a, b, x) == 0;
}

bool can_combine(const mixture& a, const mixture& b, const mixture& c, const mixture& x) {
    return
        line_side(a, b, x) == line_side(a, b, c) &&
        line_side(a, c, x) == line_side(a, c, b) &&
        line_side(b, c, x) == line_side(b, c, a)
    ;
}

int main() {
    int xA, xB, xC;
    scanf("%d %d %d", &xA, &xB, &xC);
    mixture x(xA, xB, xC);

    int N;
    scanf("%d", &N);
    for(int i = 0; i < N; i++) {
        char chr;
        for(chr = getchar(); chr != 'A' && chr != 'R'; chr = getchar());

        if(chr == 'A') {
            int a, b, c;
            scanf("%d %d %d", &a, &b, &c);
            mixtures[i] = mixture(a, b, c);
            mixtureValid[i] = true;
        } else {
            int r;
            scanf("%d", &r);
            mixtureValid[r-1] = false;
        }

        int best = INT_MAX;
        for(int a = 0; a <= i; a++) {
            if(!mixtureValid[a]) continue;
            if(best > 1 && can_combine(mixtures[a], x)) best = 1;
            for(int b = a+1; b <= i; b++) {
                if(!mixtureValid[b]) continue;
                if(best > 2 && can_combine(mixtures[a], mixtures[b], x)) best = 2;
                for(int c = b+1; c <= i; c++) {
                    if(!mixtureValid[c]) continue;
                    if(best > 3 && can_combine(mixtures[a], mixtures[b], mixtures[c], x)) best = 3;
                }
            }
        }
        if(best == INT_MAX) best = 0;
        printf("%d\n", best);
    }

    return 0;
}

Compilation message

Mixture.cpp: In function 'int main()':
Mixture.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     scanf("%d %d %d", &xA, &xB, &xC);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Mixture.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
Mixture.cpp:55:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |             scanf("%d %d %d", &a, &b, &c);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Mixture.cpp:60:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |             scanf("%d", &r);
      |             ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 268 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 268 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 268 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 268 KB Output isn't correct
3 Halted 0 ms 0 KB -