QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#680489#8776. Not Another Constructive!ahsoltan#TL 942ms952636kbC++202.4kb2024-10-26 21:13:252024-10-26 21:13:25

Judging History

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

  • [2024-10-26 21:13:25]
  • 评测
  • 测评结果:TL
  • 用时:942ms
  • 内存:952636kb
  • [2024-10-26 21:13:25]
  • 提交

answer

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

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) int((x).size())
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

#ifdef LOCAL
auto operator<<(auto& o, auto x) -> decltype(x.first, o);
auto operator<<(auto& o, auto x) -> decltype(x.end(), o) {
  o << "{";
  for (int i = 0; auto y : x) o << ", " + !i++ * 2 << y;
  return o << "}";
}
auto operator<<(auto& o, auto x) -> decltype(x.first, o) {
  return o << "(" << x.first << ", " << x.second << ")";
}
void __print(auto... x) { ((cerr << x << " "), ...) << endl; }
#define debug(x...) __print("[" #x "]:", x)
#else
#define debug(...) 2137
#endif

int c3(int x) { return x * (x - 1) * (x - 2) / 6; }
int c2(int x) { return x * (x - 1) / 2; }

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n, kk;
  string s;
  cin >> n >> kk >> s;
  vector dp(n + 1, vector(1, vector(1, vector(1, '\1'))));
  rep(i, 0, n) {
    dp[i + 1] = vector(min(kk, c3(i + 1)) + 1, vector(c2(i + 1) + 1, vector(i + 1 + 1, '\0')));
    rep(j, 0, min(kk, c3(i)) + 1) rep(k, 0, c2(i) + 1) rep(l, 0, i + 1) {
      if (dp[i][j][k][l] == '\0') continue;
      if (s[i] == 'N' || s[i] == '?') {
        dp[i + 1][j][k][l + 1] = 'N';
      }
      if (s[i] == 'A' || s[i] == '?') {
        dp[i + 1][j][k + l][l] = 'A';
      }
      if (s[i] == 'C' || s[i] == '?') {
        if (j + k <= kk) dp[i + 1][j + k][k][l] = 'C';
      }
      if (s[i] != 'N' && s[i] != 'A' && s[i] != 'C') {
        dp[i + 1][j][k][l] = s[i];
      }
    }
  }
  if (kk >= sz(dp[n])) {
    cout << "-1\n";
    return 0;
  }
  int i = n, j = kk, k = -1, l = -1;
  rep(x, 0, sz(dp[i][j])) rep(y, 0, sz(dp[i][j][x])) {
    if (dp[i][j][x][y] != '\0') {
      k = x;
      l = y;
      break;
    }
  }
  if (k == -1) {
    cout << "-1\n";
    return 0;
  }
  string ans;
  while (i > 0) {
    ans.push_back(dp[i][j][k][l]);
    if (ans.back() == '?') ans.back() = 'X';
    int ni, nj, nk, nl;
    if (ans.back() == 'N') {
      ni = i - 1;
      nj = j;
      nk = k;
      nl = l - 1;
    } else if (ans.back() == 'A') {
      ni = i - 1;
      nj = j;
      nk = k - l;
      nl = l;
    } else if (ans.back() == 'C') {
      ni = i - 1;
      nj = j - k;
      nk = k;
      nl = l;
    } else {
      ni = i - 1;
      nj = j;
      nk = k;
      nl = l;
    }
    i = ni;
    j = nj;
    k = nk;
    l = nl;
  }
  reverse(all(ans));
  cout << ans << '\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3892kb

input:

22 2
N??A??????C???????????

output:

NNXANNNNNNCNAAAAAAAAAA

result:

ok correct

Test #2:

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

input:

18 0
COUNTINGSATELLITES

output:

COUNTINGSATELLITES

result:

ok correct

Test #3:

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

input:

2 1
??

output:

-1

result:

ok correct

Test #4:

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

input:

1 0
?

output:

X

result:

ok correct

