답안 #953512

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
953512 2024-03-26T05:03:04 Z PM1 Boarding Passes (BOI22_passes) C++17
0 / 100
2000 ms 2908 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxn=1e5+5,mxg=15;
int g,n,a[mxn],cnt=0,all[mxg+5];
string s;
ll dp[(1<<mxg)],res[(1<<mxg)][mxg+5],z=1,sum[(1<<mxg)],num[mxg+5],rsum[(1<<mxg)],zz=2;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>s;
	n=s.size();
	for(int i=0;i<n;i++){
		int x=s[i];
		a[x]=(a[x]==0)?++cnt:a[x];
		x=a[x];
		all[x]+=z;
		for(int j=0;j<(1<<mxg);j++){
			if(j&(1<<(x-1))){
				rsum[j]+=z;
			}
		}
	}
	for(int i=0;i<n;i++){
		int x=s[i];
		x=a[x];
		for(int j=0;j<(1<<cnt);j++){
			if(j&(1<<(x-1)))continue;
			res[j][x]+=min(sum[j]+num[x],rsum[j]+all[x]-num[x]-z);
		}
		for(int j=0;j<(1<<cnt);j++){
			if(j&(1<<(x-1))){
				rsum[j]-=z;
				sum[j]+=z;
			}
		}
		num[x]+=z;
	}
	for(int i=1;i<(1<<cnt);i++){
		dp[i]=1e18;
		for(int j=0;j<cnt;j++){
			if(i&(1<<j)){
				int y=i-(1<<j);
				dp[i]=min(dp[i],dp[y]+res[y][j+1]);
			}
		}
	}
	cout<<dp[(1<<cnt)-1]/2;
	if(dp[(1<<cnt)-1]%2)
		cout<<".5";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 2652 KB found '100800.5000000000', expected '100800.5000000000', error '0.0000000000'
2 Correct 1 ms 2652 KB found '0.0000000000', expected '0.0000000000', error '-0.0000000000'
3 Correct 1 ms 2516 KB found '0.0000000000', expected '0.0000000000', error '-0.0000000000'
4 Correct 1 ms 2652 KB found '1.0000000000', expected '1.0000000000', error '0.0000000000'
5 Correct 28 ms 2696 KB found '124002.0000000000', expected '124002.0000000000', error '0.0000000000'
6 Execution timed out 2060 ms 2908 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB found '1.0000000000', expected '1.0000000000', error '0.0000000000'
2 Correct 5 ms 2652 KB found '1225.0000000000', expected '1225.0000000000', error '0.0000000000'
3 Incorrect 4 ms 2652 KB 1st numbers differ - expected: '1023.0000000000', found: '597.5000000000', error = '0.4159335288'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB found '1.0000000000', expected '1.0000000000', error '0.0000000000'
2 Correct 5 ms 2652 KB found '1225.0000000000', expected '1225.0000000000', error '0.0000000000'
3 Incorrect 4 ms 2652 KB 1st numbers differ - expected: '1023.0000000000', found: '597.5000000000', error = '0.4159335288'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 2652 KB found '100800.5000000000', expected '100800.5000000000', error '0.0000000000'
2 Correct 1 ms 2652 KB found '0.0000000000', expected '0.0000000000', error '-0.0000000000'
3 Correct 1 ms 2516 KB found '0.0000000000', expected '0.0000000000', error '-0.0000000000'
4 Correct 1 ms 2652 KB found '1.0000000000', expected '1.0000000000', error '0.0000000000'
5 Correct 28 ms 2696 KB found '124002.0000000000', expected '124002.0000000000', error '0.0000000000'
6 Execution timed out 2060 ms 2908 KB Time limit exceeded
7 Halted 0 ms 0 KB -