QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#225583#7615. Sequence FoldingKIK313#WA 15ms173708kbC++171.5kb2023-10-24 20:17:012023-10-24 20:17:02

Judging History

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

  • [2023-10-24 20:17:02]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:173708kb
  • [2023-10-24 20:17:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int m,tot,cnt;
long long n,pos[100100],net[2][7000010];
int co[7000100];
unordered_map<long long,int> M;
pair<int,int> edge[7000010];
vector<int> v[7000010];
int f[7000010][2];
void dp(int x) {
    for(int i=0;i<(int)v[x].size();i++) {
        int y=v[x][i];
        dp(y);
        f[x][0]+=min(f[y][0],f[y][1]+1);
        f[x][1]+=min(f[y][1],f[y][0]+1);
    }
    if(co[x]) f[x][0]++; else f[x][1]++;
}
int main() {
    scanf("%lld%d",&n,&m);
    for(int i=1;i<=m;i++) scanf("%lld",&pos[i]);
    for(int i=1;i<=m;i++) {
        long long r=n;
        long long x=pos[i];
        if(!M[x]) M[x]=++tot;
        co[tot]=1;
        while(r>1) {
            //cerr<<x<<' '<<r<<" -100"<<endl;
            if(x>r/2) {
                if(!M[x]) {
                    M[x]=++tot; 
                }            
                int t=M[x];
                if(!M[r+1-x]) M[r+1-x]=++tot;
                int tt=M[r+1-x];
                edge[++cnt]=make_pair(tt,t);
                x=r+1-x;
            }
            r=r/2;
        }
    }
   //cerr<<cnt<<" kkk"<<endl;
    sort(edge+1,edge+cnt+1);
    for(int i=1,j;i<=cnt;i=j+1) {
        j=i;
        while(j+1<=cnt&&edge[j+1]==edge[i]) j++;
        //cerr<<edge[i].first<<' '<<edge[i].second<<" OO"<<endl;
        v[edge[i].first].push_back(edge[i].second);
    }
    int rt=M[1];
    //cerr<<M[1]<<" what"<<" -100"<<endl;
    dp(rt);
    printf("%d\n",min(f[rt][0],f[rt][1]));
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 15ms
memory: 173708kb

input:

8 3
1 5 8

output:

1

result:

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