QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#500800#6545. Connect the Dotscocoa_chan#WA 1ms7984kbC++172.0kb2024-08-01 20:48:322024-08-01 20:48:32

Judging History

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

  • [2024-08-01 20:48:32]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7984kb
  • [2024-08-01 20:48:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,m,i,j,k,l,r,x,y,z,w,s,t,a[1100000],dp[1100000],prv[1100000],e,ee;
ll possible(ll x,ll y)
{
    ll i;
    for(i=x;i<y;i++)
    {
        if(a[i]==a[i+1])
            return 0;
    }
    if(a[x]==a[y])
        return 0;
    return 1;
}
void asdf(ll x,ll y)
{
    ll i;
    for(i=x;i<y;i++)
        printf("%lld %lld\n",i,i+1);
    printf("%lld %lld\n",y,x);
}
int main()
{
    scanf("%lld",&e);
    for(ee=0;ee<e;ee++)
    {
        scanf("%lld %lld",&n,&m);
        for(i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
        }
        x=0;
        for(i=2;i<=n;i++)
        {
            if(a[i]!=a[1])
            {
                x=1;
                break;
            }
        }
        if(x==0)
        {
            printf("0\n");
            continue;
        }
        dp[0]=1;
        for(i=1;i<=n;i++)
        {
            dp[i]=0;
            prv[i]=0;
        }
        for(i=1;i<=n;i++)
        {
            for(j=3;j<=10;j++)
            {
                if(i-j<0)
                    continue;
                if(possible(i-j+1,i)&&dp[i-j]==1)
                    {
                        dp[i]=1;
                        prv[i]=i-j;
                    }
            }
        }
        if(dp[n])
        {
            printf("%lld\n",n);
            x=n;
            while(x)
            {
                asdf(prv[x]+1,x);
                x=prv[x];
            }
            continue;
        }
        printf("%lld\n",n-1);
        x=a[1];
        for(i=1;i<=n;i++)
        {
            if(x!=a[i])
            {
                y=i;
                printf("%lld %lld\n",ll(1),i);
                for(j=i-1;j>=2;j--)
                {
                    if(a[j]!=x)
                        break;
                    printf("%lld %lld\n",j,i);
                }
            }
        }
        for(i=y+1;i<=n;i++)
        {
            printf("%lld %lld\n",y,i);
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
4 2
1 1 2 2
4 2
1 2 1 2
3 3
1 2 3

output:

3
1 3
2 3
1 4
4
1 2
2 3
3 4
4 1
3
1 2
2 3
3 1

result:

ok all 3 test passed

Test #2:

score: 0
Accepted
time: 1ms
memory: 7964kb

input:

1
2 2
1 2

output:

1
1 2

result:

ok all 1 test passed

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 7984kb

input:

10
5 2
2 2 2 1 2
5 2
2 1 2 1 2
5 2
1 2 2 2 1
5 2
2 1 2 1 1
5 2
1 1 1 2 1
5 2
1 2 2 1 2
5 2
2 1 1 2 2
5 2
2 2 2 1 1
5 2
1 1 2 1 2
5 2
1 2 2 2 1

output:

4
1 4
3 4
2 4
4 5
4
1 2
1 4
3 4
4 5
4
1 2
1 3
1 4
4 5
4
1 2
1 4
3 4
1 5
4
1 4
3 4
2 4
4 5
4
1 2
1 3
1 5
4 5
4
1 2
1 3
3 4
3 5
4
1 4
3 4
2 4
1 5
4
1 3
2 3
1 5
4 5
4
1 2
1 3
1 4
4 5

result:

wrong answer output = 4, answer = 5.