TopCoder

User's AC Ratio

84.6% (11/13)

Submission's AC Ratio

68.2% (15/22)

Tags

Description

本題限用 C++23 作答。

小明得到了兩個序列 $a, b$,他想知道兩序列的總和大小關係,而若是一樣時,他會自動當作 $a$ 的總和較小。

他有時候想知道誰比較大,有時候想知道誰比較小,因此希望能有個控制選項來決定要知道大還是小。

小明因此寫了一隻程式來達到這件事情,該程式在在控制選項為 < 時,會在 $a$ 的總和比 $b$ 的總和小時輸出 IOIC,否則輸出 2025;
當控制選項為 > 時,則會在 $b$ 的總和比 $a$ 的總和小時輸出 IOIC,否則輸出 2025。

然而他發現他的程式好像有時候怪怪的,請你在 edit distance 不超過 2 的情況下幫他修好他的程式。

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

#define o {
#define l 
#define a }
#define w

struct Num : public string {
#define OP(op) auto operator op(const Num &rhs) const
  l w w w w w w w w w OP(<) w w w w w w w w o
  l                                         l
  l  l w w if (size() != rhs.size()) w w o  l
  l  l                                   l  l
  l  l    return size() < rhs.size();    l  l
  l  l                                   l  l
  l  a w w w w w w w w w w w w w w w w w l  l
  l                                         l
  l        return compare(rhs) < 0;         l
  l                                         l
  a w w w w w w w w w w w w w w w w w w w w l

  l w w w w w w w w w w w w w w w w w w w w OP(+) w w w w w w w w w w w w w w w w w w w w w o
  l                                                                                         l
  l                                      Num result;                                        l
  l                                     int carry = 0;                                      l
  l                                                                                         l
  l    l for (auto [lc, rc] : views::zip(*this | views::reverse, rhs | views::reverse)) o   l
  l    l                                                                                l   l
  l    l                       carry += lc + rc - 2 * '0';                              l   l
  l    l             result.push_back(static_cast<char>(carry % 10 + '0'));             l   l
  l    l                              carry /= 10;                                      l   l
  l    l                                                                                l   l
  l    a w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w    l
  l                                                                                         l
  l   l w w w w w w w w w w for (const auto &v : {*this, rhs}) w w w w w w w w w w w w w o  l
  l   l                                                                                  l  l
  l   l   l for (auto c : v | views::reverse | views::drop(min(size(), rhs.size()))) o   l  l
  l   l   l                                                                          l   l  l
  l   l   l                            carry += c - '0';                             l   l  l
  l   l   l        result.push_back(static_cast<char>(carry % 10 + '0'));            l   l  l
  l   l   l                              carry /= 10;                                l   l  l
  l   l   l                                                                          l   l  l
  l   l   a w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w    l  l
  l   l                                                                                  l  l
  l   a w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w   l
  l                                                                                         l
  l                l w w w w w w w w w w if (carry) w w w w w w w w w w w o                 l
  l                l                                                      l                 l
  l                l  result.push_back(static_cast<char>(carry + '0'));   l                 l
  l                l                                                      l                 l
  l                a w w w w w w w w w w w w w w w w w w w w w w w w w w w                  l
  l                                                                                         l
  l                               ranges::reverse(result);                                  l
  l                                   return result;                                        l
  l                                                                                         l
  a w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w w l

  OP(+=) = delete;
};

l auto read_ints(int n) -> generator<Num> o
l                                         l
l    l for (int _ : views::iota(0, n)) o  l
l    l                                 l  l
l    l              Num s;             l  l
l    l            cin >> s;            l  l
l    l           co_yield s;           l  l
l    l                                 l  l
l    a w w w w w w w w w w w w w w w w l  l
l                                         l
a w w w w w w w w w w w w w w w w w w w w l

int main() {
  int n, m;
  cin >> n >> m;

  pair<Num, int> v1{"0", 1}, v2{"0", 2};
  for (auto s : read_ints(n)) {
    v1.first = v1.first + s;
  }

  string op;
  cin >> op;

  for (auto s : read_ints(m)) {
    v2.first = v2.first + s;
  }

  if (op == ">") {
    swap(v1, v2);
  }
  if (v1 < v2) {
    cout << "IOIC\n";
  } else {
    cout << "2025\n";
  }
}

Input Format

輸入第一行有兩個正整數 $n, m$,分別代表 $a$ 序列的長度與 $b$ 序列的長度。

接下來的一行有 $n$ 個數字,為 $a$ 序列。

再來的一行有一個符號 $o$,代表控制選項。

最後的一行有 $m$ 個數字,為 $b$ 序列。

  • $1 \leq n, m \leq 2025$
  • $1 \leq a_i, b_i < 10^ {2025}$
  • $o \in \lbrace \text{<}, \text{>}\rbrace$

Output Format

請依照題目規定輸出 IOIC 或是 2025

Sample Input 1

4 6
7 1 2 2
<
1 1 4 5 1 4

Sample Output 1

IOIC

Hints

Problem Source

Subtasks

No. Testdata Range Constraints Score
1 0 範例測資 0
2 0~18 無額外限制 200

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 262144 65536 1 2
1 1000 262144 65536 2
2 1000 262144 65536 2
3 1000 262144 65536 2
4 1000 262144 65536 2
5 1000 262144 65536 2
6 1000 262144 65536 2
7 1000 262144 65536 2
8 1000 262144 65536 2
9 1000 262144 65536 2
10 1000 262144 65536 2
11 1000 262144 65536 2
12 1000 262144 65536 2
13 1000 262144 65536 2
14 1000 262144 65536 2
15 1000 262144 65536 2
16 1000 262144 65536 2
17 1000 262144 65536 2
18 1000 262144 65536 2