結果
| 問題 | No.3561 Collect KCPC |
| コンテスト | |
| ユーザー |
Taiki0715
|
| 提出日時 | 2026-06-09 16:09:05 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 7,539 bytes |
| 記録 | |
| コンパイル時間 | 2,743 ms |
| コンパイル使用メモリ | 354,820 KB |
| 実行使用メモリ | 28,964 KB |
| 最終ジャッジ日時 | 2026-06-09 16:09:17 |
| 合計ジャッジ時間 | 11,058 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge2_1 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| 部分点1 | 10 % | AC * 9 WA * 6 |
| 部分点2 | 20 % | AC * 8 WA * 7 |
| 部分点3 | 20 % | AC * 13 |
| 部分点4 | 50 % | AC * 30 WA * 21 |
| 合計 | 20 点 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using P=pair<ll,ll>;
template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>;
template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);}
template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);}
template<typename T1,typename T2>istream &operator>>(istream &is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T1,typename T2,typename T3>istream &operator>>(istream &is,tuple<T1,T2,T3>&a){is>>std::get<0>(a)>>std::get<1>(a)>>std::get<2>(a);return is;}
template<typename T,size_t n>istream &operator>>(istream &is,array<T,n>&a){for(auto&i:a)is>>i;return is;}
template<typename T>istream &operator>>(istream &is,vector<T> &a){for(auto &i:a)is>>i;return is;}
template<typename T1,typename T2>void operator++(pair<T1,T2>&a,int n){a.first++,a.second++;}
template<typename T1,typename T2>void operator--(pair<T1,T2>&a,int n){a.first--,a.second--;}
template<typename T>void operator++(vector<T>&a,int n){for(auto &i:a)i++;}
template<typename T>void operator--(vector<T>&a,int n){for(auto &i:a)i--;}
#define overload3(_1,_2,_3,name,...) name
#define rep1(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define rep(...) overload3(__VA_ARGS__,rep2,rep1)(__VA_ARGS__)
#define reps(i,l,r) rep2(i,l,r)
#define all(x) x.begin(),x.end()
#define pcnt(x) __builtin_popcountll(x)
#define fin(x) return cout<<(x)<<'\n',static_cast<void>(0)
#define yn(x) cout<<((x)?"Yes\n":"No\n")
#define uniq(x) sort(all(x)),x.erase(unique(all(x)),x.end())
template<typename T>
inline int fkey(vector<T>&z,T key){return lower_bound(z.begin(),z.end(),key)-z.begin();}
ll myceil(ll a,ll b){return (a+b-1)/b;}
template<typename T,size_t n,size_t id=0>
auto vec(const int (&d)[n],const T &init=T()){
if constexpr (id<n)return vector(d[id],vec<T,n,id+1>(d,init));
else return init;
}
#ifdef LOCAL
#include<debug.h>
#define SWITCH(a,b) (a)
#else
#define debug(...) static_cast<void>(0)
#define debugg(...) static_cast<void>(0)
#define SWITCH(a,b) (b)
template<typename T1,typename T2>ostream &operator<<(ostream &os,const pair<T1,T2>&p){os<<p.first<<' '<<p.second;return os;}
#endif
struct Timer{
clock_t start;
Timer(){
start=clock();
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout<<fixed<<setprecision(16);
}
inline double now(){return (double)(clock()-start)/1000;}
#ifdef LOCAL
~Timer(){
cerr<<"time:";
cerr<<now();
cerr<<"ms\n";
}
#endif
}timer;
void SOLVE();
int main(){
int testcase=1;
//cin>>testcase;
for(int i=0;i<testcase;i++){
SOLVE();
}
}
template<typename T=int>
struct Edge{
int from,to;
T weight;
int index;
Edge(int from_,int to_,T weight_=T(),int index_=-1):from(from_),to(to_),weight(weight_),index(index_){}
Edge():from(-1),to(-1),weight(),index(-1){}
friend std::ostream &operator<<(std::ostream &os,const Edge&e){
os<<'[';
os<<"from:"<<e.from;
os<<"to:"<<e.to;
os<<"weight:"<<e.weight;
os<<"index:"<<e.index;
os<<']';
return os;
}
};
template<typename T=int>
struct Graph{
private:
int n;
std::vector<Edge<T>>edge;
std::vector<Edge<T>>g;
std::vector<int>ptr;
bool directed;
struct graph_range{
using iterator=typename std::vector<Edge<T>>::iterator;
iterator l,r;
iterator begin()const{return l;}
iterator end()const{return r;}
int size()const{return r-l;}
Edge<T> &operator[](int i)const{return l[i];}
};
struct const_graph_range{
using iterator=typename std::vector<Edge<T>>::const_iterator;
iterator l,r;
iterator begin()const{return l;}
iterator end()const{return r;}
int size()const{return r-l;}
const Edge<T> &operator[](int i)const{return l[i];}
};
public:
Graph(int n_,bool dir_):n(n_),directed(dir_){}
Graph():n(0){}
Graph(int n_,bool dir_,const std::vector<Edge<T>>&e):n(n_),directed(dir_),edge(e){build();}
template<bool weighted=false,bool index=1>
void read(int m){
edge.reserve(m);
for(int i=0;i<m;i++){
int u,v;
std::cin>>u>>v;
T w;
if constexpr(index)u--,v--;
if constexpr(weighted)std::cin>>w;
else w=1;
edge.emplace_back(u,v,w,i);
}
build();
}
void add_edge(int u,int v){
assert(0<=u&&u<n);
assert(0<=v&&v<n);
int id=edge.size();
edge.emplace_back(u,v,1,id);
}
void add_edge(int u,int v,T w){
assert(0<=u&&u<n);
assert(0<=v&&v<n);
int id=edge.size();
edge.emplace_back(u,v,w,id);
}
void add_edge(int u,int v,T w,int index){
assert(0<=u&&u<n);
assert(0<=v&&v<n);
edge.emplace_back(u,v,w,index);
}
void add_edge(Edge<T>e){
edge.emplace_back(e);
}
void build(){
std::vector<int>cnt(n+1,0);
for(const Edge<T>&e:edge){
cnt[e.from+1]++;
if(!directed)cnt[e.to+1]++;
}
for(int i=1;i<=n;i++)cnt[i]+=cnt[i-1];
ptr=cnt;
g.resize(cnt[n]);
for(const Edge<T>&e:edge){
g[cnt[e.from]++]=e;
if(!directed)g[cnt[e.to]++]=Edge<T>(e.to,e.from,e.weight,e.index);
}
}
void reverse(){
if(directed){
for(Edge<T>&e:edge)std::swap(e.from,e.to);
build();
}
}
inline void to_directed(){
directed=true;
build();
}
inline void to_undirected(){
directed=false;
build();
}
void reserve(int m){edge.reserve(m);}
graph_range operator[](int i){return graph_range{g.begin()+ptr[i],g.begin()+ptr[i+1]};}
const_graph_range operator[](int i)const{return const_graph_range{g.begin()+ptr[i],g.begin()+ptr[i+1]};}
const Edge<T>& get_edge(int i)const{return edge[i];}
std::vector<Edge<T>>get_edges()const{return edge;}
inline bool is_directed()const{return directed;}
inline int size()const{return n;}
inline int edge_size()const{return edge.size();}
typename std::vector<Edge<T>>::iterator begin(){return edge.begin();}
typename std::vector<Edge<T>>::iterator end(){return edge.end();}
typename std::vector<Edge<T>>::const_iterator begin()const{return edge.begin();}
typename std::vector<Edge<T>>::const_iterator end()const{return edge.end();}
};
//min
template<typename T>
struct Top2{
int key1,key2;
T top1,top2;
Top2():key1(std::numeric_limits<int>::min()),key2(std::numeric_limits<int>::min()),top1(std::numeric_limits<T>::max()),top2(std::numeric_limits<T>::max()){}
bool set(int k,T v){
if(k==key1){
if(top1>v){
top1=v;
return true;
}
}
else if(top1>v){
key2=key1;
top2=top1;
key1=k;
top1=v;
return true;
}
else if(top2>v){
key2=k;
top2=v;
return true;
}
return false;
}
T neq_min(int k)const{return k!=key1?top1:top2;}
bool contains(int k,T v)const{return (k==key1&&v==top1)||(k==key2&&v==top2);}
};
void SOLVE(){
int n,m;
cin>>n>>m;
Graph<ll>g(n,true);
g.read<1,1>(m);
string s;
cin>>s;
string t="KCPC";
vector<vector<Top2<ll>>>dst(5,vector<Top2<ll>>(n));
minque<tuple<ll,int,int,int>>que;
auto yaru=[&](int i,int j,int c,ll d)->void {
if(dst[i][j].set(c,d)){
que.emplace(d,c,i,j);
}
};
yaru(0,0,-1,0);
while(!que.empty()){
auto [d,c,i,j]=que.top();que.pop();
if(i==5)break;
if(!dst[i][j].contains(c,d))continue;
if(s[j]==t[i]){
if(i==2)yaru(i+1,j,j,d);
else if(c!=j)yaru(i+1,j,c,d);
}
for(auto e:g[j])yaru(i,e.to,c,d+e.weight);
}
ll ans=1e18;
rep(i,n)chmin(ans,dst[4][i].top1);
if(ans==1e18)ans=-1;
cout<<ans<<endl;
}
Taiki0715