QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#73672#3530. Small businesssinbad#WA 2ms3444kbC++5.1kb2023-01-27 15:46:452023-01-27 15:46:47

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-27 15:46:47]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 3444kb
  • [2023-01-27 15:46:45]
  • Submitted

answer

// #define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const multiset<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

template <class T> auto vect(const T& v, int n) { return vector<T>(n, v); }
template <class T, class... D> auto vect(const T& v, int n, D... m) {
  return vector<decltype(vect(v, m...))>(n, vect(v, m...));
}

using int64 = long long;
using int128 = __int128_t;
using ii = pair<int64, int64>;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
mt19937_64 mrand(random_device{}());
int64 rnd(int64 x) { return mrand() % x; }
constexpr inline int lg2(int64 x) { return x == 0 ? -1 : sizeof(int64) * 8 - 1 - __builtin_clzll(x); }
constexpr inline int p2ceil(int64 x) { return 1 << (lg2(x - 1) + 1); }
template <class T> void out(const vector<T>& a) { for (int i = 0; i < SZ(a); ++i) cout << a[i] << " \n"[i + 1 == SZ(a)]; }
template <class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template <class T> void dedup(vector<T>& v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); }
inline void add_mod(int& x, int y) { x += y; if (x >= MOD) x -= MOD; }
inline void sub_mod(int& x, int y) { x += MOD - y; if (x >= MOD) x -= MOD; }
inline int mod(int x) { return x >= MOD ? x - MOD : x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  string s;
  cin >> s;
  vector<int> cnt(10);
  for (auto& c : s) cnt[c - '0']++;

  int n = SZ(s);
  trace(n);
  ii ret = {inf<int64>, inf<int64>};
  auto get =
    [&](int k) -> int64 {
      trace(k);
      int128 ret = 0;
      if (k == 1) {
        for (int x = 0; x < 10; ++x) {
          if (cnt[x] > 0) {
            --cnt[x];
            return x;
          }
        }
      }
      for (int x = 1; x < 10; ++x) {
        if (cnt[x] > 0) {
          ret = x;
          cnt[x]--;
          break;
        }
      }
      if (ret == 0) return -1;
      for (int i = 1; i < k; ++i) {
        for (int x = 0; x < 10; ++x) {
          if (cnt[x] > 0) {
            ret = ret * 10 + x;
            --cnt[x];
            break;
          }
        }
      }
      if (ret > 1000000000LL * 1000000000LL) ret = -1;
      return ret;
    };
  for (int k = 1; k <= 19; ++k) {
    if (n - k > 19 || n - k < 1) continue;
    if (k > n - k) continue;
    auto old_cnt = cnt;
    int64 x = get(k);
    int64 y = get(n - k);
    if (x >= 0 && y >= 0) {
      ckmin(ret, ii{x, y});
    }
    cnt = old_cnt;
  }
  if (ret.first == inf<int64>) ret = {-1, -1};
  trace(ret.first / 1e18, ret.second / 1e18);
  cout << ret.first << " " << ret.second << '\n';
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3348kb

input:

123456

output:

1 23456

result:

ok ok

Test #2:

score: 0
Accepted
time: 0ms
memory: 3332kb

input:

42

output:

2 4

result:

ok ok

Test #3:

score: 0
Accepted
time: 2ms
memory: 3336kb

input:

000

output:

-1 -1

result:

ok ok

Test #4:

score: 0
Accepted
time: 0ms
memory: 3436kb

input:

4418409405

output:

0 104444589

result:

ok ok

Test #5:

score: 0
Accepted
time: 2ms
memory: 3340kb

input:

82933602294918208962

output:

10 202222334668889999

result:

ok ok

Test #6:

score: 0
Accepted
time: 0ms
memory: 3324kb

input:

264727800857314294187884421131

output:

100111122223 344444567777888889

result:

ok ok

Test #7:

score: 0
Accepted
time: 1ms
memory: 3332kb

input:

5879012924529447774473489599650098351318

output:

-1 -1

result:

ok ok

Test #8:

score: 0
Accepted
time: 2ms
memory: 3440kb

input:

61899560303187317666207432000671179900997026617305

output:

-1 -1

result:

ok ok

Test #9:

score: 0
Accepted
time: 0ms
memory: 3324kb

input:

0

output:

-1 -1

result:

ok ok

Test #10:

score: 0
Accepted
time: 0ms
memory: 3320kb

input:

0000000000000000010

output:

0 100000000000000000

result:

ok ok

Test #11:

score: 0
Accepted
time: 0ms
memory: 3444kb

input:

72

output:

2 7

result:

ok ok

Test #12:

score: 0
Accepted
time: 2ms
memory: 3316kb

input:

9407809440087866606

output:

0 400004466667788899

result:

ok ok

Test #13:

score: 0
Accepted
time: 1ms
memory: 3436kb

input:

89809008899888899001

output:

10 800008888888999999

result:

ok ok

Test #14:

score: 0
Accepted
time: 2ms
memory: 3444kb

input:

5977998750

output:

0 557778999

result:

ok ok

Test #15:

score: 0
Accepted
time: 2ms
memory: 3344kb

input:

079968486310868706

output:

0 10034666677888899

result:

ok ok

Test #16:

score: 0
Accepted
time: 2ms
memory: 3340kb

input:

8863679763487438575

output:

3 334455666777788889

result:

ok ok

Test #17:

score: 0
Accepted
time: 2ms
memory: 3332kb

input:

89989959979978899897

output:

57 778888899999999999

result:

ok ok

Test #18:

score: 0
Accepted
time: 1ms
memory: 3388kb

input:

04

output:

0 4

result:

ok ok

Test #19:

score: 0
Accepted
time: 2ms
memory: 3352kb

input:

050

output:

0 50

result:

ok ok

Test #20:

score: 0
Accepted
time: 2ms
memory: 3416kb

input:

00600

output:

0 6000

result:

ok ok

Test #21:

score: -100
Wrong Answer
time: 0ms
memory: 3336kb

input:

00000004000000000001

output:

10 400000000000000000

result:

wrong answer jury has the better answer