Cod sursa(job #1397648)

Utilizator delia_99Delia Draghici delia_99 Data 23 martie 2015 17:38:42
Problema Multimi2 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.62 kb
#include <cstdio>

using namespace std;
int st[1000010],dr[1000010],i,n,r,dif;
int main()
{
    freopen("multimi2.in","r",stdin);
    freopen("multimi2.out","w",stdout);
    scanf("%d\n",&n);
    r=n%4;
    if(r==0)
    {
        for(i=n; i>=4; i-=4)
        {
            st[++st[0]]=i;
            st[++st[0]]=i-3;
        }
        for(i=n-1; i>=3; i-=4)
        {
            dr[++dr[0]]=i;
            dr[++dr[0]]=i-1;
        }
    }
    if(r==1)
    {
        for(i=n; i>=5; i-=4)
        {
            st[++st[0]]=i;
            st[++st[0]]=i-3;
        }
        for(i=n-1; i>=4; i-=4)
        {
            dr[++dr[0]]=i;
            dr[++dr[0]]=i-1;
        }
        st[++st[0]]=1;
        dif=1;
    }
    if(r==3)
    {
        for(i=n; i>=7; i-=4)
        {
            st[++st[0]]=i;
            st[++st[0]]=i-3;
        }
        for(i=n-1; i>=6; i-=4)
        {
            dr[++dr[0]]=i;
            dr[++dr[0]]=i-1;
        }
        st[++st[0]]=1;
        st[++st[0]]=2;
        dr[++dr[0]]=3;
        dif=0;
    }
    if(r==2)
    {
        dif=1;
        for(i=n; i>=6; i-=4)
        {
            st[++st[0]]=i;
            st[++st[0]]=i-3;
        }
        for(i=n-1; i>=5; i-=4)
        {
            dr[++dr[0]]=i;
            dr[++dr[0]]=i-1;
        }
        st[++st[0]]=1;
        dr[++dr[0]]=2;
    }
    printf("%d\n",dif);
    printf("%d\n",st[0]);
    for(i=1; i<=st[0]; ++i)
        printf("%d ",st[i]);
    printf("\n");
    printf("%d\n",dr[0]);
    for(i=1; i<=dr[0]; ++i)
        printf("%d ",dr[i]);
    printf("\n");

    return 0;
}