QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#490030#6159. 信号传递kymmykym#0 1474ms12700kbC++141.1kb2024-07-25 10:32:032024-07-25 10:32:03

Judging History

你现在查看的是最新测评结果

  • [2024-07-25 10:32:03]
  • 评测
  • 测评结果:0
  • 用时:1474ms
  • 内存:12700kb
  • [2024-07-25 10:32:03]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long 
const int maxm = 23;
const int maxn=100005;
int dp[(1<<maxm) + 5];
const int oo = 1'000'000'000'000'000'000ll;
int n,m,k;
int S[maxn];
int F[maxm][maxm];
int B[maxm][maxm];
int32_t main(){
	for(int i=1;i<1<<m;i++)dp[i]=oo;
	cin >> n >> m >> k;
	for(int i=1;i<=n;i++){
		cin>>S[i];
		--S[i];
	}
	for(int i=1;i<=n-1;i++){
		F[S[i]][S[i+1]]++;
		B[S[i+1]][S[i]]++;
	}
	for(int bm=0;bm<1<<m;bm++){
		vector<int>on,off;
		for(int i=0;i<m;i++){
			if(bm&(1<<i)){
				on.push_back(i);
			} else{
				off.push_back(i);
			}
		} 
		for(auto x:off){
			int pos = on.size() + 1;
			int nbm=bm|(1<<x);
			int res=dp[bm];
			for(int b=0;b<m;b++){
				if(b==x)continue;
				if(bm&(1<<b)){
					res += k * F[x][b] * pos;
				} else{
					res += F[x][b] * (-pos);
				}
			}
			for(int b=0;b<m;b++){
				if(b==x)continue;
				if(bm&(1<<b)){
					res += B[x][b] * pos;	
				} else{
					res += B[x][b] * pos * k;
				}
			}
			dp[nbm]=min(dp[nbm],res);
		}
	}
	cout<<dp[(1<<m)-1];
}

详细


Pretests


Final Tests

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3776kb

input:

62 4 6
1 3 3 1 2 3 2 3 4 3 3 3 4 3 2 1 1 4 3 3 1 1 1 4 1 2 4 2 4 4 1 1 2 2 3 4 2 3 4 4 1 1 4 4 2 1 4 2 2 4 3 3 2 2 1 2 3 1 2 1 1 1

output:

0

result:

wrong answer 1st numbers differ - expected: '619', found: '0'

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 3772kb

input:

87 4 2
1 4 2 3 4 4 2 2 1 4 2 3 3 3 1 3 1 4 2 2 2 4 4 4 4 3 1 1 2 3 2 4 2 3 4 3 3 3 3 2 4 3 2 1 1 1 3 2 3 3 4 4 3 1 3 4 1 3 2 2 3 2 2 4 3 4 1 1 4 1 1 1 2 2 3 2 3 1 4 2 2 3 2 4 2 1 2

output:

0

result:

wrong answer 1st numbers differ - expected: '334', found: '0'

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 3536kb

input:

95 7 5
3 5 7 3 2 5 6 1 1 4 2 2 5 4 6 3 5 7 1 1 3 3 6 7 3 1 2 2 4 6 3 6 7 1 5 3 3 4 7 1 1 4 1 3 7 5 6 4 7 4 7 4 2 6 4 5 2 2 6 1 4 6 5 2 6 2 7 1 1 4 3 2 6 6 6 5 6 7 3 2 3 1 1 5 3 2 5 7 1 5 1 4 6 4 2

output:

0

result:

wrong answer 1st numbers differ - expected: '1363', found: '0'

Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 3584kb

input:

54 5 3
5 4 4 4 4 3 5 2 2 1 2 2 3 5 3 2 1 4 3 1 5 2 5 1 4 1 5 1 1 1 5 5 4 5 2 1 2 5 2 4 1 1 1 3 2 4 1 1 5 2 5 2 5 5

output:

0

result:

wrong answer 1st numbers differ - expected: '322', found: '0'

Test #5:

score: 0
Wrong Answer
time: 0ms
memory: 3520kb

input:

55 4 1
3 2 3 1 4 1 3 3 2 3 1 4 4 3 3 4 4 3 3 3 4 4 1 1 1 1 4 3 2 1 2 1 2 3 1 2 1 4 4 3 4 3 1 3 3 4 4 2 3 3 3 1 4 2 3

output:

0

result:

wrong answer 1st numbers differ - expected: '114', found: '0'

Test #6:

score: 0
Wrong Answer
time: 0ms
memory: 3520kb

input:

88 7 4
5 1 7 2 3 7 3 5 7 2 7 1 1 7 6 3 3 1 3 7 5 1 3 5 6 4 2 4 2 2 6 7 7 3 6 3 3 5 1 6 3 2 7 1 4 4 7 4 1 1 3 1 4 1 5 5 1 3 4 5 4 5 1 7 5 1 1 3 4 6 6 5 2 3 2 6 1 2 3 6 2 6 3 3 7 1 4 1

output:

0

result:

