QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#120200#6353. Kth Lex Min Min Min Subpalindromeshos_lyricAC ✓89ms18856kbC++143.8kb2023-07-06 14:55:432023-07-06 14:56:00

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-06 14:56:00]
  • 评测
  • 测评结果:AC
  • 用时:89ms
  • 内存:18856kb
  • [2023-07-06 14:55:43]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }


vector<string> PRE[16];
void experiment() {
  for (int n = 1; n < 16; ++n) {
    int mn = n * n + 1;
    vector<string> ss;
    for (int p = 0; p < 1 << n; ++p) {
      string s(n, '?');
      for (int i = 0; i < n; ++i) s[n - 1 - i] = "01"[p >> i & 1];
      auto isPalin = [&](int i, int j) -> bool {
        --j;
        for (; i < j; ++i, --j) {
          if (s[i] != s[j]) return false;
        }
        return true;
      };
      int cnt = 0;
      for (int i = 0; i < n; ++i) for (int j = i + 1; j <= n; ++j) {
        if (isPalin(i, j)) {
          ++cnt;
        }
      }
      if (chmin(mn, cnt)) ss.clear();
      if (mn == cnt) ss.push_back(s);
    }
    // cerr << n << ": " << mn << " " << ss.size() << endl;
    for (const auto &s : ss) {
      PRE[n].push_back(s);
      // cout << s << endl;
    }
  }
}
/*
15: 28 12
001011001011001
001101001101001
010011010011010
010110010110010
011001011001011
011010011010011
100101100101100
100110100110100
101001101001101
101100101100101
110010110010110
110100110100110
*/

vector<Int> solve(int N, Int M, Int K) {
  if (M == 1) {
    if (K > 1) {
      return {};
    }
    return vector<Int>(N, 0);
  } else if (M == 2) {
    const int len = min(N, 6);
    if (K > (int)PRE[len].size()) {
      return {};
    }
    vector<Int> ans(N, -1);
    for (int i = 0; i < N; ++i) {
      ans[i] = PRE[len][K - 1][i % 6] - '0';
    }
    return ans;
  } else {
    vector<Int> prod(N + 1);
    prod[N] = 1;
    for (int i = N; --i >= 0; ) {
      const __int128 b = ((i == 0) ? M : (i == 1) ? (M - 1) : (M - 2));
      prod[i] = min<__int128>(b * prod[i + 1], K + 1);
    }
    if (K > prod[0]) {
      return {};
    }
    vector<Int> ans(N, -1);
    Int k = K;
    for (int i = 0; i < N; ++i) {
      const Int q = (k - 1) / prod[i + 1];
      k -= prod[i + 1] * q;
      ans[i] = q;
      if (i == 0) {
        //
      } else if (i == 1) {
        if (ans[i - 1] <= ans[i]) ++ans[i];
      } else {
        const Int a = min(ans[i - 2], ans[i - 1]);
        const Int b = max(ans[i - 2], ans[i - 1]);
        if (a <= ans[i]) ++ans[i];
        if (b <= ans[i]) ++ans[i];
      }
    }
    return ans;
  }
}

int main() {
  // needed
  experiment();
  
  int N;
  Int M, K;
  for (; ~scanf("%d%lld%lld", &N, &M, &K); ) {
    const auto ans = solve(N, M, K);
    if (!ans.empty()) {
      for (int i = 0; i < N; ++i) {
        if (i) printf(" ");
        printf("%lld", ans[i] + 1);
      }
      puts("");
    } else {
      puts("-1");
    }
  }
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 29ms
memory: 3744kb

input:

1 1 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 28ms
memory: 3636kb

input:

2 2 2

output:

2 1

result:

ok 2 number(s): "2 1"

Test #3:

score: 0
Accepted
time: 29ms
memory: 3632kb

input:

3 3 3

output:

2 1 3

result:

ok 3 number(s): "2 1 3"

Test #4:

score: 0
Accepted
time: 29ms
memory: 3632kb

input:

9 9 8244353

output:

2 4 1 2 6 8 1 2 7

result:

ok 9 numbers

Test #5:

score: 0
Accepted
time: 29ms
memory: 3516kb

input:

10 7 998244353

output:

-1

result:

ok 1 number(s): "-1"

Test #6:

score: 0
Accepted
time: 29ms
memory: 3700kb

input:

3 1000 994253860

output:

998 244 353

result:

ok 3 number(s): "998 244 353"

Test #7:

score: 0
Accepted
time: 29ms
memory: 3704kb

input:

58 4 864691128455135232

output:

4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4

result:

ok 58 numbers

Test #8:

score: 0
Accepted
time: 29ms
memory: 3504kb

input:

58 4 864691128455135233

output:

-1

result:

ok 1 number(s): "-1"

Test #9:

score: 0
Accepted
time: 86ms
memory: 18844kb

input:

1000000 1000000 1000000000000000000

output:

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ...

result:

ok 1000000 numbers

Test #10:

score: 0
Accepted
time: 86ms
memory: 18856kb

input:

1000000 4 1000000000000000000

output:

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ...

result:

ok 1000000 numbers

Test #11:

score: 0
Accepted
time: 29ms
memory: 3580kb

input:

1 1 2

output:

-1

result:

ok 1 number(s): "-1"

Test #12:

score: 0
Accepted
time: 25ms
memory: 3668kb

input:

1 2 2

output:

2

result:

ok 1 number(s): "2"

Test #13:

score: 0
Accepted
time: 28ms
memory: 3648kb

input:

2 2 1

output:

1 2

result:

ok 2 number(s): "1 2"

Test #14:

score: 0
Accepted
time: 25ms
memory: 3692kb

input:

3 2 4

output:

2 1 1

result:

ok 3 number(s): "2 1 1"

Test #15:

score: 0
Accepted
time: 29ms
memory: 3452kb

input:

3 2 7

output:

-1

result:

ok 1 number(s): "-1"

Test #16:

score: 0
Accepted
time: 29ms
memory: 3748kb

input:

4 2 10

output:

2 2 1 2

result:

ok 4 number(s): "2 2 1 2"

Test #17:

score: 0
Accepted
time: 29ms
memory: 3640kb

input:

4 2 3

output:

1 2 1 1

result:

ok 4 number(s): "1 2 1 1"

Test #18:

score: 0
Accepted
time: 29ms
memory: 3640kb

input:

5 2 7

output:

2 1 1 2 1

result:

ok 5 number(s): "2 1 1 2 1"

Test #19:

score: 0
Accepted
time: 25ms
memory: 3580kb

input:

5 2 13

output:

-1

result:

ok 1 number(s): "-1"

Test #20:

score: 0
Accepted
time: 29ms
memory: 3748kb

input:

6 2 5

output:

1 2 2 1 1 2

result:

ok 6 numbers

Test #21:

score: 0
Accepted
time: 78ms
memory: 10796kb

input:

1000000 2 3

output:

1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 ...

result:

ok 1000000 numbers

Test #22:

score: 0
Accepted
time: 76ms
memory: 11136kb

input:

1000000 2 5

output:

1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 ...

result:

ok 1000000 numbers

Test #23:

score: 0
Accepted
time: 77ms
memory: 11004kb

input:

1000000 2 7

output:

2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 ...

result:

ok 1000000 numbers

Test #24:

score: 0
Accepted
time: 25ms
memory: 3456kb

input:

1000000 2 1000000000000000000

output:

-1

result:

ok 1 number(s): "-1"

Test #25:

score: 0
Accepted
time: 25ms
memory: 3644kb

input:

1 3 2

output:

2

result:

ok 1 number(s): "2"

Test #26:

score: 0
Accepted
time: 25ms
memory: 3644kb

input:

2 3 5

output:

3 1

result:

ok 2 number(s): "3 1"

Test #27:

score: 0
Accepted
time: 85ms
memory: 18712kb

input:

1000000 3 5

output:

3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 ...

result:

ok 1000000 numbers

Test #28:

score: 0
Accepted
time: 28ms
memory: 11140kb

input:

1000000 3 7

output:

-1

result:

ok 1 number(s): "-1"

Test #29:

score: 0
Accepted
time: 85ms
memory: 18844kb

input:

1000000 4 211106232532991

output:

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ...

result:

ok 1000000 numbers

Test #30:

score: 0
Accepted
time: 89ms
memory: 18844kb

input:

1000000 5 1000000000000000000

output:

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ...

result:

ok 1000000 numbers

Test #31:

score: 0
Accepted
time: 81ms
memory: 18800kb

input:

1000000 123123 1000000000000000000

output:

1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 ...

result:

ok 1000000 numbers

Test #32:

score: 0
Accepted
time: 29ms
memory: 3704kb

input:

6 1000000 1000000000000000000

output:

1 2 4 9 15 8

result:

ok 6 numbers

Test #33:

score: 0
Accepted
time: 29ms
memory: 3688kb

input:

4 1000000 1000000000000000000

output:

2 7 15 9

result:

ok 4 number(s): "2 7 15 9"

Test #34:

score: 0
Accepted
time: 29ms
memory: 3632kb

input:

3 1000000 999997000002000000

output:

1000000 999999 999998

result:

ok 3 number(s): "1000000 999999 999998"

Test #35:

score: 0
Accepted
time: 29ms
memory: 3480kb

input:

3 1000000 999997000002000001

output:

-1

result:

ok 1 number(s): "-1"