Submission #121108

# Submission time Handle Problem Language Result Execution time Memory
121108 2019-06-26T06:27:31 Z 이온조(#2969) Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
0 / 100
3 ms 384 KB
#include <bits/stdc++.h>
using namespace std;

char S[444];

int main() {
	int N, s = 0; scanf("%d",&N);
	for(int i=1; i<=N; i++) scanf(" %c", &S[i]);
	for(int k=1; k<=3*N; k++) {
		for(int i=2; i<=N; i++) {
			if(S[i] == S[i-1]) {
				int x = -1;
				for(int j=i+1; j<=N; j++) if(S[j] != S[i]) {x = j; break;}
				if(x != -1) for(int j=x; j>i; j--) {swap(S[j], S[j-1]); ++s;}
			}
		}
		for(int i=N-1; i>=1; i--) {
			if(S[i] == S[i+1]) {
				int x = -1;
				for(int j=i-1; j>=1; j--) if(S[j] != S[i]) {x = j; break;}
				if(x != -1)	for(int j=x; j<i; j++) {swap(S[j], S[j+1]); ++s;}
			}
		}
	}
	for(int i=2; i<=N; i++) if(S[i] == S[i-1]) return !printf("-1");
	printf("%d", s);
	return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:7:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int N, s = 0; scanf("%d",&N);
                ~~~~~^~~~~~~~~
joi2019_ho_t3.cpp:8:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=N; i++) scanf(" %c", &S[i]);
                          ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Incorrect 2 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Incorrect 2 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 360 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Incorrect 2 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Incorrect 2 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -