Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
It's easy to see that for every word, the minimum cost of sending it is the minimum cost of sending any word in its group. For each group, we'll maintain the minimum cost for sending a word in it (let it be costi) and for each word, we'll maintain its group (let it be groupi). For every word i in the message, we'll add costgroupi to the answer. Time complexity O((n + m)log(n) * len). #include
#include
using namespace std; map
d; int arr[100005],cost[100005],group[100005]; int main() { int n,k,m; cin >> n >> k >> m; for (int i=1;i<=n;i++) { string s; cin >> s; d[s]=i; } for (int i=1;i<=n;i++) { cin >> arr[i]; cost[i]=(1<<30); } for (int i=1;i<=k;i++) { int x; cin >> x; while (x--) { int a; cin >> a; group[a]=i; cost[i]=min(cost[i],arr[a]); } } long long ans=0; while (m--) { string s; cin >> s; ans+=cost[group[d[s]]]; } cout << ans; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)