QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#646724#7695. Double Upenze114514WA 1ms3580kbC++202.0kb2024-10-17 04:31:142024-10-17 04:31:15

Judging History

你现在查看的是最新测评结果

  • [2024-10-17 04:31:15]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3580kb
  • [2024-10-17 04:31:14]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

#define pb push_back

const ld pi = 3.14159265358979323846;
const ll INF = 1e18;

template<typename T>
T chmax(T a, T b) {
    return a > b ? a : b;
}

template<typename T>
T chmin(T a, T b) {
    return a > b ? b : a;
}

string mul(const string& a, const string& b) {
    if (a == "0" || b == "0") return "0";
    
    int La = a.size(), Lb = b.size();
    vector<int> res(La + Lb, 0);

    for (int i = La - 1; i >= 0; --i) {
        for (int j = Lb - 1; j >= 0; --j) {
            int mul = (a[i] - '0') * (b[j] - '0');
            int sum = mul + res[i + j + 1];

            res[i + j + 1] = sum % 10;
            res[i + j] += sum / 10;
        }
    }

    string result;
    for (int num : res) {
        if (!(result.empty() && num == 0)) {
            result += to_string(num);
        }
    }

    return result.empty() ? "0" : result;
}

bool cmp(const string& a, const string& b) {
    if (a.size() != b.size()) return a.size() < b.size();
    return a < b;
}

void solve() {
    int n;
    cin >> n;

    vector<string> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    sort(a.begin(), a.end(), cmp);

    while (a.size() > 1) {
        vector<string> b;
        for (int i = 1; i < a.size(); i++) {
            if (a[i] == a[i - 1]) {
                b.pb(mul(a[i], a[i - 1]));
                ++i;
            } else {
                b.pb(a[i - 1]);
            }
        }
        if (a.size() > 1 && a.back() != a[a.size() - 2]) {
            b.pb(a.back());
        }

        if (b.size() == a.size()) break;
        a = move(b);
        sort(a.begin(), a.end(), cmp);
    }

    cout << a.back() << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3576kb

input:

5
4 2 2 1 8

output:

16

result:

ok single line: '16'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3580kb

input:

1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1

result:

wrong answer 1st lines differ - expected: '512', found: '1'