wrong answer 1st numbers differ - expected: '1072', found: '0'

Test #7:

score: 0
Wrong Answer
time: 1468ms
memory: 12700kb

input:

97864 20 22
10 16 2 14 10 5 8 18 20 7 4 10 20 5 11 6 18 7 20 7 10 3 11 7 1 9 5 3 11 18 15 15 9 8 16 17 20 18 4 18 6 13 2 13 20 4 20 1 18 20 6 17 19 3 4 10 8 14 20 10 3 4 7 10 18 4 2 9 14 14 12 18 17 19 15 10 3 7 20 3 20 6 11 12 9 9 18 18 9 2 9 2 6 10 1 9 20 2 5 8 1 20 10 3 2 19 14 12 4 14 19 12 19 1...

output:

0

result:

wrong answer 1st numbers differ - expected: '21467158', found: '0'

Test #8:

score: 0
Wrong Answer
time: 1470ms
memory: 12580kb

input:

99240 20 81
4 14 5 13 16 11 8 19 12 5 8 6 2 15 2 17 1 16 11 2 1 10 3 13 5 7 12 15 17 14 6 17 14 16 9 3 14 3 13 2 12 10 13 10 12 11 8 12 11 10 7 19 10 18 11 19 15 13 14 3 15 19 4 7 5 15 8 10 8 5 10 14 17 3 19 16 11 19 11 9 7 1 14 1 5 17 19 7 8 11 5 9 6 5 6 10 7 8 13 13 16 7 10 15 1 8 17 4 4 9 19 18 1...

output:

0

result:

wrong answer 1st numbers differ - expected: '79146075', found: '0'

Test #9:

score: 0
Wrong Answer
time: 1474ms
memory: 12484kb

input:

90117 20 72
14 14 6 10 9 5 8 9 7 6 18 2 3 19 9 12 7 19 20 13 7 4 3 4 7 9 19 8 11 12 16 12 3 8 19 1 20 4 9 19 6 20 8 8 2 8 20 17 13 6 1 10 9 7 3 12 20 5 1 13 7 18 14 7 5 17 14 17 12 5 5 3 3 11 9 16 5 5 12 5 4 15 2 7 6 1 12 13 8 12 7 19 15 2 1 11 20 16 17 18 18 2 10 4 7 18 8 19 7 4 3 9 8 2 13 6 3 14 4...

output:

0

result:

wrong answer 1st numbers differ - expected: '63791487', found: '0'

Test #10:

score: 0
Wrong Answer
time: 1457ms
memory: 12508kb

input:

93274 20 81
19 19 6 13 17 4 10 18 5 19 4 7 4 1 10 20 1 19 2 10 12 9 3 13 9 15 13 14 8 14 2 6 20 2 9 7 11 4 10 17 6 1 10 12 1 19 13 20 5 4 13 4 8 13 17 15 13 17 13 4 20 2 20 18 4 3 7 12 11 15 8 20 14 4 19 1 11 19 19 9 15 16 9 5 7 9 4 2 20 16 9 16 13 12 13 11 6 7 18 19 11 1 19 4 7 16 14 12 17 9 5 17 1...

output:

0

result:

wrong answer 1st numbers differ - expected: '74419960', found: '0'

Test #11:

score: 0
Wrong Answer
time: 1468ms
memory: 12544kb

input:

96831 20 93
12 19 17 6 7 20 3 14 5 13 19 12 15 7 14 9 7 15 20 10 10 18 12 12 2 19 12 15 7 8 9 15 20 8 11 3 4 9 4 7 10 5 17 1 13 13 10 6 16 20 3 18 5 17 3 13 13 8 20 15 8 10 18 3 9 11 13 3 19 12 13 11 13 13 17 3 15 20 8 13 2 14 10 16 14 2 5 14 14 8 17 12 4 4 14 7 18 7 6 17 16 13 7 2 2 4 14 16 17 3 4 ...

output:

0

result:

wrong answer 1st numbers differ - expected: '88602279', found: '0'

Test #12:

score: 0
Wrong Answer
time: 1469ms
memory: 12532kb

input:

96251 20 38
18 15 8 5 10 17 16 8 5 12 15 19 16 7 18 4 8 12 3 13 3 1 13 14 19 16 11 17 3 11 14 12 12 9 15 3 9 20 16 15 13 1 1 2 12 17 11 20 5 19 20 5 20 13 18 20 12 16 8 7 10 6 5 4 15 3 8 19 18 15 19 13 5 13 12 4 17 16 5 8 16 13 15 10 20 6 17 4 1 9 2 16 3 20 8 16 11 3 3 4 6 10 17 13 12 5 3 15 3 6 4 1...

output:

0

result:

wrong answer 1st numbers differ - expected: '36201870', found: '0'

Test #13:

score: 0
Time Limit Exceeded

input:

