QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#637099#8048. Roman Masterucup-team073#WA 52ms3804kbC++203.6kb2024-10-13 09:26:402024-10-13 09:26:40

Judging History

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

  • [2024-10-13 09:26:40]
  • 评测
  • 测评结果:WA
  • 用时:52ms
  • 内存:3804kb
  • [2024-10-13 09:26:40]
  • 提交

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[j+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: 3664kb

input:

3
II
IVI
VIIIIIV

output:

2
16
634

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 52ms
memory: 3804kb

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
55831
1784
5555631
235554
6736
564531
45545555
6455545
845555
55555535
67456
73556
8314
54577
2376
34557
16326
45324
45735
13745
5555664
558455
53136
6334
5355545
1863
27645
33145
53231
55556455
31345
3731
74531
6633
5455535
738
3276
8666
1455355
555555556
35354
456355
5733
338
5455535
6336
...

result:

wrong answer 2nd lines differ - expected: '55846', found: '55831'