Test #5:

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

input:

1 0
N

output:

N

result:

ok correct

Test #6:

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

input:

1 0
X

output:

X

result:

ok correct

Test #7:

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

input:

1 1
?

output:

-1

result:

ok correct

Test #8:

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

input:

1 1
N

output:

-1

result:

ok correct

Test #9:

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

input:

1 1
X

output:

-1

result:

ok correct

Test #10:

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

input:

2 0
??

output:

NA

result:

ok correct

Test #11:

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

input:

2 0
N?

output:

NA

result:

ok correct

Test #12:

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

input:

2 0
?C

output:

XC

result:

ok correct

Test #13:

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

input:

2 1
N?

output:

-1

result:

ok correct

Test #14:

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

input:

2 1
?C

output:

-1

result:

ok correct

Test #15:

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

input:

3 1
???

output:

NAC

result:

ok correct

Test #16:

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

input:

3 1
N??

output:

NAC

result:

ok correct

Test #17:

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

input:

3 1
?A?

output:

NAC

result:

ok correct

Test #18:

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

input:

3 1
??C

output:

NAC

result:

ok correct

Test #19:

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

input:

3 1
NA?

output:

NAC

result:

ok correct

Test #20:

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

input:

3 1
N?C

output:

NAC

result:

ok correct

Test #21:

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

input:

3 1
?AC

output:

NAC

result:

ok correct

Test #22:

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

input:

4 1
????

output:

NACA

result:

ok correct

Test #23:

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

input:

4 1
X???

output:

XNAC

result:

ok correct

Test #24:

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

input:

4 1
???Z

output:

NACZ

result:

ok correct

Test #25:

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

input:

4 1
?AA?

output:

-1

result:

ok correct

Test #26:

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

input:

4 1
N???

output:

NACA

result:

ok correct

Test #27:

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

input:

4 1
?N??

output:

XNAC

result:

ok correct

Test #28:

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

input:

4 1
??N?

output:

NANC

result:

ok correct

Test #29:

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

input:

4 1
???N

output:

NACN

result:

ok correct

Test #30:

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

input:

4 1
A???

output:

ANAC

result:

ok correct

Test #31:

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

input:

4 1
?A??

output:

NACA

result:

ok correct

Test #32:

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

input:

4 1
??A?

output:

NXAC

result:

ok correct

Test #33:

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

input:

4 1
???A

output:

NACA

result:

ok correct

Test #34:

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

input:

4 1
C???

output:

CNAC

result:

ok correct

Test #35:

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

input:

4 1
?C??

output:

NCAC

result:

ok correct

Test #36:

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

input:

4 1
??C?

output:

NACA

result:

ok correct

Test #37:

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

input:

4 1
???C

output:

NAXC

result:

ok correct

Test #38:

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

input:

5 4
?????

output:

NNAAC

result:

ok correct

Test #39:

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

input:

6 14
??????

output:

-1

result:

ok correct

Test #40:

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

input:

7 14
???????

output:

-1

result:

ok correct

Test #41:

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

input:

8 43
????????

output:

-1

result:

ok correct

Test #42:

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

input:

9 55
?????????

output:

-1

result:

ok correct

Test #43:

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

input:

10 112
??????????

output:

-1

result:

ok correct

Test #44:

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

input:

11 110
???????????

output:

-1

result:

ok correct

Test #45:

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

input:

12 4
????????????

output:

NNNNACNAAAAA

result:

ok correct

Test #46:

score: 0
Accepted
time: 3ms
memory: 6356kb

input:

13 193
?????????????

output:

-1

result:

ok correct

Test #47:

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

input:

14 91
??????????????

output:

NNNNANAAACACCC

result:

ok correct

Test #48:

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

input:

15 15
???????????????

output:

NNNNNNNANACAAAA

result:

ok correct

Test #49:

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

input:

16 261
????????????????

output:

-1

result:

ok correct

Test #50:

score: 0
Accepted
time: 7ms
memory: 18676kb

