QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#123834#2835. Number TheoryToUNVRSeRE 1ms9984kbC++141.6kb2023-07-13 19:25:482023-07-13 19:25:49

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-13 19:25:49]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:9984kb
  • [2023-07-13 19:25:48]
  • 提交

answer

#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=5010,T=944,H=T>>1,FSIZE=15010,INF=0x3f3f3f3f;
int tn,s[N];
int _f[2][T+1][T+1];
vector<pair<short,short>> p,np;
auto f=_f[0],nf=_f[1];
char BuF[FSIZE],*InF=BuF;
void cmin(int &a,int b){if(a>b) a=b;}
void work(){
    // for(;*InF<33;++InF);
    if(!~scanf("%s\n",InF)) exit(0);
    int sz=1,ans=INF;
    for(;*InF>32;s[++sz]=*InF++^48);
    for(auto i:p) f[i.first][i.second]=INF;
    f[H][H]=0;
    p.clear();
    p.emplace_back(H,H);
    for(int i=1,mx=1;i<sz;++i){
        mx+=abs(s[i]-s[i-1])*(sz-i+1);
        np.clear();
        for(auto h:p){
            int j=h.first,k=h.second,now=s[i]+j-H,c=f[j][k],del=k-now,
                lb=max({(now-k+10)/11,now-k,now-5}),
                rb=min({(T-k+now)/11,T-k+now,now+5});
            f[j][k]=INF;
            if(c>mx) continue;
            for(int l=lb+del,tmp=del+(l-del)*11;l<=rb+del;++l,tmp+=11){
                if(abs(tmp-H)>100) continue;
                if(nf[tmp][l]==INF) np.emplace_back(tmp,l);
                cmin(nf[tmp][l],c+abs(k-l)*(sz-i+1));
            }
        }
        swap(f,nf);
        swap(p,np);
    }
    for(auto h:p){
        int i=h.first,j=h.second;
        cmin(ans,f[i][j]+abs(s[sz]+i-H));
    }
    printf("%d\n",ans);
}
int main(){
    // fread(BuF,1,FSIZE,stdin);
    memset(f,63,sizeof(_f[0]));
    memset(nf,63,sizeof(_f[0]));
    p.reserve(N<<2); 
    np.reserve(N<<2);
    // for(;*InF>32;tn=tn*10+(*InF++^48));
    // for(;tn--;work());
    for(;;work());
    fclose(stdin);
    fclose(stdout);
    return(0);
}

詳細信息

Test #1:

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

input:

12
100
998244353

output:

3
5
76

result:

ok 3 lines

Test #2:

score: -100
Runtime Error

input:

4296
5370
8014
9532
6311
4070
2541
4782
5630
1487
2916
454
2020
5650
1851
5885
3556
6533
5044
1780
5746
5605
7860
4416
4495
8081
2416
3534
6045
3348
4536
8725
3505
1074
1531
937
7954
4451
7052
9586
3468
2679
6085
9908
3630
8046
6282
2883
9021
1436
5201
8166
8986
2167
7780
4156
101
3753
5732
5173
118...

output:

29
36
28
27
35
36
22
30
32
22
33
15
20
30
28
32
19
29
40
22
34
34
30
26
30
35
24
23
42
18
26
28
31
14
22
22
33
22
43
30
21
24
42
19
30
33
43
30
21
18
34
36
21
18
19
34
6
30
35
42
14
27
36
32
23
25
30
35
28
22
32
27
41
39
26
37
30
28
39
35
22
24
32
44
35
36
35
42
22
22
31
35
25
32
32
15
17
33
38
31
2...

result: