結果

問題 No.2740 Old Maid
ユーザー iroha HEFFERNANiroha HEFFERNAN
提出日時 2024-04-21 12:37:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 484 ms / 2,000 ms
コード長 3,847 bytes
コンパイル時間 2,518 ms
コンパイル使用メモリ 210,536 KB
実行使用メモリ 33,076 KB
最終ジャッジ日時 2024-04-21 12:37:55
合計ジャッジ時間 15,749 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 282 ms
31,488 KB
testcase_01 AC 268 ms
31,360 KB
testcase_02 AC 267 ms
31,232 KB
testcase_03 AC 269 ms
31,488 KB
testcase_04 AC 281 ms
31,232 KB
testcase_05 AC 269 ms
31,488 KB
testcase_06 AC 272 ms
31,488 KB
testcase_07 AC 269 ms
31,360 KB
testcase_08 AC 269 ms
31,360 KB
testcase_09 AC 272 ms
31,232 KB
testcase_10 AC 261 ms
31,360 KB
testcase_11 AC 272 ms
31,360 KB
testcase_12 AC 314 ms
24,956 KB
testcase_13 AC 347 ms
26,556 KB
testcase_14 AC 52 ms
8,064 KB
testcase_15 AC 77 ms
10,112 KB
testcase_16 AC 230 ms
19,616 KB
testcase_17 AC 49 ms
7,936 KB
testcase_18 AC 328 ms
25,576 KB
testcase_19 AC 110 ms
12,416 KB
testcase_20 AC 404 ms
29,084 KB
testcase_21 AC 60 ms
8,960 KB
testcase_22 AC 249 ms
19,244 KB
testcase_23 AC 36 ms
6,656 KB
testcase_24 AC 103 ms
11,904 KB
testcase_25 AC 440 ms
30,392 KB
testcase_26 AC 5 ms
5,376 KB
testcase_27 AC 24 ms
5,888 KB
testcase_28 AC 225 ms
19,472 KB
testcase_29 AC 245 ms
18,824 KB
testcase_30 AC 9 ms
5,376 KB
testcase_31 AC 484 ms
33,076 KB
testcase_32 AC 125 ms
13,920 KB
testcase_33 AC 463 ms
31,556 KB
testcase_34 AC 204 ms
18,500 KB
testcase_35 AC 131 ms
11,904 KB
testcase_36 AC 112 ms
12,416 KB
testcase_37 AC 167 ms
16,116 KB
testcase_38 AC 88 ms
11,136 KB
testcase_39 AC 44 ms
7,680 KB
testcase_40 AC 281 ms
22,200 KB
testcase_41 AC 394 ms
28,788 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 2 ms
5,376 KB
testcase_52 AC 2 ms
5,376 KB
testcase_53 AC 2 ms
5,376 KB
testcase_54 AC 2 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
testcase_56 AC 2 ms
5,376 KB
testcase_57 AC 2 ms
5,376 KB
testcase_58 AC 2 ms
5,376 KB
testcase_59 AC 2 ms
5,376 KB
testcase_60 AC 2 ms
5,376 KB
testcase_61 AC 2 ms
5,376 KB
testcase_62 AC 2 ms
5,376 KB
testcase_63 AC 2 ms
5,376 KB
testcase_64 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*______
   ||       |
   ||ACはこちらへ|
   ||       |
   || ̄ ̄ ̄ ̄ ̄ ̄ 
∧_∧||
(`・ω・||
( つ||0
 uーu*/
#include <bits/stdc++.h>
using namespace std;
//output and debug
template <class T> using V = vector<T>;
template <class T, class U> 
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}
template <class T> ostream& operator<<(ostream& os,const V<T>& v) {
    os << "[";
    bool f = false;
    for (auto d : v) {
        if (f) os << ", ";
        f = true;
        os << d;
    }
    return os << "]";
}
template <class T> ostream& operator<<(ostream& os,const set<T>& s) {
    os << "{";
    bool f = false;
    for (auto d : s) {
        if (f) os << ", ";
        f = true;
        os << d;
    }
    return os << "}";
}
template <class T> ostream& operator<<(ostream& os, const multiset<T>& s) {
    os << "{";
    bool f = false;
    for (auto d : s) {
        if (f) os << ", ";
        f = true;
        os << d;
    }
    return os << "}";
}
template <class T, class U>
ostream& operator<<(ostream& os, const map<T, U>& s) {
    os << "{";
    bool f = false;
    for (auto p : s) {
        if (f) os << ", ";
        f = true;
        os << p.first << ": " << p.second;
    }
    return os << "}";
}
template<class T, class... Ts>
void o(const T& a, const Ts&... b){
    cout << a;
    (cout << ... << (cout << ' ', b));
    cout << '\n';
}
#ifdef LOCAL
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        o(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif
// input
template<class... T>
void in(T&... a){
    (cin >> ... >> a);
}
template<class T> void in(vector<T>& a){ for(auto&& i : a) in(i); }
template<class T, class L> void in(pair<T, L>& p){ in(p.first); in(p.second); }
template<class T> void in(T& a){ cin >> a; }

#define rep1(n)          for(ll i = 0; i < n; ++i)
#define rep2(i, n)       for(ll i = 0; i < n; ++i)
#define rep3(i, j, n)    for(ll i = j; i < n; ++i)
#define overload3(a, b, c,  e, ...) e
#define rep(...) overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(i,n) for(ll i = n-1;i>=0;--i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using ll = long long ;
using ld = long double;
using pa = pair<ll,ll>;
using t2 = tuple<ll,ll>;
using tu = tuple<ll,ll,ll>;
using vi = vector<ll>;
using vs = vector<string>;
using vp = vector<pa>;
using vvi = vector<vi>;
using vvp = vector<vp>;
using vvvi = vector<vvi>;
using v4 = vector<vvvi>;
using vt = vector<tu>;
const ll INF = (1ll << 29);
const ll inf = INF*INF;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};
void Yes(bool i = true){ return o(i?"Yes":"No"); }

//reversed priority_queue
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
const ll mod = 998244353;
//const ll mod = 1000000007;


int main(){
    ll n;
    in(n);
    vi a(n),ed(n),ans;
	in(a);
	map<ll,ll> id;
	set<pa> b;
	rep(i,n){
		--a[i];
		id[a[i]] = i;
		b.emplace(i,a[i]);
	}
	rep(i,n/2){
		auto nit = id.begin();
		ll x = (*nit).first,xid = (*nit).second;
		auto it = b.upper_bound(pa(xid,x));
		if(it == b.end()){
			++nit;
			x = (*nit).first;
			xid = (*nit).second;
			it = b.upper_bound(pa(xid,x));
		}
		ll y = (*it).second,yid = (*it).first;
		ans.push_back(x);
		ans.push_back(y);
		id.erase(id.find(x));
		id.erase(id.find(y));
		b.erase(pa(xid,x));
		b.erase(pa(yid,y));
	}
	rep(i,n) {
		ans[i] += 1;
	}
	rep(i,n){
		cout << ans[i];
		if(i != n-1) cout << " ";
	}
	cout << endl;
}
0