結果

問題 No.762 PDCAパス
ユーザー gazellegazelle
提出日時 2018-12-10 00:55:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,470 bytes
コンパイル時間 1,174 ms
コンパイル使用メモリ 127,168 KB
実行使用メモリ 6,512 KB
最終ジャッジ日時 2023-10-14 22:00:42
合計ジャッジ時間 3,383 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,356 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,352 KB
testcase_22 AC 17 ms
4,648 KB
testcase_23 AC 18 ms
4,852 KB
testcase_24 AC 21 ms
5,932 KB
testcase_25 AC 21 ms
5,936 KB
testcase_26 AC 17 ms
4,592 KB
testcase_27 AC 17 ms
4,664 KB
testcase_28 AC 27 ms
6,456 KB
testcase_29 AC 28 ms
6,512 KB
testcase_30 AC 26 ms
5,988 KB
testcase_31 AC 27 ms
5,984 KB
testcase_32 AC 26 ms
5,924 KB
testcase_33 AC 25 ms
5,400 KB
testcase_34 AC 26 ms
5,456 KB
testcase_35 AC 26 ms
5,460 KB
testcase_36 AC 22 ms
4,896 KB
testcase_37 AC 22 ms
4,864 KB
testcase_38 AC 22 ms
5,108 KB
testcase_39 AC 22 ms
4,868 KB
testcase_40 AC 22 ms
4,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

/* --------------------------------------- */

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	vector<P> edge(m);
	vector<ll> cntp(n, 0);
	vector<ll> cnta(n, 0);
	REP(i, m) {
		ll u, v;
		cin >> u >> v;
		u--; v--;
		edge[i] = P(u, v);
		if(s[u] == 'P') cntp[v]++;
		if(s[u] == 'A') cnta[v]++;
		if(s[v] == 'P') cntp[u]++;
		if(s[v] == 'A') cnta[u]++;
	}
	ll ans = 0;
	REP(i, m) {
		if(s[edge[i].first] == 'D' && s[edge[i].second] == 'C') {
			ans += cntp[edge[i].first] * cnta[edge[i].second];
			ans %= MOD;
		}
		if(s[edge[i].first] == 'C' && s[edge[i].second] == 'D') {
			ans += cnta[edge[i].first] * cntp[edge[i].second];
			ans %= MOD;
		}
	}
	cout << ans << endl;
	return 0;
}

/* --------------------------------------- */

0