92874 21 99
15 10 19 18 6 9 7 11 14 13 6 4 6 10 11 6 13 17 14 1 18 17 14 2 16 20 11 6 16 13 11 4 1 17 4 3 6 7 4 1 7 9 9 6 3 11 21 2 21 17 12 1 1 19 19 19 10 21 10 10 11 6 21 20 19 15 17 5 18 15 20 17 5 21 5 12 16 8 18 6 16 16 4 12 14 7 7 12 8 9 20 15 3 13 1 10 6 19 11 17 3 9 16 5 3 16 5 21 8 7 8 12 ...

output:


result:


Test #14:

score: 0
Time Limit Exceeded

input:

93171 21 46
9 5 2 18 18 15 6 8 6 14 10 11 11 9 14 12 17 1 1 19 3 20 9 1 7 7 4 15 11 12 3 2 7 14 12 18 5 3 16 14 9 9 19 14 21 20 6 17 14 9 18 4 7 8 3 20 4 9 1 12 6 18 9 17 10 3 3 2 18 2 4 6 18 19 14 4 12 3 8 1 1 14 11 21 10 6 15 18 20 2 13 18 7 10 9 18 16 17 16 15 4 13 18 2 3 11 21 10 8 6 10 6 5 4 8 ...

output:


result:


Test #15:

score: 0
Time Limit Exceeded

input:

95808 22 25
15 13 17 3 18 1 9 2 19 21 17 16 15 8 12 6 21 7 13 21 8 14 15 19 15 9 8 4 2 9 14 3 14 5 21 9 16 7 18 6 13 15 18 9 17 9 5 6 19 17 7 4 17 2 18 14 19 12 17 5 11 8 6 20 22 4 6 15 10 11 13 8 21 9 4 13 5 17 14 14 22 19 12 19 19 11 18 11 20 8 4 6 18 12 18 20 14 14 1 17 10 8 3 6 20 5 2 4 3 17 12 ...

output:


result:


Test #16:

score: 0
Time Limit Exceeded

input:

97413 22 86
13 20 15 16 16 3 6 19 8 20 18 10 5 3 12 3 2 10 9 12 18 20 13 15 11 5 7 12 21 6 14 3 21 1 10 8 19 20 7 22 13 10 6 9 16 22 16 21 14 11 21 18 17 12 7 17 13 13 2 6 5 6 15 3 9 18 10 11 22 4 14 12 21 20 13 8 19 6 20 8 6 5 4 12 13 11 11 11 2 18 18 16 18 16 13 11 8 16 5 3 18 6 1 11 9 13 22 7 17 ...

output:


result:


Test #17:

score: 0
Time Limit Exceeded

input:

100000 23 29
1 11 20 18 16 13 10 18 21 15 20 19 6 12 6 21 22 2 17 19 20 15 15 19 13 7 1 7 6 3 17 7 2 21 8 11 8 6 8 6 22 20 23 2 2 11 11 14 23 19 1 6 2 2 10 13 10 15 16 19 16 19 15 11 14 1 14 21 4 13 2 15 6 21 18 6 6 5 18 15 18 4 12 22 16 12 23 18 9 18 20 19 3 20 23 15 20 9 8 23 12 17 1 10 22 23 15 6...

output:


result:


Test #18:

score: 0
Time Limit Exceeded

input:

100000 23 72
7 9 3 23 1 7 18 22 12 4 9 8 10 21 1 2 5 3 9 23 4 23 20 23 17 21 3 17 11 15 19 6 14 8 17 5 20 17 8 9 6 20 3 21 12 17 23 17 4 15 20 21 13 19 20 9 22 23 8 1 7 19 23 21 20 14 21 8 4 9 11 19 7 6 8 2 6 18 15 19 18 16 8 12 9 4 7 23 17 19 19 11 17 13 14 1 12 9 3 10 11 22 9 20 8 12 2 21 3 10 18 ...

output:


result:


Test #19:

score: 0
Time Limit Exceeded

input:

100000 23 81
6 20 5 18 20 5 22 7 10 1 22 5 9 1 1 8 22 18 13 5 16 19 10 19 21 10 14 17 6 8 12 22 2 14 6 2 7 8 8 9 20 22 1 23 5 12 12 3 6 7 16 5 17 10 8 12 1 12 18 4 17 3 12 1 7 23 1 23 23 12 15 3 10 4 10 1 2 17 6 10 1 10 6 1 7 18 16 22 12 22 9 19 6 18 7 20 10 16 2 20 1 21 7 6 13 6 15 8 15 14 8 5 23 1...

output:


result:


Test #20:

score: 0
Time Limit Exceeded

input:

100000 23 89
13 19 14 9 22 13 22 13 16 20 5 20 13 12 4 17 9 6 8 12 22 2 15 13 23 10 7 21 7 18 14 17 7 12 1 8 11 1 19 7 20 3 18 19 22 20 23 3 6 8 9 16 22 9 14 13 11 11 14 6 23 1 23 16 10 7 11 17 18 14 2 15 9 22 3 17 8 21 7 5 10 1 12 3 21 23 15 20 14 1 16 18 14 12 17 14 2 11 13 4 6 7 21 23 9 15 17 2 3...

output:


result: