Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9-yuyu0830 #36

Merged
merged 1 commit into from
May 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions yuyu0830/์ •๋ ฌ/23970.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <iostream>

#define fastio cin.tie(NULL); cin.sync_with_stdio(false);

using namespace std;

int arr[2][10001] = {0, };
int n, arrPtr = 0;

bool same() {
// start at 'arrPtr'
for (int i = arrPtr; i < n; i++) {
// if diff, terminate this function
if (arr[0][i] != arr[1][i]) return false;
// if same, then that index will same forever. no reason to compare again.
arrPtr++;
}
return true;
}

int main() {
fastio
cin >> n;
for (int i = 0; i < 2; i++)
for (int j = 0; j < n; j++)
cin >> arr[i][j];

int rnd = n - 1, ptr = 0;

// it can be same before sort
if (same()) {
printf("1\n");
return 0;
}

while (rnd) {
// sort [0] to [ptr - rnd]
int a = arr[0][ptr];
int b = arr[0][ptr + 1];

arr[0][ptr] = min(a, b);
arr[0][ptr + 1] = max(a, b);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swap์„ ์“ฐ๋ฉด ๋Œ€์†Œ ๊ด€๊ณ„๋งŒ ๋น„๊ตํ•ด์„œ ๋ฐ”๋กœ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Šด๋‹ˆ๋‹ค!


// if this index is last index in this round
if (++ptr == rnd) {
// next round
ptr = 0;
rnd--;
}

if (same()) {
// if arr is same
printf("1\n");
return 0;
}
}
printf("0\n");
}