結果
| 問題 | 
                            No.1288 yuki collection
                             | 
                    
| コンテスト | |
| ユーザー | 
                             chocorusk
                         | 
                    
| 提出日時 | 2021-02-21 00:32:55 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 3,861 ms / 5,000 ms | 
| コード長 | 1,316 bytes | 
| コンパイル時間 | 3,999 ms | 
| コンパイル使用メモリ | 197,904 KB | 
| 最終ジャッジ日時 | 2025-01-19 02:50:51 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 40 | 
ソースコード
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
int n;
string str;
ll v[3030];
int main()
{
    cin>>n;
    cin>>str;
    for(int i=0; i<n; i++) cin>>v[i];
	int s=2*n, t=2*n+1;
    mcf_graph<ll, ll> g(2*n+2);
    const ll INF=1e9+7;
    for(int i=0; i<n; i++){
        if(str[i]=='y') g.add_edge(s, 2*i, 1, 0);
        g.add_edge(2*i, 2*i+1, 1, INF-v[i]);
        if(str[i]=='i') g.add_edge(2*i+1, t, 1, 0);
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<i; j++){
            if((str[j]=='y' && str[i]=='u') || (str[j]=='u' && str[i]=='k') || (str[j]=='k' && str[i]=='i')){
                g.add_edge(2*j+1, 2*i, 1, 0);
            }
        }
    }
    g.add_edge(s, t, n/4, INF*4);
    cout<<INF*(n/4)*4-g.flow(s, t, n/4).second<<endl;
    return 0;
}
            
            
            
        
            
chocorusk