/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 324.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

int main() {
    string s;
    getline(cin, s); // Read the full first line
    int a, b, last;

    // Remove all whitespace just in case
    s.erase(remove(s.begin(), s.end(), ' '), s.end());

    // Check if input contains "..."
    bool has_ellipsis = s.find("...") != string::npos;

    vector<int> terms;
    string temp = "";
    for (char ch : s) {
        if (isdigit(ch)) {
            temp += ch;
        } else if (ch == '+' || ch == '.') {
            if (!temp.empty()) {
                terms.push_back(stoi(temp));
                temp = "";
            }
        }
    }
    if (!temp.empty()) terms.push_back(stoi(temp)); // last number if no ellipsis

    if (terms.size() < 2) {
        cerr << "Invalid input format\n";
        return 1;
    }

    a = terms[0];
    b = terms[1];

    if (has_ellipsis) {
        cin >> last;
    } else {
        if (terms.size() < 3) {
            cerr << "Missing last term\n";
            return 1;
        }
        last = terms[2];
    }

    int d = b - a;
    int n = (last - a) / d + 1;
    int sum = (2 * a + (n - 1) * d) * n / 2;

    cout << sum << "\n";
    return 0;
}

Information

Submit By
Type
Pretest
Problem
P1231 Busy Friend
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-02 16:53:15
Judged At
2025-09-02 16:53:15
Judged By
Score
0
Total Time
1ms
Peak Memory
324.0 KiB