QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#740746 | #8776. Not Another Constructive! | actor | TL | 250ms | 3968kb | C++14 | 1.6kb | 2024-11-13 11:20:34 | 2024-11-13 11:20:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for (int i = (l); i <= (r); i++)
#define per(i,r,l) for (int i = (r); i >= (l); i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define maxn(a, b) a = max(a, b)
#define minn(a, b) a = min(a, b)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
const ll mod = 998244353;
mt19937 gen(random_device{}());
ll rp(ll a,ll b) {ll res=1%mod;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N = 40;
const int K = 2514;
int n, k;
char s[N], ans[N];
void dfs(int x, int a, int b, int c) {
if (x > n) {
if (c == k) {
printf("%s\n", ans + 1);
exit(0);
}
return ;
}
if (c < k && b + c > k) return ;
ans[x] = s[x];
if (s[x] == 'N') {
dfs(x + 1, a + 1, b, c);
} else if (s[x] == 'A') {
dfs(x + 1, a, b + a, c);
} else if (s[x] == 'C') {
dfs(x + 1, a, b, c + b);
} else if (s[x] == '?') {
ans[x] = 'S'; dfs(x + 1, a, b, c);
ans[x] = 'N'; dfs(x + 1, a + 1, b, c);
ans[x] = 'A'; dfs(x + 1, a, b + a, c);
ans[x] = 'C'; dfs(x + 1, a, b, c + b);
} else {
dfs(x + 1, a, b, c);
}
}
int main() {
scanf("%d%d", &n, &k);
scanf("%s", s + 1);
dfs(1, 0, 0, 0);
puts("-1");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3696kb
input:
22 2 N??A??????C???????????
output:
NSSASSSSSSCSSSSSSSSSSC
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
18 0 COUNTINGSATELLITES
output:
COUNTINGSATELLITES
result:
ok correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
2 1 ??
output:
-1
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3764kb
input:
1 0 ?
output:
S
result:
ok correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
1 0 N
output:
N
result:
ok correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
1 0 X
output:
X
result:
ok correct
Test #7:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
1 1 ?
output:
-1
result:
ok correct
Test #8:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
1 1 N
output:
-1
result:
ok correct
Test #9:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
1 1 X
output:
-1
result:
ok correct
Test #10:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
2 0 ??
output:
SS
result:
ok correct
Test #11:
score: 0
Accepted
time: 0ms
memory: 3956kb
input:
2 0 N?
output:
NS
result:
ok correct
Test #12:
score: 0
Accepted
time: 0ms
memory: 3732kb
input:
2 0 ?C
output:
SC
result:
ok correct
Test #13:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
2 1 N?
output:
-1
result:
ok correct
Test #14:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
2 1 ?C
output:
-1
result:
ok correct
Test #15:
score: 0
Accepted
time: 0ms
memory: 3900kb
input:
3 1 ???
output:
NAC
result:
ok correct
Test #16:
score: 0
Accepted
time: 0ms
memory: 3968kb
input:
3 1 N??
output:
NAC
result:
ok correct
Test #17:
score: 0
Accepted
time: 0ms
memory: 3968kb
input:
3 1 ?A?
output:
NAC
result:
ok correct
Test #18:
score: 0
Accepted
time: 0ms
memory: 3696kb
input:
3 1 ??C
output:
NAC
result:
ok correct
Test #19:
score: 0
Accepted
time: 0ms
memory: 3936kb
input:
3 1 NA?
output:
NAC
result:
ok correct
Test #20:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
3 1 N?C
output:
NAC
result:
ok correct
Test #21:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
3 1 ?AC
output:
NAC
result:
ok correct
Test #22:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
4 1 ????
output:
SNAC
result:
ok correct
Test #23:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
4 1 X???
output:
XNAC
result:
ok correct
Test #24:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
4 1 ???Z
output:
NACZ
result:
ok correct
Test #25:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
4 1 ?AA?
output:
-1
result:
ok correct
Test #26:
score: 0
Accepted
time: 0ms
memory: 3696kb
input:
4 1 N???
output:
NSAC
result:
ok correct
Test #27:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
4 1 ?N??
output:
SNAC
result:
ok correct
Test #28:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
4 1 ??N?
output:
NANC
result:
ok correct
Test #29:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
4 1 ???N
output:
NACN
result:
ok correct
Test #30:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
4 1 A???
output:
ANAC
result:
ok correct
Test #31:
score: 0
Accepted
time: 0ms
memory: 3944kb
input:
4 1 ?A??
output:
NASC
result:
ok correct
Test #32:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
4 1 ??A?
output:
SNAC
result:
ok correct
Test #33:
score: 0
Accepted
time: 0ms
memory: 3900kb
input:
4 1 ???A
output:
NACA
result:
ok correct
Test #34:
score: 0
Accepted
time: 0ms
memory: 3900kb
input:
4 1 C???
output:
CNAC
result:
ok correct
Test #35:
score: 0
Accepted
time: 0ms
memory: 3956kb
input:
4 1 ?C??
output:
NCAC
result:
ok correct
Test #36:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
4 1 ??C?
output:
NACS
result:
ok correct
Test #37:
score: 0
Accepted
time: 0ms
memory: 3936kb
input:
4 1 ???C
output:
SNAC
result:
ok correct
Test #38:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
5 4 ?????
output:
NNAAC
result:
ok correct
Test #39:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
6 14 ??????
output:
-1
result:
ok correct
Test #40:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
7 14 ???????
output:
-1
result:
ok correct
Test #41:
score: 0
Accepted
time: 1ms
memory: 3908kb
input:
8 43 ????????
output:
-1
result:
ok correct
Test #42:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
9 55 ?????????
output:
-1
result:
ok correct
Test #43:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
10 112 ??????????
output:
-1
result:
ok correct
Test #44:
score: 0
Accepted
time: 12ms
memory: 3552kb
input:
11 110 ???????????
output:
-1
result:
ok correct
Test #45:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
12 4 ????????????
output:
SSSSSSSNNAAC
result:
ok correct
Test #46:
score: 0
Accepted
time: 178ms
memory: 3832kb
input:
13 193 ?????????????
output:
-1
result:
ok correct
Test #47:
score: 0
Accepted
time: 250ms
memory: 3632kb
input:
14 91 ??????????????
output:
NNNNANAAACACCC
result:
ok correct
Test #48:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
15 15 ???????????????
output:
SSSSSSSNNNAACAC
result:
ok correct
Test #49:
score: -100
Time Limit Exceeded
input:
16 261 ????????????????