input:

17 514
?????????????????

output:

-1

result:

ok correct

Test #51:

score: 0
Accepted
time: 13ms
memory: 25888kb

input:

18 678
??????????????????

output:

-1

result:

ok correct

Test #52:

score: 0
Accepted
time: 4ms
memory: 6208kb

input:

19 40
???????????????????

output:

NNNNNNNNAAAAACAAAAA

result:

ok correct

Test #53:

score: 0
Accepted
time: 33ms
memory: 46980kb

input:

20 1019
????????????????????

output:

-1

result:

ok correct

Test #54:

score: 0
Accepted
time: 55ms
memory: 62368kb

input:

21 1218
?????????????????????

output:

-1

result:

ok correct

Test #55:

score: 0
Accepted
time: 60ms
memory: 80984kb

input:

22 1348
??????????????????????

output:

-1

result:

ok correct

Test #56:

score: 0
Accepted
time: 42ms
memory: 50124kb

input:

23 476
???????????????????????

output:

-1

result:

ok correct

Test #57:

score: 0
Accepted
time: 92ms
memory: 130352kb

input:

24 1445
????????????????????????

output:

-1

result:

ok correct

Test #58:

score: 0
Accepted
time: 122ms
memory: 153384kb

input:

25 1331
?????????????????????????

output:

-1

result:

ok correct

Test #59:

score: 0
Accepted
time: 83ms
memory: 77832kb

input:

26 459
??????????????????????????

output:

NNNNNNNNNAAAAAAAAAAAACACCC

result:

ok correct

Test #60:

score: 0
Accepted
time: 84ms
memory: 78580kb

input:

27 398
???????????????????????????

output:

NNNNNNNNNNAAANAAAAAAAAACCAC

result:

ok correct

Test #61:

score: 0
Accepted
time: 69ms
memory: 63636kb

input:

28 274
????????????????????????????

output:

NNNNNNNNNNNANAAAAAAAAAACACAA

result:

ok correct

Test #62:

score: 0
Accepted
time: 263ms
memory: 339528kb

input:

29 1624
?????????????????????????????

output:

-1

result:

ok correct

Test #63:

score: 0
Accepted
time: 412ms
memory: 469420kb

input:

30 2079
??????????????????????????????

output:

-1

result:

ok correct

Test #64:

score: 0
Accepted
time: 483ms
memory: 535252kb

input:

31 2067
???????????????????????????????

output:

-1

result:

ok correct

Test #65:

score: 0
Accepted
time: 359ms
memory: 404156kb

input:

32 1267
????????????????????????????????

output:

-1

result:

ok correct

Test #66:

score: 0
Accepted
time: 332ms
memory: 340976kb

input:

33 928
?????????????????????????????????

output:

NNNNNNNNNNNNNAANAAAAAAAAAAACCCACC

result:

ok correct

Test #67:

score: 0
Accepted
time: 137ms
memory: 129664kb

input:

34 298
??????????????????????????????????

output:

NNNNNNNNNNNNNNANAAAAAAAAACCAAAAAAA

result:

ok correct

Test #68:

score: 0
Accepted
time: 942ms
memory: 952636kb

input:

35 2361
???????????????????????????????????

output:

-1

result:

ok correct

Test #69:

score: 0
Accepted
time: 268ms
memory: 249504kb

input:

36 489
????????????????????????????????????

output:

NNNNNNNNNNNNNNNNAANAAAAAAAAAAAACACAA

result:

ok correct

Test #70:

score: 0
Accepted
time: 203ms
memory: 167304kb

input:

37 294
?????????????????????????????????????

output:

NNNNNNNNNNNNNNNNNNNNNAAAAAAAAAAAAAACA

result:

ok correct

Test #71:

score: -100
Time Limit Exceeded

input:

38 1558
??????????????????????????????????????

output:

NNNNNNNNNNNNNNNAAAAAANAAAAAAAACCCCCACC

result: