Submission #14068861


Source Code Expand

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/













int N, Q;
struct Node {
	Node(int v) : val(v), next(nullptr) {}
	Node* next;
	int val;
};
Node* containers[201010];
Node* topOfDesk[201010];
int ans[201010];
//---------------------------------------------------------------------------------------------------
void out() {
	rep(desk, 1, N + 1) {
		Node* cur = topOfDesk[desk];
		while (cur != nullptr) {
			ans[cur->val] = desk;
			cur = cur->next;
		}
	}
	rep(container, 1, N + 1) printf("%d\n", ans[container]);
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> Q;

	rep(i, 1, N + 1) topOfDesk[i] = containers[i] = new Node(i);
	rep(_, 0, Q) {
		int f, t, x; cin >> f >> t >> x;

		Node* nextTop = topOfDesk[f];
		topOfDesk[f] = containers[x]->next;
		containers[x]->next = topOfDesk[t];
		topOfDesk[t] = nextTop;
	}

	out();
}




Submission Info

Submission Time
Task K - Moving Containers
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 6
Code Size 2181 Byte
Status AC
Exec Time 109 ms
Memory 13896 KiB

Compile Error

./Main.cpp: In constructor ‘Node::Node(int)’:
./Main.cpp:38:6: warning: ‘Node::val’ will be initialized after [-Wreorder]
   38 |  int val;
      |      ^~~
./Main.cpp:37:8: warning:   ‘Node* Node::next’ [-Wreorder]
   37 |  Node* next;
      |        ^~~~
./Main.cpp:36:2: warning:   when initialized here [-Wreorder]
   36 |  Node(int v) : val(v), next(nullptr) {}
      |  ^~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 6 / 6
Status
AC × 2
AC × 20
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All hand2_01.txt, hand2_02.txt, hand_01.txt, hand_02.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, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
hand2_01.txt AC 109 ms 13896 KiB
hand2_02.txt AC 109 ms 13788 KiB
hand_01.txt AC 55 ms 8712 KiB
hand_02.txt AC 55 ms 8820 KiB
random_01.txt AC 28 ms 4948 KiB
random_02.txt AC 20 ms 3920 KiB
random_03.txt AC 29 ms 8292 KiB
random_04.txt AC 14 ms 4108 KiB
random_05.txt AC 16 ms 6716 KiB
random_06.txt AC 15 ms 3892 KiB
random_07.txt AC 30 ms 4964 KiB
random_08.txt AC 32 ms 5908 KiB
random_09.txt AC 31 ms 8420 KiB
random_10.txt AC 26 ms 5720 KiB
random_11.txt AC 99 ms 13664 KiB
random_12.txt AC 101 ms 13740 KiB
random_13.txt AC 41 ms 4248 KiB
random_14.txt AC 42 ms 4200 KiB
sample_01.txt AC 2 ms 3772 KiB
sample_02.txt AC 2 ms 3632 KiB