답안 #57180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
57180 2018-07-14T08:33:17 Z 정원준(#1655) JOIRIS (JOI16_joiris) C++11
30 / 100
4 ms 692 KB
#include <bits/stdc++.h>
#define L long long

using namespace std;

L n,K;
L a[55];

vector<L>ans1,ans2;

void E(){
	puts("-1");
	exit(0);
}

int main()
{
	scanf("%lld %lld",&n,&K);
	if(K==2)
	{
		L i,j,k;
		for(i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		for(i=2;i<=n;i++)
		{
			while(a[i]<a[i-1])
			{
				ans1.push_back(1);
				ans2.push_back(i);
				a[i]+=2;
			}
		}
		for(i=2;i<=n;i++)
		{
			a[i]-=a[1];
		}
		a[1]=0;
		for(i=3;i<=n;i++)
		{
			while(a[i]>a[i-1])
			{
				for(j=i-2;j>=1;j-=2)
				{
					ans1.push_back(2);
					ans2.push_back(j);
					a[j]++;
					a[j+1]++;
					if(j==1)
					{
						for(k=1;k<=n;k++)
						{
							a[k]--;
						}
					}
				}
			/*puts("");
			for(k=1;k<=n;k++)
			{
				printf("%lld ",a[k]);
			}
			puts("");*/
			}
		}
		for(i=1;i<=(a[2]+1)/2;i++)
		{
			ans1.push_back(1);
			ans2.push_back(1);
		}
		if(a[2]%2)
		{
			if(n%2)
			{
				for(i=2;i<=n;i+=2)
				{
					ans1.push_back(2);
					ans2.push_back(i);
				}
			}
			else
			{
				E();
			}
		}
	}
	else if(n%K==0)
	{
		L i,j,k;
		for(i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
		}
		for(i=2;i<=n;i++)
		{
			while(a[i]<a[i-1])
			{
				ans1.push_back(1);
				ans2.push_back(i);
				a[i]+=K;
			}
		}
		for(i=2;i<=n;i++)
		{
			a[i]-=a[1];
		}
		a[1]=0;
		for(i=K+1;i<=n;i++)
		{
			while(a[i]>a[i-1])
			{
				L changed=0;
				for(j=i-K;j>=1;j-=K)
				{
					if(j==1)
					{
						changed=1;
						ans1.push_back(2);
						ans2.push_back(1);
						for(k=1+K;k<=n;k++)
						{
							a[k]--;
						}
						continue;
					}
					if(a[j]!=a[i-1]) break;
					changed=1;
					ans1.push_back(2);
					ans2.push_back(j);
					for(k=0;k<K;k++)
					{
						a[j+k]++;
					}
				}
				/*puts("");
				for(k=1;k<=n;k++)
				{
					printf("%lld ",a[k]);
				}
				puts("");*/
				if(!changed) break;
			}
		}
		while(a[n])
		{
			L height;
			for(i=n;i>=1;i--)
			{
				if(a[i]==0)
				{
					height=a[i+1];
					break;
				}
			}
			L st=i;
			if(height%K) E();
			for(i=st;i>=1;i--)
			{
				for(j=1;j<=height/K;j++)
				{
					ans1.push_back(1);
					ans2.push_back(i);
				}
			}
			for(i=st+1;i<=n;i++)
			{
				a[i]-=height;
			}
				/*puts("");
				for(k=1;k<=n;k++)
				{
					printf("%lld ",a[k]);
				}
				puts("");*/
		}
	}
	printf("%lld\n",ans1.size());
	for(L i=0;i<ans1.size();i++)
	{
		printf("%lld %lld\n",ans1[i],ans2[i]);
	}
}

Compilation message

joiris.cpp: In function 'int main()':
joiris.cpp:177:29: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'std::vector<long long int>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%lld\n",ans1.size());
                  ~~~~~~~~~~~^
joiris.cpp:178:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(L i=0;i<ans1.size();i++)
            ~^~~~~~~~~~~~
joiris.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld",&n,&K);
  ~~~~~^~~~~~~~~~~~~~~~~~~
joiris.cpp:24:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld",&a[i]);
    ~~~~~^~~~~~~~~~~~~~
joiris.cpp:92:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld",&a[i]);
    ~~~~~^~~~~~~~~~~~~~
joiris.cpp:156:13: warning: 'height' may be used uninitialized in this function [-Wmaybe-uninitialized]
    if(height%K) E();
       ~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 692 KB Output is correct
6 Correct 2 ms 692 KB Output is correct
7 Correct 2 ms 692 KB Output is correct
8 Correct 4 ms 692 KB Output is correct
9 Correct 2 ms 692 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Correct 2 ms 692 KB Output is correct
12 Correct 2 ms 692 KB Output is correct
13 Correct 2 ms 692 KB Output is correct
14 Correct 2 ms 692 KB Output is correct
15 Correct 2 ms 692 KB Output is correct
16 Correct 2 ms 692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 692 KB Output is correct
2 Correct 2 ms 692 KB Output is correct
3 Correct 2 ms 692 KB Output is correct
4 Correct 2 ms 692 KB Output is correct
5 Correct 2 ms 692 KB Output is correct
6 Correct 2 ms 692 KB Output is correct
7 Correct 2 ms 692 KB Output is correct
8 Correct 2 ms 692 KB Output is correct
9 Correct 2 ms 692 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Correct 2 ms 692 KB Output is correct
12 Correct 2 ms 692 KB Output is correct
13 Correct 2 ms 692 KB Output is correct
14 Correct 2 ms 692 KB Output is correct
15 Correct 2 ms 692 KB Output is correct
16 Correct 2 ms 692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 692 KB Output is correct
6 Correct 2 ms 692 KB Output is correct
7 Correct 2 ms 692 KB Output is correct
8 Correct 4 ms 692 KB Output is correct
9 Correct 2 ms 692 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Correct 2 ms 692 KB Output is correct
12 Correct 2 ms 692 KB Output is correct
13 Correct 2 ms 692 KB Output is correct
14 Correct 2 ms 692 KB Output is correct
15 Correct 2 ms 692 KB Output is correct
16 Correct 2 ms 692 KB Output is correct
17 Correct 2 ms 692 KB Output is correct
18 Correct 2 ms 692 KB Output is correct
19 Incorrect 2 ms 692 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 692 KB Output is correct
6 Correct 2 ms 692 KB Output is correct
7 Correct 2 ms 692 KB Output is correct
8 Correct 4 ms 692 KB Output is correct
9 Correct 2 ms 692 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Correct 2 ms 692 KB Output is correct
12 Correct 2 ms 692 KB Output is correct
13 Correct 2 ms 692 KB Output is correct
14 Correct 2 ms 692 KB Output is correct
15 Correct 2 ms 692 KB Output is correct
16 Correct 2 ms 692 KB Output is correct
17 Correct 2 ms 692 KB Output is correct
18 Correct 2 ms 692 KB Output is correct
19 Correct 2 ms 692 KB Output is correct
20 Correct 2 ms 692 KB Output is correct
21 Correct 2 ms 692 KB Output is correct
22 Correct 2 ms 692 KB Output is correct
23 Correct 2 ms 692 KB Output is correct
24 Correct 2 ms 692 KB Output is correct
25 Correct 2 ms 692 KB Output is correct
26 Correct 2 ms 692 KB Output is correct
27 Correct 2 ms 692 KB Output is correct
28 Correct 2 ms 692 KB Output is correct
29 Correct 2 ms 692 KB Output is correct
30 Correct 2 ms 692 KB Output is correct
31 Correct 2 ms 692 KB Output is correct
32 Correct 2 ms 692 KB Output is correct
33 Correct 2 ms 692 KB Output is correct
34 Correct 2 ms 692 KB Output is correct
35 Incorrect 2 ms 692 KB Output isn't correct
36 Halted 0 ms 0 KB -