제출 #332723

#제출 시각아이디문제언어결과실행 시간메모리
332723daniel920712JOIRIS (JOI16_joiris)C++14
15 / 100
486 ms262148 KiB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;
int all[55];
vector < pair < int , int > > ans;
int main()
{
    int N,M,t=0,ok,small,i,j,st;
    scanf("%d %d",&N,&M);
    for(i=0;i<N;i++)
    {
        scanf("%d",&all[i]);
        t+=all[i];
    }
    if(t%2!=N%2)
    {
        printf("-1\n");
        return 0;
    }
    else
    {
        while(1)
        {
            for(i=0;i<N;i++)
            {
                if(all[i]==0)
                {
                    if(i+3<N&&all[i+1]==1&&all[i+2]==0&all[i+3]==1)
                    {
                        ans.push_back(make_pair(1,i+1));
                        all[i]+=2;

                        ans.push_back(make_pair(2,i+2));
                        all[i+1]++;
                        all[i+2]++;

                        ans.push_back(make_pair(1,i+4));
                        all[i+3]+=2;
                        break;
                    }
                }
            }
            if(i!=N)
            {
                for(j=0;j<i;j++)
                {
                    ans.push_back(make_pair(1,j+1));
                    all[j]+=2;
                }
                for(j=i+4;j<N;j++)
                {
                    ans.push_back(make_pair(1,j+1));
                    all[j]+=2;
                }

                small=all[0];
                for(i=0;i<N;i++) small=min(small,all[i]);

                for(i=0;i<N;i++) all[i]-=small;
                for(i=0;i<N;i++) if(all[i]) break;

                if(i==N) break;
            }
            for(i=0;i<N;i++)
            {

                if(all[i]==0)
                {

                    if(i+1<N&&all[i+1]==0)
                    {
                        ans.push_back(make_pair(2,i+1));
                        all[i]++;
                        all[i+1]++;
                    }
                    else if(i+3<N&&all[i+1]==1&&all[i+2]==0&all[i+3]==1)
                    {
                        ans.push_back(make_pair(1,i+1));
                        all[i]+=2;

                        ans.push_back(make_pair(2,i+2));
                        all[i+1]++;
                        all[i+2]++;

                        ans.push_back(make_pair(1,i+4));
                        all[i+3]+=2;



                    }
                    else
                    {
                        ans.push_back(make_pair(1,i+1));
                        all[i]+=2;
                    }
                }
            }


            small=all[0];
            for(i=0;i<N;i++) small=min(small,all[i]);

            for(i=0;i<N;i++) all[i]-=small;
            for(i=0;i<N;i++) if(all[i]) break;

            if(i==N) break;

        }


    }
    printf("%d\n",ans.size());
    for(auto i:ans) printf("%d %d\n",i.first,i.second);
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

joiris.cpp: In function 'int main()':
joiris.cpp:31:52: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   31 |                     if(i+3<N&&all[i+1]==1&&all[i+2]==0&all[i+3]==1)
      |                                            ~~~~~~~~^~~
joiris.cpp:79:57: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   79 |                     else if(i+3<N&&all[i+1]==1&&all[i+2]==0&all[i+3]==1)
      |                                                 ~~~~~~~~^~~
joiris.cpp:115:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wformat=]
  115 |     printf("%d\n",ans.size());
      |             ~^    ~~~~~~~~~~
      |              |            |
      |              int          std::vector<std::pair<int, int> >::size_type {aka long unsigned int}
      |             %ld
joiris.cpp:11:17: warning: unused variable 'ok' [-Wunused-variable]
   11 |     int N,M,t=0,ok,small,i,j,st;
      |                 ^~
joiris.cpp:11:30: warning: unused variable 'st' [-Wunused-variable]
   11 |     int N,M,t=0,ok,small,i,j,st;
      |                              ^~
joiris.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
joiris.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |         scanf("%d",&all[i]);
      |         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...