# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
827031 |
2023-08-16T08:14:02 Z |
반딧불(#10373) |
JOIRIS (JOI16_joiris) |
C++17 |
|
1 ms |
212 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, k;
int arr[52];
void subtask1();
void subtask2();
void subtask3();
void subtask4();
int main(){
scanf("%d %d", &n, &k);
for(int i=1; i<=n; i++) scanf("%d", &arr[i]);
if(0 && k==2){
if(n%2==0) subtask1();
else subtask2();
return 0;
}
if(n%k==0) subtask3();
else subtask4();
}
vector<pair<int, int> > ans;
void subtask1(){
if(accumulate(arr+1, arr+n+1, 0) % 2){
puts("-1");
exit(0);
}
for(int i=1; i<=n; i++){
while(arr[i] < arr[i-1]){
ans.push_back(make_pair(1, i));
arr[i] += 2;
}
}
int minV = *min_element(arr+1, arr+n+1);
for(int i=1; i<=n; i++) arr[i] -= minV;
for(int i=1; i<n; i++){
int v = arr[i+1] - arr[i];
for(int j=i-1; j>=1; j-=2) for(int c=0; c<v; c++) ans.push_back(make_pair(2, j));
if(i%2==0) for(int j=i+1; j<=n; j++) arr[j] -= v;
else for(int j=2; j<=i; j++) arr[j] += v;
}
int v = (arr[2] - arr[1]) / 2;
for(int i=0; i<v; i++) ans.push_back(make_pair(1, 1));
printf("%d\n", (int)ans.size());
for(auto p: ans){
printf("%d %d\n", p.first, p.second);
}
}
void subtask2(){
for(int i=1; i<=n; i++){
while(arr[i] < arr[i-1]){
ans.push_back(make_pair(1, i));
arr[i] += 2;
}
}
int minV = *min_element(arr+1, arr+n+1);
for(int i=1; i<=n; i++) arr[i] -= minV;
for(int i=1; i<n; i++){
int v = arr[i+1] - arr[i];
for(int j=i-1; j>=1; j-=2) for(int c=0; c<v; c++) ans.push_back(make_pair(2, j));
if(i%2==0) for(int j=i+1; j<=n; j++) arr[j] -= v;
else for(int j=2; j<=i; j++) arr[j] += v;
}
int v = (arr[2] - arr[1]) / 2;
for(int i=0; i<v; i++) ans.push_back(make_pair(1, 1)), arr[1] += 2;
if(arr[1] != arr[2]){
ans.push_back(make_pair(1, 1));
for(int i=2; i<n; i+=2) ans.push_back(make_pair(2, i));
}
printf("%d\n", (int)ans.size());
for(auto p: ans){
printf("%d %d\n", p.first, p.second);
}
}
int cntMod[52];
void subtask3(){
for(int i=1; i<=n; i++) cntMod[(i-1)%k+1] = (cntMod[(i-1)%k+1] + arr[i]) % k;
if(*max_element(cntMod+1, cntMod+k+1) != *min_element(cntMod+1, cntMod+k+1)){
puts("-1");
exit(0);
}
for(int i=1; i<=n; i++){
while(arr[i] < arr[i-1]){
ans.push_back(make_pair(1, i));
arr[i] += k;
}
}
int minV = *min_element(arr+1, arr+n+1);
for(int i=1; i<=n; i++) arr[i] -= minV;
for(int c=1; c<=k; c++){ /// 제거한 뒤 c열에 추가함
for(int i=c+k; i<=n; i+=k){
int v = arr[i] - arr[i-1];
for(int d=0; d<v; d++) for(int x=c; x<i; x+=k) ans.push_back(make_pair(2, x));
for(int j=1; j<c; j++) arr[j] -= v;
for(int j=i; j<=n; j++) arr[j] -= v;
}
while(arr[c] < arr[n]) ans.push_back(make_pair(1, c)), arr[c] += k;
int minV = *min_element(arr+1, arr+n+1);
for(int i=1; i<=n; i++) arr[i] -= minV;
printf("%d complete\n", c);
for(int i=1; i<=n; i++) printf("%d ", arr[i]);
puts("");
}
printf("%d\n", (int)ans.size());
for(auto p: ans){
printf("%d %d\n", p.first, p.second);
}
}
void subtask4(){
}
Compilation message
joiris.cpp: In function 'int main()':
joiris.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%d %d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~
joiris.cpp:17:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | for(int i=1; i<=n; i++) scanf("%d", &arr[i]);
| ~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Expected integer, but "complete" found |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Expected integer, but "complete" found |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Expected integer, but "complete" found |
5 |
Halted |
0 ms |
0 KB |
- |