• Kimcoding's Dev Note!
    • About
    • Posts
    • Categories
    • Tags
    • Projects

    Ozon Tech Challenge 2020 (Div. 1 + Div. 2)

    by Kimcoding on 2020-03-05 08:26

    in Codeforces


    헤헿헤헤헤헤ㅔ헤헤헤헤헿

    망했습니다….

    저번 글에서 블루 달았다고 좋아했는데 바로 터져버렸습니다…

    ㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠㅠ



    멘탈도 바사삭…


    영어를 공부해야겠다는 생각이 너무나 들었습니다

    B 번 해석을 못해서 1시간 동안 헤맸어요 ㅠㅠ


    멘탈 잡으려고 하면서 C 번도 잠깐잠깐 봤는데 이것도 안 풀리고…

    많이 부족하네요…

    더욱더 공부를 열심히 해야겠습니다

    나중에 D 번도 한번 풀어봐야겠네요



    A. Kuroni and the Gifts


    A - Kuroni and the Gifts


    중복이 없는 배열이 2개 주어지고 그 둘의 같은 인덱스 값의 합이 중복이 없게끔 순서를 구하는 문제입니다.


    중복만 없으면 되니 두 배열을 정렬하고 같은 인덱스끼리 합을 구하게 되면 두 배열 내에서도 중복이 없기 때문에 같은 값이 나올 수 없습니다.


    #include <bits/stdc++.h>
    #define FIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
    #define FOR(a,b,c) for(int a = (b); a <= (c); a++)
    #define RFOR(a,b,c) for(int a = (b); a >= (c); a--)
    #define all(x) (x).begin(), (x).end()
    #define vi vector <int>
    #define vvi vector <vi>
    #define ll long long
    #define vll vector <ll>
    #define vvl vector <vll>
    #define pii pair<int,int>
    #define pll pair<ll,ll>
    #define eb emplace_back
    #define ep emplace
    #define fs first
    #define sd second
    using namespace std;
    
    int main() {
    	FIO;
    	int t; cin >> t; while (t--) {
    		int n; cin >> n;
    		int a[105], b[105];
    		FOR(i, 0, n - 1) cin >> a[i];
    		FOR(i, 0, n - 1) cin >> b[i];
    		sort(a, a + n);
    		sort(b, b + n);
    		FOR(i, 0, n - 1) cout << a[i] << ' '; cout << '\n';
    		FOR(i, 0, n - 1) cout << b[i] << ' '; cout << '\n';
    	}
    	return 0;
    }
    


    B. Kuroni and Simple Strings


    B - Kuroni and Simple Strings


    하아… 입력으로 주어지는 문자열에서 간단한 부분 문자열을 제거하고 제거한 문자 인덱스와 횟수를 출력하는 문제입니다.


    간단한 문자열이 뭔지 해석을 못하고…

    모든 문자 제거 못하는 줄 알고…

    이거저거 해석을 못해서 너무 많은 시간과 제출을 낭비했네요 ㅠㅠ


    간단한 문자열을 지운 뒤 또 간단한 문자열이 있으면 계속 지워서

    그 횟수를 출력하라고 하는데 간단한 문자열이 있을 때 지우고 난 다음에

    간단한 문자열이 없게끔 지울 수 있으므로 0 또는 1을 출력합니다.


    괄호를 최대한 크게 만들어 간단한 문자열을 최대한 많이 지웁니다.

    왼쪽 끝에서 여는 괄호 나오는 것과 오른쪽 끝에서 닫는 괄호를 이어주면서 쭉 보시면 됩니다.


    #include <bits/stdc++.h>
    #define FIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
    #define FOR(a,b,c) for(int a = (b); a <= (c); a++)
    #define RFOR(a,b,c) for(int a = (b); a >= (c); a--)
    #define all(x) (x).begin(), (x).end()
    #define vi vector <int>
    #define vvi vector <vi>
    #define ll long long
    #define vll vector <ll>
    #define vvl vector <vll>
    #define pii pair<int,int>
    #define pll pair<ll,ll>
    #define eb emplace_back
    #define ep emplace
    #define fs first
    #define sd second
    using namespace std;
    
    int main() {
    	FIO;
    	string s;
    	cin >> s;
    	queue <int> q;
    	vi ans;
    	int len = (int)s.size();
    	FOR(i, 0, len - 1) {
    		if (s[i] == '(') q.ep(i);
    	}
    	RFOR(i, len - 1, 0) {
    		if (s[i] == ')') {
    			if (q.empty()) break;
    			int a = q.front(); q.pop();
    			if (a > i) break;
    			ans.eb(i);
    			ans.eb(a);
    		}
    	}
    	sort(all(ans));
    	if ((int)ans.size()) {
    		cout << 1 << '\n';
    		cout << (int)ans.size() << '\n';
    		for (int i : ans) cout << i + 1 << ' ';
    	}
    	else cout << 0 << '\n';
    	return 0;
    }
    


    C. Kuroni and Impossible Calculation


    C - Kuroni and Impossible Calculation


    문제에 주어진 연산을 하고 모듈러 연산을 한 값을 구하는 문제입니다.


    이 문제에서 연산을 하는 시간 복잡도를 줄여야 하는 줄 알고 수학 문제 풀듯이 계속 식만 적었는데 알고 보니 연산은 O(N^2)으로 그냥 하는 것이었습니다..


    M이 최대 1000이라서 비둘기집의 원리로 값들을 미리 M으로 모듈러 연산을 하고 체크해 줍니다.

    그리고 같은 수가 나왔을 경우 그 두 수를 연산하면 0이기 때문에 곱하면 0이 나오므로 0을 출력해 줍니다.


    만약 같은 숫자가 나오지 않았다면 N은 최대 999이므로 O(N^2)으로 답을 구하시면 됩니다.


    그때는 엄청 어려웠는데… 알고 나니 쉬운 문제네요… ㅠㅠ


    #include <bits/stdc++.h>
    #define FIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
    #define FOR(a,b,c) for(int a = (b); a <= (c); a++)
    #define RFOR(a,b,c) for(int a = (b); a >= (c); a--)
    #define all(x) (x).begin(), (x).end()
    #define vi vector <int>
    #define vvi vector <vi>
    #define ll long long
    #define vll vector <ll>
    #define vvl vector <vll>
    #define pii pair<int,int>
    #define pll pair<ll,ll>
    #define eb emplace_back
    #define ep emplace
    #define fs first
    #define sd second
    using namespace std;
    
    int main() {
    	FIO;
    	int n, m; cin >> n >> m;
    	int arr[1005] = {}, ans = 1;
    	int v[1005];
    	FOR(i, 1, n) {
    		int x; cin >> x; v[i] = x;
    		if (arr[x % m]) return cout << 0 << '\n', 0;
    		arr[x % m] = 1;
    	}
    	FOR(i, 1, n) FOR(j, i + 1, n) {
    		ans = (1LL * ans * abs(v[j] - v[i])) % m;
    	}
    	cout << ans << '\n';
    	return 0;
    }
    


    PSOzon Tech ChallengeDiv.1 + Div.2 Share Tweet +1

    CATALOG