前提
Atcoder ABC278 C問題をC++で解いています。
https://atcoder.jp/contests/abc278/tasks/abc278_c
実現したいこと
sample問題をローカルの環境でg++ C.cpp -o out -std=gnu++17でコンパイルし,
実行したところうまくいっているように見えたのですが,
提出したところ全問REとなってしまいました。
原因が全くわからないため質問させてください。
自分のコードのどこが間違っているかご教示お願いいたします。
発生している問題・エラーメッセージ
全問実行時エラー
該当のソースコード
C++
1#include <iostream> 2#include <string> 3#include <cmath> 4#include <vector> 5#include <algorithm> 6 7using namespace std; 8using ll=long long; 9 10 11 12int main(void){ 13 14 ll N,Q; 15 cin >> N >> Q; 16 vector<vector<long long int> > follow(N+1); 17 18 for(ll i=0;i<Q;i++){ 19 int T; 20 ll A,B; 21 22 cin >> T >> A >> B; 23 24 if(T == 1){ 25 if(find(follow[A].begin(), follow[A].end(), B) == follow[A].end()){ 26 follow[A].push_back(B); 27 } 28 }else if(T == 2){ 29 auto itr = find(follow[A].begin(), follow[A].end(), B); 30 if(itr != follow[A].end()){ 31 follow[A].erase(itr); 32 } 33 }else{ 34 if(find(follow[A].begin(), follow[A].end(), B) != follow[A].end() && find(follow[B].begin(), follow[B].end(), A) != follow[B].end()){ 35 cout << "Yes" << endl; 36 }else{ 37 cout << "No" << endl; 38 } 39 } 40 } 41 42 return 0; 43}
試したこと
vectorを定義する際の添字をN→N+1に変更した結果,REが半分減りました
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー