7 / 7
Aug 2018

Hello there! I am new to this forum and spoj, but I already was able to solve a couple of problems. Here is my code for the mentioned task. Would anybody help, please, to find a mistake?

#include <bits/stdc++.h>

    using namespace std;

int main() {
    int t, n, a, r, suma, sumr, sum;
    cin >> t;
    for (int p = 0; p < t; p++) {
        cin >> n;
        struct Stats {
            int time;
            string team;
            char pr;
            char st;
        } data[n];
        set<string> set;
        for (int i = 0; i < n; i++) {
            cin >> data[i].time >> data[i].team >> data[i].pr >> data[i].st;
        }
        for (char ch = 'A'; ch <= 'I'; ch++) {
            for (int i = 0; i < n; i++) {
                if (data[i].pr == ch) {
                    set.insert(data[i].team);
                }
            }
            suma = sumr = sum = 0;
            for (auto it = set.begin(); it != set.end(); ++it) {
                a = r = 0;
                for (int i = 0; i < n; i++) {
                    if (data[i].pr == ch) {
                        if (data[i].team == *it && data[i].st == 'R') r++;
                        else if (data[i].team == *it && data[i].st == 'A') {
                            a = 1;
                            sum += data[i].time;
                            break;
                        }
                    }
                }
                suma += a;
                sumr += r;
            }
            if (suma == 0) cout << ch << " " << suma << "\n";
            else {
                cout.precision(2);
                cout << ch << " " << suma << " " << fixed << (double)(suma + sumr) / suma << " " << (double) sum / suma << "\n";
            }
            set.clear();
        }
    }
    system("pause");
    return 0;
}

Try this:

23
10 aaaaa A R
80 aaaaa A R
100 aaaaa A A
100 bbbb A R
150 bbbb A A
200 aaaaa B A
210 aaaaa B A
300 aaaaa C R
350 aaaaa C R
360 aaaaa C R
370 aaaaa C R
380 aaaaa C A
400 bbbb B A
500 bbbb C A
1000 ccc A R
1010 aaaaa A A
1200 aaaaa D A
1400 ccc B A
1500 ccc C R
1520 ccc C A
1600 bbbb D A
1707 aaaaa E A
1801 ccc F A

Expected answer:

A 2 2.50 125.00
B 3 1.00 666.67
C 3 2.67 800.00
D 2 1.00 1400.00
E 1 1.00 1707.00
F 1 1.00 1801.00
G 0
H 0
I 0

Also, did you leave the system(“pause”) in when you submitted?

Thank you for your answer, simes. I get this for your test:

A 2 3.00 125.00
B 3 1.00 666.67
C 3 2.67 800.00
D 2 1.00 1400.00
E 1 1.00 1707.00
F 1 1.00 1801.00
G 0
H 0
I 0

But what’s wrong? Only for a case A I regard the following sequence:

10 aaaaa A R [v] r
80 aaaaa A R [v] r
100 aaaaa A A [v] a
100 bbbb A R [v] r
150 bbbb A A [v] a
1000 ccc A R [v] r
1010 aaaaa A A [NOT INCLUDED IN STATS]

So, I get 4 rejected and 2 accepted. The average is 6 / 2 = 3.00. Why do you propose 2.50?

P.S. And yes, I left system(“pause”) when submitted.

the average number of submissions done by teams that solved that problem

ccc didn’t solve the problem, and so shouldn’t be included in that average.

Thank you for this hint. I truly didn’t take that possibility into account. Try to fix the problem and write you back with a new solution if it still fails.

Thank you very much, simes. I fixed this tiny bug and was able to pass all the tests:)

They’re only tiny after you’ve found and fixed them. Until then, they’re showstoppers.

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 23 14d

Want to read more? Browse other topics in C and C++ or view latest topics.