题解:AT_arc177_e [ARC177E] Wrong Scoreboard
songhongyi · · 题解
简要题意:一场 ACM 赛事,五道题目,分数递增。现在给定每个人通过了哪些题,和期望排名
Part I: 在每题得分给定的情况下(其实是任意情况下),按照
只需要最大化
这样解决一个给定得分的复杂度为
Part II: 我们设
在这个基础上搜索,可以得到
Part III: 我们发现对于得分相同的人,可以通过钦定罚时的方式任意决定其顺序。因而,对于某两个得分方案
在 Part II 的基础上,删去冗余的方案,则只剩下
参考代码:
#include <algorithm>
#include <iostream>
using namespace std;
const int V[][ 5 ] = {
{ 1, 1, 1, 1, 1 }, // Edited
};
const int MAXN = 3e5 + 10;
bool f[ MAXN ][ 5 ];
int r[ MAXN ];
pair< int, int > v[ MAXN ];
int main()
{
cin.tie( 0 );
int T;
cin >> T;
while ( T-- )
{
int n;
cin >> n;
for ( int i = 1; i <= n; i++ )
{
for ( int j = 0; j < 5; j++ )
{
cin >> f[ i ][ j ];
}
}
for ( int i = 1; i <= n; i++ )
{
cin >> r[ i ];
}
long long int res = 1e18;
for ( int T = 0; T < 113; T++ )
{
for ( int i = 1; i <= n; i++ )
{
int s = 0;
for ( int j = 0; j < 5; j++ )
{
s += V[ T ][ j ] * f[ i ][ j ];
}
v[ i ] = { -s, r[ i ] };
}
sort( v + 1, v + n + 1 );
long long int s = 0;
for ( int i = 1; i <= n; i++ )
{
int d = i - v[ i ].second;
s += 1ll * d * d;
}
res = min( res, s );
}
cout << res << endl;
}
}