QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#637097 | #8048. Roman Master | ucup-team073# | WA | 48ms | 3776kb | C++20 | 3.6kb | 2024-10-13 09:23:30 | 2024-10-13 09:23:31 |
Judging History
answer
#include<bits/stdc++.h>
#ifdef LOCAL
#define debug(...) printf(__VA_ARGS__)
#define edebug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#define edebug(...)
#endif
#define int ll
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define nrep(i, x, y) for(int i = x; i >= y; --i)
#define ll long long
#define pii std::pair<int,int>
#define pb emplace_back
#define fi first
#define se second
template <class T>
inline void ckmax(T &a, T b) {
if(a < b) a = b;
}
template <class T>
inline void ckmin(T &a, T b) {
if(a > b) a = b;
}
auto rt_YES = []{puts("YES");};
auto rt_Yes = []{puts("Yes");};
auto rt_NO = []{puts("NO");};
auto rt_No = []{puts("No");};
namespace IO {
#define isdigit(x) (x >= '0' && x <= '9')
inline char gc() {
return getchar();
}
inline bool blank(char ch) {
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
template <class T>
inline void read(T &x) {
double tmp = 1;
bool sign = 0;
x = 0;
char ch = gc();
for(; !isdigit(ch); ch = gc())
if(ch == '-') sign = 1;
for(; isdigit(ch); ch = gc())
x = x * 10 + (ch - '0');
if(ch == '.')
for(ch = gc(); isdigit(ch); ch = gc())
tmp /= 10.0, x += tmp * (ch - '0');
if(sign) x = -x;
}
inline void read(char *s) {
char ch = gc();
for(; blank(ch); ch = gc());
for(; !blank(ch); ch = gc())
*s++ = ch;
*s = 0;
}
inline void read(char &c) {
for(c = gc(); blank(c); c = gc());
}
inline void push(const char &c) {
putchar(c);
}
template <class T>
inline void print(T x) {
if(x < 0) {
x = -x;
push('-');
}
static T sta[35];
T top = 0;
do {
sta[top++] = x % 10;
x /= 10;
} while(x);
while(top)
push(sta[--top] + '0');
}
template <class T>
inline void print(T x, char lastChar) {
print(x);
push(lastChar);
}
}
using namespace IO;
char s[100010];
int f[100010];
void solve(){
std::cin>>s;
int n=strlen(s);
rep(i,0,n+5)f[i]=1e9;
f[n]=0;
nrep(i,n-1,0){
rep(j,i,i+3){
if(j>=n)break;
if(j==i)ckmin(f[i],f[j+1]+1);
if(j==i+1){
if(s[i]=='I'&&s[i+1]=='I')ckmin(f[i],f[j+1]+1);
if(s[i]=='I'&&s[i+1]=='V')ckmin(f[i],f[j+1]+1);
if(s[i]=='V'&&s[i+1]=='I')ckmin(f[i],f[j+1]+1);
}
if(j==i+2){
if(s[i]=='I'&&s[i+1]=='I'&&s[i+2]=='I')ckmin(f[i],f[j+1]+1);
if(s[i]=='V'&&s[i+1]=='I'&&s[i+2]=='I')ckmin(f[i],f[j+1]+1);
}
if(j==i+3){
if(s[i]=='V'&&s[i+1]=='I'&&s[i+2]=='I'&&s[i+3]=='I')ckmin(f[i],f[i+1]+1);
}
}
}
int i=0;
while(1){
int nxt=0,dig=100;
if(f[i]==f[i+1]+1){
int t=0;
if(s[i]=='I')t=1;
else t=5;
if(t<dig)nxt=i+1,dig=t;
}
if(f[i]==f[i+2]+1){
int t=0;
if(s[i]=='V')t=6;
else if(s[i+1]=='V')t=4;
else t=2;
if(t<dig)nxt=i+2,dig=t;
}
if(f[i]==f[i+3]+1){
int t=0;
if(s[i]=='V')t=7;
else t=3;
if(t<dig)nxt=i+3,dig=t;
}
if(f[i]==f[i+4]+1){
int t=8;
if(t<dig)nxt=i+4,dig=t;
}
print(dig);
i=nxt;
if(nxt>=n)break;
}
puts("");
}
signed main() {
clock_t c1 = clock();
#ifdef LOCAL
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
//------------------------------------------------------------------
int t;read(t);while(t--)solve();
//------------------------------------------------------------------
end:
std::cerr << "Time : " << clock() - c1 << " ms" << std::endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3708kb
input:
3 II IVI VIIIIIV
output:
2 16 634
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 48ms
memory: 3776kb
input:
100000 VVIVVVVVII VVVIIIIVVI IVIIVIIIIV VVVVVIIVVI IIIVIVVVIV VIVIIIIIVI VVIIVVIVVI IVVVIVVVVV VIIVVVVIVV VIIIIVVVVV VVVVVVIVIV VIVIIIVVVI VIIIVIVVVI VIIIIVVIIV VIVVVIIVII IIIIIVIIVI IIIIVVVVII IVIIVVIIVI IVVIVVIIIV IVVVIIIVIV IIIIVIIIVV VVVVVIVIIV VVVIIIIVVV VIVVIIIIVI VIIIIIIIIV VIVIVVVIVV IVIIIVI...
output:
5545557 555331 16324 5555631 235554 6736 564531 45545555 6455545 5345555 55555535 67456 73556 53314 54577 2376 34557 16326 45324 45735 13745 5555664 5553455 53136 6334 5355545 3263 27645 33145 53231 55556455 31345 3731 74531 6633 5455535 6332 3276 53666 1455355 555555556 35354 456355 5733 3232 54555...
result:
wrong answer 2nd lines differ - expected: '55846', found: '555331'