cppAcademy
FROM LEARNING TO COMPETING

Beginner.
Your first challenges.

Bulgarian Informatics Group E · 2007–2026

270 independently explained problems: 54 Municipal, 54 Regional, 105 National Olympiad tasks and 57 Autumn Tournament tasks. Start with the easier tasks and work upwards. Difficulty labels are learning estimates, not official ratings; Group E also includes challenging national-level problems. Years follow Arena’s competition-season labels. Source clarifications are noted on affected tasks.
GROUP E2016 · MediumArrays & scoring

Paired Test Scores

National Olympiad — National round (2016 season)

Submission name: pair.cpp

Problem summary

T equally weighted tests are partitioned into pairs. A student receives both tests’ points only if both tests in the pair are correct; otherwise that pair earns zero. The total possible score is 100. Compute each student’s score.

Source clarification. The output prose says the N integers are on one line, while its worked output lists one integer per line. This solution follows the worked output; both layouts have the same whitespace-separated score tokens.

Input

Even T, then T/2 test-number pairs; N; then N binary strings of length T showing each student’s correct and incorrect tests.

Output

The N scores in input order. The official example prints one score per line.

Constraints

T is an even divisor of 100; 1 ≤ N ≤ 200; the pairs partition tests 1…T.

Worked example

An independently prepared example for this explanation.

Input

4
1 3
2 4
6
1100
1010
1111
1011
0101
0001

Output

0
50
100
50
50
0

Solution analysis

  1. Each individual test is worth 100 / T points. Therefore each successful pair contributes 200 / T points, and unsuccessful pairs contribute zero.
  2. Store the input pairs with indices reduced by one. For every binary result string, check both positions of each pair and add the pair value only when both characters are 1.
  3. In the example each successful pair is worth 50 points. String 1100 fails both pairs (1,3) and (2,4), scoring zero. String 1010 passes only pair (1,3), scoring 50; 1111 passes both for 100.

Why it works

The pair list partitions all tests. For each pair the algorithm awards exactly the full two-test value if and only if both tests are correct, as required. Summing these disjoint contributions therefore yields the student’s score, and processing students in input order preserves the output order.

Complexity: O(NT) time and O(T) space.

Watch out. Test numbers in the input are one-based. A single correct test within a pair earns nothing. Read the results as strings, not integer values.

Commented C++17 solution

An independently written complete program with standard headers.

#include <iostream>
#include <vector>
#include <utility>
#include <string>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    vector<pair<int, int>> pairs(t / 2);
    for (auto &tests : pairs) {
        cin >> tests.first >> tests.second;
        --tests.first;
        --tests.second;
    }
    int n;
    cin >> n;
    for (int student = 0; student < n; ++student) {
        string result;
        cin >> result;
        int score = 0;
        for (const auto &tests : pairs) {
            // A pair earns its full two-test value only when both tests pass.
            if (result[tests.first] == '1' && result[tests.second] == '1') {
                score += 200 / t;
            }
        }
        cout << score << '\n';
    }
    return 0;
}

Source: Arena Olimpiici ↗