結果
問題 | No.2740 Old Maid |
ユーザー | Shibaken_8128 |
提出日時 | 2024-04-20 10:52:16 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 425 ms / 2,000 ms |
コード長 | 3,888 bytes |
コンパイル時間 | 1,177 ms |
コンパイル使用メモリ | 125,064 KB |
実行使用メモリ | 23,460 KB |
最終ジャッジ日時 | 2024-04-20 10:52:29 |
合計ジャッジ時間 | 11,597 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 193 ms
22,656 KB |
testcase_01 | AC | 198 ms
22,784 KB |
testcase_02 | AC | 191 ms
22,784 KB |
testcase_03 | AC | 188 ms
22,912 KB |
testcase_04 | AC | 193 ms
22,784 KB |
testcase_05 | AC | 198 ms
22,784 KB |
testcase_06 | AC | 192 ms
22,784 KB |
testcase_07 | AC | 191 ms
22,784 KB |
testcase_08 | AC | 191 ms
22,784 KB |
testcase_09 | AC | 192 ms
22,656 KB |
testcase_10 | AC | 185 ms
22,784 KB |
testcase_11 | AC | 199 ms
22,784 KB |
testcase_12 | AC | 250 ms
17,788 KB |
testcase_13 | AC | 282 ms
19,100 KB |
testcase_14 | AC | 40 ms
6,944 KB |
testcase_15 | AC | 57 ms
7,936 KB |
testcase_16 | AC | 170 ms
14,336 KB |
testcase_17 | AC | 37 ms
6,940 KB |
testcase_18 | AC | 270 ms
18,512 KB |
testcase_19 | AC | 85 ms
9,728 KB |
testcase_20 | AC | 350 ms
20,736 KB |
testcase_21 | AC | 47 ms
7,168 KB |
testcase_22 | AC | 174 ms
14,008 KB |
testcase_23 | AC | 27 ms
6,940 KB |
testcase_24 | AC | 79 ms
9,344 KB |
testcase_25 | AC | 355 ms
21,652 KB |
testcase_26 | AC | 3 ms
6,940 KB |
testcase_27 | AC | 18 ms
6,944 KB |
testcase_28 | AC | 165 ms
14,396 KB |
testcase_29 | AC | 156 ms
13,696 KB |
testcase_30 | AC | 7 ms
6,944 KB |
testcase_31 | AC | 425 ms
23,460 KB |
testcase_32 | AC | 95 ms
10,368 KB |
testcase_33 | AC | 355 ms
22,492 KB |
testcase_34 | AC | 159 ms
13,696 KB |
testcase_35 | AC | 76 ms
9,216 KB |
testcase_36 | AC | 79 ms
9,600 KB |
testcase_37 | AC | 119 ms
12,160 KB |
testcase_38 | AC | 66 ms
8,656 KB |
testcase_39 | AC | 34 ms
6,940 KB |
testcase_40 | AC | 206 ms
16,152 KB |
testcase_41 | AC | 355 ms
20,528 KB |
testcase_42 | AC | 2 ms
6,940 KB |
testcase_43 | AC | 2 ms
6,940 KB |
testcase_44 | AC | 1 ms
6,940 KB |
testcase_45 | AC | 2 ms
6,940 KB |
testcase_46 | AC | 3 ms
6,940 KB |
testcase_47 | AC | 2 ms
6,940 KB |
testcase_48 | AC | 2 ms
6,944 KB |
testcase_49 | AC | 2 ms
6,940 KB |
testcase_50 | AC | 2 ms
6,944 KB |
testcase_51 | AC | 2 ms
6,944 KB |
testcase_52 | AC | 2 ms
6,944 KB |
testcase_53 | AC | 2 ms
6,944 KB |
testcase_54 | AC | 2 ms
6,944 KB |
testcase_55 | AC | 1 ms
6,940 KB |
testcase_56 | AC | 2 ms
6,940 KB |
testcase_57 | AC | 2 ms
6,944 KB |
testcase_58 | AC | 2 ms
6,940 KB |
testcase_59 | AC | 2 ms
6,940 KB |
testcase_60 | AC | 2 ms
6,940 KB |
testcase_61 | AC | 2 ms
6,940 KB |
testcase_62 | AC | 2 ms
6,944 KB |
testcase_63 | AC | 1 ms
6,944 KB |
testcase_64 | AC | 2 ms
6,940 KB |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:146:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 146 | auto [p,i] = *(rest.begin()); | ^ main.cpp:161:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 161 | auto [i2,p2] = *it; | ^
ソースコード
#include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <iomanip> #include <climits> #include <cmath> #include <functional> #include <numeric> #include <regex> #include <array> #include <fstream> #include <sstream> //#include<atcoder/modint> //using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define repl(i,l,r) for (int i = l; i < (int)(r); i++) #define all(a) a.begin(),a.end() #define Pii pair<int,int> #define Pll pair<long,long> #define INFi 1000000001 #define INFl 1000000000000000001 #define ll long long using namespace std; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> void printArray(vector<T>&A){ for(T&a:A){ cout<<a<<" "; } cout<<endl; } template<class T> void printArrayln(vector<T>&A){ for(T&a:A){ cout<<a<<endl; } } template<class T1,class T2> std::ostream &operator<<(std::ostream &out, const pair<T1,T2> &A){ cout<<"{"<<A.first<<","<<A.second<<"}"; return out; } template<class T1,class T2> std::ostream &operator<<(std::ostream &out, const map<T1,T2> &M){ for(const auto&A:M){ cout<<"{"<<A.first<<","<<A.second<<"}"; } return out; } template<class T1> std::ostream &operator<<(std::ostream &out, const set<T1> &M){ cout<<"{"; for(const auto&A:M){ cout<<A<<", "; } cout<<"}"<<endl; return out; } template<class T1> std::ostream &operator<<(std::ostream &out, const multiset<T1> &M){ cout<<"{"; for(const auto&A:M){ cout<<A<<", "; } cout<<"}"<<endl; return out; } template<class T> std::ostream &operator<<(std::ostream &out, const vector<T> &A){ for(const T &a:A){ cout<<a<<" "; } return out; } void print() { cout << endl; } template <typename Head, typename... Tail> void print(Head H, Tail... T) { cout << H << " "; print(T...); } template<class T> std::istream &operator>>(std::istream &in,vector<T>&A){ for(T&a:A){ std::cin>>a; } return in; } int main(void){ std::cin.tie(0)->sync_with_stdio(0); int N;cin>>N; vector<int> p(N); set<Pii> st; set<Pii> rest; rep(i,N){ cin>>p[i]; p[i]--; st.insert({i,p[i]}); rest.insert({p[i],i}); } vector<int> ans(0); while(!st.empty()){ auto [p,i] = *(rest.begin()); // 残っている数字の中で最小 // iより右に数字があるか auto it = st.upper_bound({i,p}); if(it == st.end()){ // iより右に数字がない // 2番目に小さい数字を探す auto it2 = rest.begin(); it2++; p = it2->first; i = it2->second; it = st.upper_bound({i,p}); } auto [i2,p2] = *it; ans.push_back(p); ans.push_back(p2); st.erase({i,p}); st.erase({i2,p2}); rest.erase({p,i}); rest.erase({p2,i2}); } rep(i,N){ cout<<ans[i]+1<<" "; } cout<<endl; }