Submission #28871835


Source Code Expand

#include<bits/stdc++.h>

using namespace std;

#define fr(i, n) for(int i = 0; i < n; i++)
#define frr(i, n) for(int i = 1; i <= n; i++)
#define frm(i, n) for(int i = (int)n-1; i >= 0; i--)

#define pb push_back
#define f first
#define s second

typedef long long ll;
typedef pair<int,int> pii;

#define mem(v, k) memset(v, k, sizeof(v));
#define db cout << "Debug" << endl;
#define all(x) begin(x), end(x)
#define dbg(x)  cout << #x << " = " << x << endl
#define dbgv(v)  cout << #v << " = "; for(auto x : v) cout << x << " "; cout << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define random mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define myrand(a, b) uniform_int_distribution<int>(a, b)(rng)
#define ioFile freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);

#define mp make_pair
#define pq priority_queue

#define MAXN 100010
#define MOD 1000000007
#define INF 2000000000000000100

pii v[MAXN];
int n;

vector<int> ans;
multiset<int> m;

signed main(){
	fastio;
	cin >> n;
	fr(i, n) cin >> v[i].f, m.insert(v[i].f);
	fr(i, n) cin >> v[i].s;

	int primeiro_baixo = MOD;
	int primeiro_baixo_diferente = 0;

	int l = 0;
	while(l < n){
		int cur_minimo = *(m.begin());

		if(cur_minimo > primeiro_baixo) break;
		else if(cur_minimo == primeiro_baixo){
			if(cur_minimo > primeiro_baixo_diferente){
				break;
			}
		}


		vector<pii> cur_baixo;
		while(m.size() && *(m.begin()) == cur_minimo){
			if(v[l].f == cur_minimo){
				cur_baixo.pb({v[l].s, l});
			}
			m.erase(m.find(v[l].f));
			l++;
		}

		if(primeiro_baixo == MOD){
			int menor_baixo = MOD, ind = 0;
			for(auto x : cur_baixo) {
				if(menor_baixo > x.f){
					menor_baixo = x.f;
					ind = x.s;
				}
			}

			if(menor_baixo <= cur_minimo){
				ans.pb(ind);
				break;
			}

			primeiro_baixo = cur_baixo[0].f;

			for(auto x : cur_baixo){
				ans.pb(x.s);
				if(x.f != primeiro_baixo && primeiro_baixo_diferente == 0)
					primeiro_baixo_diferente = x.f; 
			}
		}
		else{
			for(auto x : cur_baixo){
				ans.pb(x.s);
				if(x.f != primeiro_baixo && primeiro_baixo_diferente == 0)
					primeiro_baixo_diferente = x.f; 
			}
		}
	}

	for(auto x : ans) cout << v[x].f << " ";
	for(auto x : ans) cout << v[x].s << " ";
	cout << endl;
}

Submission Info

Submission Time
Task D - Concatenate Subsequences
User lucas3h
Language C++ (GCC 9.2.1)
Score 600
Code Size 2391 Byte
Status AC
Exec Time 81 ms
Memory 9128 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 95
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, random2_01.txt, random2_02.txt, random2_03.txt, random2_04.txt, random2_05.txt, random2_06.txt, random2_07.txt, random2_08.txt, random2_09.txt, random2_10.txt, random2_11.txt, random2_12.txt, random2_13.txt, random2_14.txt, random2_15.txt, random2_16.txt, random2_17.txt, random2_18.txt, random2_19.txt, random2_20.txt, random3_01.txt, random3_02.txt, random3_03.txt, random3_04.txt, random3_05.txt, random3_06.txt, random3_07.txt, random3_08.txt, random3_09.txt, random3_10.txt, random3_11.txt, random3_12.txt, random3_13.txt, random3_14.txt, random3_15.txt, random3_16.txt, random3_17.txt, random3_18.txt, random3_19.txt, random3_20.txt, random4_01.txt, random4_02.txt, random4_03.txt, random4_04.txt, random4_05.txt, random4_06.txt, random4_07.txt, random4_08.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt AC 8 ms 3472 KiB
hand_02.txt AC 62 ms 9044 KiB
hand_03.txt AC 81 ms 9048 KiB
hand_04.txt AC 76 ms 8972 KiB
hand_05.txt AC 62 ms 8916 KiB
hand_06.txt AC 69 ms 8976 KiB
hand_07.txt AC 49 ms 8980 KiB
hand_08.txt AC 50 ms 9040 KiB
hand_09.txt AC 48 ms 8920 KiB
hand_10.txt AC 46 ms 8964 KiB
hand_11.txt AC 60 ms 9044 KiB
hand_12.txt AC 61 ms 9048 KiB
hand_13.txt AC 61 ms 9128 KiB
hand_14.txt AC 65 ms 9048 KiB
random2_01.txt AC 64 ms 8972 KiB
random2_02.txt AC 65 ms 8920 KiB
random2_03.txt AC 64 ms 8968 KiB
random2_04.txt AC 76 ms 8976 KiB
random2_05.txt AC 77 ms 9080 KiB
random2_06.txt AC 68 ms 9124 KiB
random2_07.txt AC 62 ms 8972 KiB
random2_08.txt AC 59 ms 8920 KiB
random2_09.txt AC 65 ms 9048 KiB
random2_10.txt AC 68 ms 9044 KiB
random2_11.txt AC 4 ms 3552 KiB
random2_12.txt AC 2 ms 3576 KiB
random2_13.txt AC 2 ms 3604 KiB
random2_14.txt AC 2 ms 3608 KiB
random2_15.txt AC 2 ms 3440 KiB
random2_16.txt AC 47 ms 7484 KiB
random2_17.txt AC 66 ms 8456 KiB
random2_18.txt AC 34 ms 5728 KiB
random2_19.txt AC 59 ms 8308 KiB
random2_20.txt AC 11 ms 3852 KiB
random3_01.txt AC 64 ms 8968 KiB
random3_02.txt AC 63 ms 9088 KiB
random3_03.txt AC 63 ms 9080 KiB
random3_04.txt AC 72 ms 8972 KiB
random3_05.txt AC 75 ms 9048 KiB
random3_06.txt AC 68 ms 8964 KiB
random3_07.txt AC 61 ms 9088 KiB
random3_08.txt AC 58 ms 8972 KiB
random3_09.txt AC 62 ms 8968 KiB
random3_10.txt AC 67 ms 9052 KiB
random3_11.txt AC 6 ms 3640 KiB
random3_12.txt AC 2 ms 3560 KiB
random3_13.txt AC 2 ms 3596 KiB
random3_14.txt AC 2 ms 3548 KiB
random3_15.txt AC 2 ms 3500 KiB
random3_16.txt AC 50 ms 7596 KiB
random3_17.txt AC 66 ms 8528 KiB
random3_18.txt AC 34 ms 5612 KiB
random3_19.txt AC 58 ms 8428 KiB
random3_20.txt AC 10 ms 3956 KiB
random4_01.txt AC 75 ms 9044 KiB
random4_02.txt AC 73 ms 9032 KiB
random4_03.txt AC 2 ms 3596 KiB
random4_04.txt AC 2 ms 3496 KiB
random4_05.txt AC 42 ms 6632 KiB
random4_06.txt AC 8 ms 3920 KiB
random4_07.txt AC 23 ms 4800 KiB
random4_08.txt AC 34 ms 5784 KiB
random_01.txt AC 62 ms 9080 KiB
random_02.txt AC 62 ms 9080 KiB
random_03.txt AC 61 ms 9028 KiB
random_04.txt AC 69 ms 9052 KiB
random_05.txt AC 76 ms 9092 KiB
random_06.txt AC 65 ms 8912 KiB
random_07.txt AC 60 ms 8916 KiB
random_08.txt AC 57 ms 8980 KiB
random_09.txt AC 62 ms 9128 KiB
random_10.txt AC 66 ms 8980 KiB
random_11.txt AC 6 ms 3600 KiB
random_12.txt AC 2 ms 3652 KiB
random_13.txt AC 3 ms 3496 KiB
random_14.txt AC 2 ms 3600 KiB
random_15.txt AC 2 ms 3492 KiB
random_16.txt AC 51 ms 7540 KiB
random_17.txt AC 65 ms 8384 KiB
random_18.txt AC 32 ms 5744 KiB
random_19.txt AC 58 ms 8360 KiB
random_20.txt AC 11 ms 3848 KiB
random_21.txt AC 23 ms 4832 KiB
random_22.txt AC 10 ms 3896 KiB
random_23.txt AC 20 ms 4848 KiB
random_24.txt AC 34 ms 5632 KiB
random_25.txt AC 26 ms 4860 KiB
random_26.txt AC 33 ms 5768 KiB
random_27.txt AC 21 ms 4892 KiB
random_28.txt AC 60 ms 7632 KiB
random_29.txt AC 64 ms 8592 KiB
random_30.txt AC 54 ms 7644 KiB
sample_01.txt AC 2 ms 3564 KiB
sample_02.txt AC 2 ms 3496 KiB
sample_03.txt AC 3 ms 3604 KiB