답안 #781716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781716 2023-07-13T10:20:58 Z vjudge1 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ll long long
#define pb push_back
#define N 200005
int n;
int arr[N];
int main(){
	lalala;
	cin>>n;
	string str;cin>>str;
	int r=0,g=0;
	for(int i=0;i<n;i++){
		if(str[i]=='G'){
			arr[i]=1;g++;}

		if(str[i]=='R'){
			arr[i]=2;r++;}
	}
	if(abs(g-r)>1){
		cout<<-1<<endl;
		return 0;
	}
	ll int cev=0;
	for(int i=0;i<n-1;i++){
		//cout<<cev<<endl;
		if(arr[i]==arr[i+1]){
			for(int j=n-1;j>i;j--){
				if(arr[j]==arr[j-1]&&arr[j]!=arr[i]){
					swap(arr[i+1],arr[j-1]);
					//cout<<i<< " "<<j-1<<endl;
					cev+=(j-1-(i+1));break;
				}
			}
		}
	}cout<<cev<<endl;


}#include<bits/stdc++.h>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ll long long
#define pb push_back
#define N 200005
int n;
int arr[N];
int main(){
	lalala;
	cin>>n;
	string str;cin>>str;
	int r=0,g=0;
	for(int i=0;i<n;i++){
		if(str[i]=='G'){
			arr[i]=1;g++;}

		if(str[i]=='R'){
			arr[i]=2;r++;}
	}
	if(abs(g-r)>1){
		cout<<-1<<endl;
		return 0;
	}
	ll int cev=0;
	for(int i=0;i<n-1;i++){
		//cout<<cev<<endl;
		if(arr[i]==arr[i+1]){
			for(int j=n-1;j>i;j--){
				if(arr[j]==arr[j-1]&&arr[j]!=arr[i]){
					swap(arr[i+1],arr[j-1]);
					//cout<<i<< " "<<j-1<<endl;
					cev+=(j-1-(i+1));break;
				}
			}
		}
	}cout<<cev<<endl;


}

Compilation message

joi2019_ho_t3.cpp:41:2: error: stray '#' in program
   41 | }#include<bits/stdc++.h>
      |  ^
joi2019_ho_t3.cpp:41:3: error: 'include' does not name a type
   41 | }#include<bits/stdc++.h>
      |   ^~~~~~~
joi2019_ho_t3.cpp:48:5: error: redefinition of 'int n'
   48 | int n;
      |     ^
joi2019_ho_t3.cpp:8:5: note: 'int n' previously declared here
    8 | int n;
      |     ^
joi2019_ho_t3.cpp:49:5: error: redefinition of 'int arr [200005]'
   49 | int arr[N];
      |     ^~~
joi2019_ho_t3.cpp:9:5: note: 'int arr [200005]' previously declared here
    9 | int arr[N];
      |     ^~~
joi2019_ho_t3.cpp:50:5: error: redefinition of 'int main()'
   50 | int main(){
      |     ^~~~
joi2019_ho_t3.cpp:10:5: note: 'int main()' previously defined here
   10 | int main(){
      |     ^~~~