Submission #824640

# Submission time Handle Problem Language Result Execution time Memory
824640 2023-08-14T08:28:48 Z kshitij_sodani Rope (JOI17_rope) C++17
0 / 100
0 ms 340 KB
#include <bits/stdc++.h>
#define a first
#define b second
#define pb push_back
using namespace std;
#define endl '\n'
typedef long long llo;


int it[1000001];
int ans[1000001];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		ans[i]=n;
	}
	for(int i=0;i<n;i++){
		cin>>it[i];
		it[i]--;
		ans[it[i]]--;
	}
	
	for(int i=0;i<m;i++){
		for(int j=i+1;j<m;j++){
			for(int k=0;k<2;k++){
				pair<int,int> pr={-1,-1};
				int co=0;
				for(int l=0;l<n;l++){
					if(it[l]==i or it[l]==j){
						co++;

						if(pr.a==-1){
							pr={l,it[l]};
						}
						else if(it[l]==pr.b){
							pr={l,it[l]};
						}
						else if(pr.a<l-1){
							pr={l,it[l]};
						}
						else{
							if((pr.a-1)%2==k){
								pr={l,it[l]};
							}
							else{
								
								co--;
								continue;
							}
						}
					}
				}
				ans[i]=min(ans[i],n-co);
				ans[j]=min(ans[j],n-co);
			}
		}
	}

	for(int i=0;i<m;i++){
		cout<<ans[i]<<endl;

	}






	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 328 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -