QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#279709#7052. Xian Xiangbachbeo2007AC ✓786ms5692kbC++233.5kb2023-12-08 23:28:522023-12-08 23:28:52

Judging History

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

  • [2023-12-08 23:28:52]
  • 评测
  • 测评结果:AC
  • 用时:786ms
  • 内存:5692kb
  • [2023-12-08 23:28:52]
  • 提交

answer

// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int mod2=1e9+7;
const int maxn=20;
const int maxq=500005;
const int maxl=20;
const int maxa=1000005;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
int n,m,k,s[maxn],cnt,num[maxn][maxn],mk[maxn][maxn][2],dist[maxn][maxn],dp[(1<<18)+5];
pii pos[maxn];
string ss[maxn][maxn];

void solve(){
    cin >> n >> m >> k;
    string check;cnt=0;
    for(int i=1;i<=k;i++) check.push_back('-');
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin >> ss[i][j];
            if(ss[i][j]!=check){num[i][j]=cnt;pos[cnt++]={i,j};}
            else num[i][j]=-1;
        }
    }
    for(int i=0;i<=k;i++) cin >> s[i];
    for(int i=0;i<cnt;i++){
        for(int j=i+1;j<cnt;j++){
            int dif=0;
            for(int p=0;p<k;p++){
                if(ss[pos[i].first][pos[i].second][p]==ss[pos[j].first][pos[j].second][p]) dif++;
            }
            dist[i][j]=s[dif];
            mk[i][j][0]=mk[i][j][1]=0;
            for(int p=pos[i].first+1;p<pos[j].first;p++){
                if(num[p][pos[i].second]!=-1) mk[i][j][0]^=(1<<num[p][pos[i].second]);
            }
            for(int p=pos[i].first;p<pos[j].first;p++){
                if(num[p][pos[j].second]!=-1) mk[i][j][1]^=(1<<num[p][pos[j].second]);
            }
            if(pos[i].second>pos[j].second){
                for(int p=pos[i].second;p>pos[j].second;p--){
                    if(num[pos[j].first][p]!=-1) mk[i][j][0]^=(1<<num[pos[j].first][p]);
                }
                for(int p=pos[i].second-1;p>pos[j].second;p--){
                    if(num[pos[i].first][p]!=-1) mk[i][j][1]^=(1<<num[pos[i].first][p]);
                }
            }
            else{
                for(int p=pos[i].second;p<pos[j].second;p++){
                    if(num[pos[j].first][p]!=-1) mk[i][j][0]^=(1<<num[pos[j].first][p]);
                }
                for(int p=pos[i].second+1;p<pos[j].second;p++){
                    if(num[pos[i].first][p]!=-1) mk[i][j][1]^=(1<<num[pos[i].first][p]);
                }
            }
        }
    }
    dp[0]=0;
    for(int mask=1;mask<(1<<cnt);mask++){
        dp[mask]=0;
        for(int i=0;i<cnt;i++){
            if(((mask>>i)&1)==0) continue;
            for(int j=i+1;j<cnt;j++){
                if(((mask>>j)&1)==0) continue;
                if((mask&mk[i][j][0]) && (mask&mk[i][j][1])) continue;
                dp[mask]=max(dp[mask],dp[mask^(1<<i)^(1<<j)]+dist[i][j]);
            }
        }
    }
    cout << dp[(1<<cnt)-1] << '\n';
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;cin >> test;
    while(test--) solve();
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3752kb

input:

3
2 2 3
aaa aaa
bbb bbb
1 10 100 1000
2 3 3
aaa --- bbb
bbb --- aaa
1 10 100 1000
1 4 3
aaa bba abb aaa
1 10 100 1000

output:

2000
2
1010

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 786ms
memory: 5692kb

input:

20
5 6 5
dbdaa cbcdc ----- dadad dbdaa bdbcc
dbbdc aadcc dbbdc bdbad ----- -----
bccad abdab ----- bbdda ----- ddcbd
adcbb ----- ----- ----- bdbcc -----
----- ----- bbdda ----- ----- -----
156 1333 2713 2853 3242 9881
6 7 4
---- acaa ---- ---- ---- ---- ----
accc accc dcda ---- cbcb bbda ----
bbda d...

output:

49276
65059
38746
34398
39744
73820
31466
33302
43342
26102
45570
69039
61574
63160
66552
57157
69615
76688
79535
34563

result:

ok 20 lines