QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#651238#8048. Roman MasterTggdb#WA 18ms5748kbC++202.3kb2024-10-18 17:32:042024-10-18 17:32:21

Judging History

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

  • [2024-10-18 17:32:21]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:5748kb
  • [2024-10-18 17:32:04]
  • 提交

answer

#include<stdio.h>
#include<iostream>
#include<algorithm>
#define inf 0X7fffffff
#define int long long
using namespace std;
const int N=2e6+9;
int read(int &x){
    int dat=0,oko=1;char chc=getchar();
    while(chc<'0'||chc>'9'){if(chc=='-')oko=-1;chc=getchar();}
    while(chc>='0'&&chc<='9'){dat=dat*10+chc-'0';chc=getchar();}
    x=dat*oko;return x;
}int T,n,ans,val[N];
bool vis[N];
string s;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>T;
    while(T--){
        cin>>s;n=s.length();ans=0;
        for(int i=0;i<n;i++){
            if(s[i]=='I')val[i]=1;
            if(s[i]=='V')val[i]=5;
            //cout<<"val["<<i<<"]="<<val[i];1
            vis[i]=false;
        }
        for(int i=1;i<n;i++){//cout<<"FCLK\n";
            if(s[i]=='V'&&i){
                if((i+1<n&&s[i+1]=='V')||i==n-1){
                    if(s[i-1]=='I'){
                        vis[i-1]=true;
                        //printf("vis[%lld]=1\n",i-1);
                        val[i]=4;
                    }
                }
            }
        }int pre=0,head=n;
        for(int i=0;i<n;i++){
            if(vis[i])continue;
            if(s[i]=='V'){
                head=i;break;
            }else pre++;
        }
        if(pre){
            ans=pre%3;//cout<<"pre"<<pre<<"\n";
            for(int i=1;i<=(pre/3);i++){
                ans=ans*10+3;
            }
        }int tot=0;
        for(int i=head+1;i<s.length();i++){
            if(s[i]=='V'||vis[i]){
                if(val[i]==4){
                    ans=ans*10+4;
                    continue;
                }int len=tot/3;
                if(tot%3||!len){
                    ans=ans*10+tot%3+5;
                }else {
                    ans=ans*10+8;len--;
                }
                for(int j=1;j<=len;j++){
                    ans=ans*10+3;
                }tot=0;
            }else{
                tot++;
            }
        }if(tot){
            //cout<<tot<<"\n";
            int len=tot/3;
            if(tot%3){
                ans=ans*10+tot%3+5;
            }else {
                ans=ans*10+8;len--;
            }
            for(int j=1;j<=len;j++){
                ans=ans*10+3;
            }tot=0;
        }
        cout<<ans<<"\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5740kb

input:

3
II
IVI
VIIIIIV

output:

2
16
634

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 18ms
memory: 5748kb

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:

55455557
558456
1784
55556456
3545554
6736
56455456
55545555
64555545
845555
55555654
674556
854556
84564
545577
2376
35557
164576
554574
55854
13745
5555664
558455
545636
6334
65455545
1863
27645
35645
5457456
55556455
56345
37456
7455456
6633
54555654
738
5776
8666
1556545
555555556
166654
557545
...

result:

wrong answer 1st lines differ - expected: '5545557', found: '55455557'