스웨덴의 대학교에서 개최하는 대회의 본선 이전에 연습하는 대회이다.

연습 대회이긴 하지만 문제 질도 괜찮고, 난이도도 상당하기에 후기를 올린다.

sitstar2021.contest.codeforces.com/group/1HLBM0lmlk/contests

 

Login - Codeforces

 

sitstar2021.contest.codeforces.com

여기서 대회를 볼 수 있다.(대회 진행중에는 볼 수 없는 것으로 알고 있다)

일단 문제는 12문제인데, 나는 그 중 8개를 풀었다.

8개 모두 풀이를 작성하고, 짧은 것은 이어서, 긴 것은 따로 풀이를 포스팅해 링크를 여기에 모아두도록 하겠다.

에디토리얼은 영어로 작성했다

시작하자!

 

 

A~D = ilc12345-080.tistory.com/57

 

SIT Contest A, B, C, D Editorial

A. Arithmetic sitstar2021.contest.codeforces.com/group/1HLBM0lmlk/contest/309373/problem/A Login - Codeforces sitstar2021.contest.codeforces.com (sol) You need to print 'Yes' if a*b==c or b*c==a or..

ilc12345-080.tistory.com

 

나머지는 더 쓸 예정..

쓰는대로 업데이트하겠습니다

A. Arithmetic

<problem link>

sitstar2021.contest.codeforces.com/group/1HLBM0lmlk/contest/309373/problem/A

 

Login - Codeforces

 

sitstar2021.contest.codeforces.com

(sol)

You need to print 'Yes' if a*b==c or b*c==a or c*a==b.

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0)
typedef long long ll;
using namespace std;
int main(){
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		if(a*b==c)
		{
			puts("YES");
			printf("%d %d %d\n",a,b,c);
		}
		else if(b*c==a)
		{
			puts("YES");
			printf("%d %d %d\n",b,c,a);
		}
		else if(c*a==b)
		{
			puts("YES");
			printf("%d %d %d\n",c,a,b);
		}
		else puts("NO");
	}
	return 0;
}

 

B. Fair Division

<problem link>

sitstar2021.contest.codeforces.com/group/1HLBM0lmlk/contest/309373/problem/B

 

Login - Codeforces

 

sitstar2021.contest.codeforces.com

(sol)

If n is dividable by 3, you need to print 'a/3-1', 'a/3', and 'a/3+1'.

If not, the answer does not exist. Print '-1'.

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0)
typedef long long ll;
using namespace std;

int main(){
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int a;
		scanf("%d",&a);
		if(a%3==0)
		{
			int k=a/3;
			printf("%d %d %d\n",k-1,k,k+1);
		}
		else puts("-1");
	}
	return 0;
}

 

C. Baking

<problem link>

sitstar2021.contest.codeforces.com/group/1HLBM0lmlk/contest/309373/problem/C

 

Login - Codeforces

 

sitstar2021.contest.codeforces.com

(sol)

You can compare |a-b| and |a-c|.

If |a-b| is smaller, print |a-b|+|b-c|.

Else, print |a-c|+|b-c|.

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0)
typedef long long ll;
using namespace std;

int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(abs(a-b)<=abs(a-c))
	{
		printf("%d",abs(a-b)+abs(b-c));
	}
	else
	{
		printf("%d",abs(a-c)+abs(c-b));
	}
	return 0;
}

 

D. Cheese Factory

<problem link>

sitstar2021.contest.codeforces.com/group/1HLBM0lmlk/contest/309373/problem/D

 

Login - Codeforces

 

sitstar2021.contest.codeforces.com

(sol)

You can conduct a greedy solution.

Use the container that can contain the most for the customer that buys the most, and vice versa.

Therefore, you need to print the sum of the multiples of the first, second, and third biggest numbers in the sequence a[i] and b[i].

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0)
typedef long long ll;
using namespace std;
int main(){
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int a,b,c,d,e,f;
		scanf("%d %d %d\n%d %d %d",&a,&b,&c,&d,&e,&f);
		int m1,m2,m3,n1,n2,n3;
		m1=max3(a,b,c);
		m3=min3(a,b,c);
		m2=a+b+c-m1-m3;
		n1=max3(d,e,f);
		n3=min3(d,e,f);
		n2=d+e+f-n1-n3;
		printf("%d\n",m1*n1+m2*n2+m3*n3);
	}
	return 0;
}

 

 

Div 3라 문제가 쉬웠고, 업솔빙 포함해서 3문제를 풀 수 있었다.

업솔빙 한 문제는 년-월-일-시간 순으로 맞은 일시를 적었고, 대회 시간 내 푼 문제는 대회시작으로부터 누적시간-분 순으로 맞은 일시를 적었다.

바로 풀이로 들어가자.

 

A. Favorite Sequence

Problem statement

 

Polycarp has a favorite sequence a[1n] consisting of n integers. He wrote it out on the whiteboard as follows:

  • he wrote the number a1 to the left side (at the beginning of the whiteboard);
  • he wrote the number a2 to the right side (at the end of the whiteboard);
  • then as far to the left as possible (but to the right from a1), he wrote the number a3;
  • then as far to the right as possible (but to the left from a2), he wrote the number a4;
  • Polycarp continued to act as well, until he wrote out the entire sequence on the whiteboard.

The beginning of the result looks like this (of course, if n≥4).

For example, if n=7 and a=[3,1,4,1,5,9,2], then Polycarp will write a sequence on the whiteboard [3,4,5,2,9,1,1].

You saw the sequence written on the whiteboard and now you want to restore Polycarp's favorite sequence.

Input

The first line contains a single positive integer t (1≤t≤300) — the number of test cases in the test. Then t test cases follow.

The first line of each test case contains an integer n (1≤n≤300) — the length of the sequence written on the whiteboard.

The next line contains nn integers b1,b2,,bn (1bi10^9) — the sequence written on the whiteboard.

Output

Output t answers to the test cases. Each answer — is a sequence a that Polycarp wrote out on the whiteboard.

풀이

문제를 읽으면 알 수 있듯이 처음과 마지막을 먼저 쓰고, 중간을 끝에서부터 순서대로 채워나가는 방식으로 쓴다고 하니 이를 역방향으로 적용시키면 된다. 가장 먼저 첫 element를 출력하고, 그 다음 마지막 element, 2번째, 마지막에서 2번째, ... 이런 식으로 출력을 하자. 이때 n이 홀수인지 짝수인지를 판단해서, 홀수라면 가운데 값이 있으므로 마지막에 따로 출력해 주고, 짝수라면 특이사항이 없다.

#include<stdio.h>
int main()
{
    int n;
    int arr[1001];
    scanf("%d\n",&t);
    while(t--){
        scanf("%d",&n);
        for(i=0;i<n;i++){
            scanf("%d ",&arr[i]);
        }
        k = n/2;
        if(n%2==0){
            for(i=0;i<n/2;i++){
                printf("%d %d ",arr[i],arr[n-i-1]);
            }
            printf("\n");
        }
        else{
            for(i=0;i<n/2;i++){
                printf("%d %d ",arr[i],arr[n-i-1]);
            }
            printf("%d\n",arr[n/2]);
        }
    }
    return 0;
}

[00:08 Accepted]

 

B. Last Year's Substring

Problem statement

 

Polycarp has a string s[1n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):

  • Polycarp selects two numbers i and j (1≤i≤j≤n) and removes characters from the s string at the positions i,i+1,i+2,,j (i.e. removes substring s[i…j]). More formally, Polycarp turns the string s into the string s1s2si1sj+1sj+2sn.

For example, the string s="20192020" Polycarp can turn into strings:

  • "2020" (in this case (i,j)=(3,6) or (i,j)=(1,4));
  • "2019220" (in this case (i,j)=(6,6));
  • "020" (in this case (i,j)=(1,5));
  • other operations are also possible, only a few of them are listed above.

Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.

Input

The first line contains a positive integer t (1≤t≤1000) — number of test cases in the test. Then tt test cases follow.

The first line of each test case contains an integer n (4≤n≤200) — length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.

Output

For each test case, output on a separate line:

  • "YES" if Polycarp can turn the string ss into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
  • "NO" otherwise.

You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

풀이

문제를 요약하면 주어진 문자열 안에 '2020'이 1개, 또는 2개로 분리되어 있는지를 판별하는 문제이다. 2020이 1개로 분리되는 방법은 '2020' 한가지밖에 없다. 2개로 분리되는 방법의 수는 '2/020', '20/20', '202/0' 이렇게 3개지 경우가 있다. 하지만 이때 한번만 문자열에서 문자의 묶음을 지울 수 있으므로 '2020'이 2개로 분리되는 경우에서는 분리된 2개의 문자열이 각각 주어진 문자열의 맨 앞과 맨 뒤에 있어야 한다. 앞서 말한 조건을 단순 if문으로 모두 확인하면 된다. 

 

이 문제는 개인적으로 어렵게 생각하면 굉장히 어려워지지만 실제로는 쉬운 문제라고 생각된다. 

Editorial을 보기 전 이 문제를 가지고 정말 한참을 고민했는데도 답을 찾지 못했는데, Editorial을 보고 나니 허탈했다;;

 

#include<stdio.h>
char x[210];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		int a;
		scanf("%d",&a);
		scanf("%s",x+1);
		if(x[1]=='2'&&x[2]=='0'&&x[3]=='2'&&x[4]=='0'){
        	printf("YES\n");
        }
		else if(x[1]=='2'&&x[2]=='0'&&x[3]=='2'&&x[a]=='0'){
        	printf("YES\n");
        }
		else if(x[1]=='2'&&x[2]=='0'&&x[a-1]=='2'&&x[a]=='0'){
        	printf("YES\n");
        }
		else if(x[1]=='2'&&x[a-2]=='0'&&x[a-1]=='2'&&x[a]=='0'){
        	printf("YES\n");
        }
		else if(x[a-3]=='2'&&x[a-2]=='0'&&x[a-1]=='2'&&x[a]=='0'){
        	printf("YES\n");
        }
		else printf("NO\n");
	}
}

[2020-12-15-19:58 Accepted]

 

 

C. Unique number

Problem statement

You are given a positive number x. Find the smallest positive integer number that has the sum of digits equal to x and all digits are distinct (unique).

 

Input

The first line contains a single positive integer t (1≤t≤50) — the number of test cases in the test. Then t test cases follow.

Each test case consists of a single integer number x (1x50).

Output

Output t answers to the test cases:

  • if a positive integer number with the sum of digits equal to x and all digits are different exists, print the smallest such number;
  • otherwise print -1.

풀이

if문 노가다 ㄱㄱ!! 뭐 Editorial 보니까 멋있게 수식으로 푸는 방법이 있더라...

근데 이게 노가다 하는거도 50개를 다 하기에는 손이 너무 아파서 좀 효율적인(?) 노가다를 하기 위해서 일종의 전략(?)을 짜 보았다.

일단 x가 9보다 작거나 같은 경우에는 그냥 x를 출력하자.

x가 1~9까지의 숫자로 만들 수 있는 가장 큰 수의 자릿수의 합보다 큰 경우(즉, 45보다 큰 경우)는 -1을 출력한다.

그 외의 경우를 다 노가다 치기는 힘드니까 또다시 자연수들을 묶음으로 나누어 보자.

먼저 x가 9보다 크고 17보다 작거나 같은 경우는 모두 _9 모양의 2자리 숫자로 표현해야 한다.

그다음 x가 17보다 크고 24보다 작거나 같은 경우는 모두 _89 모양의 3자리 숫자로 표현해야 한다.

이런 식으로 해 나가면 if문 단 14개(?!)로 해결 할 수 있다!!

물론 그래도 노가다는 심하다

#include <stdio.h>
int main()
{
    int t,i,x;
    scanf("%d\n",&t);
    while(t--)
    {
        scanf("%d",&x);
        if(x<=9) printf("%d\n",x);
        else
        {
            if(x>45)
            {
                printf("-1\n");
            }
            else if(x>9&&x<=17)
            {
                printf("%d9\n",x-9);
            }
            else if(x>=18&&x<=24)
            {
                printf("%d89\n",x-17);
            }
            else if(x>=25&&x<=30)
            {
                printf("%d789\n",x-24);
            }
            else if(x>=31&&x<=35)
            {
                printf("%d6789\n",x-30);
            }
            else if(x>=36&&x<=39)
            {
                printf("%d56789\n",x-35);
            }
            else if(x==40)
            {
                printf("1456789\n");
            }
            else if(x==41)
            {
                printf("2456789\n");
            }
            else if(x==42)
            {
                printf("3456789\n");
            }
            else if(x==43)
            {
                puts("13456789");
            }
            else if(x==44)
            {
                puts("23456789");
            }
            else
            {
                puts("123456789");
            }
        }
    }
    return 0;
}

[01:34 Wrong Answer on test 2]

[01:37 Accepted]

 

 

3번이 생각보다 쉬워서 좋았다.(--)

조금 늦게 후기를 작성한다.

이 라운드는 한국인인 djm03718님이 주최하셔서 굉장히 기대가 되었다.

시간도 한국인에 맞게 1시간 이른 10시 35분이어서 좋았다.

그래도 한문제밖에 못풀었다.

바로 풀이로 들어가도록 하겠다.

 

A. Cancel the trains

Problem statement

Gildong's town has a train system that has 100 trains that travel from the bottom end to the top end and 100 trains that travel from the left end to the right end. The trains starting from each side are numbered from 11 to 100, respectively, and all trains have the same speed. Let's take a look at the picture below.

The train system can be represented as coordinates on a 2D plane. The i-th train starting at the bottom end is initially at (i,0) and will be at (i,T) after T minutes, and the i-th train starting at the left end is initially at (0,i) and will be at (T,i) after T minutes. All trains arrive at their destinations after 101 minutes.

However, Gildong found that some trains scheduled to depart at a specific time, simultaneously, are very dangerous. At this time, n trains are scheduled to depart from the bottom end and mm trains are scheduled to depart from the left end. If two trains are both at (x,y) at the same time for some x and y, they will crash into each other. Therefore, he is asking you to find the minimum number of trains that should be canceled to prevent all such crashes.

**문제에 오타가 있습니다. Bold로 표시한 'canceled'가 문제 지문에서는 'cancelled'로 표기되어 있습니다.**

 

Input

Each test contains one or more test cases. The first line contains the number of test cases t (1≤t≤100).

Each test case contains three lines. The first line of each test case consists of two integers n and m (1≤n,m≤100) — the number of trains scheduled to depart from the bottom end, and the number of trains scheduled to depart from the left end, respectively.

The second line of each test case contains n integers. Each integer is a train number that is scheduled to start from the bottom end. The numbers are given in strictly increasing order, and are between 1 and 100, inclusive.

The third line of each test case contains mm integers. Each integer is a train number that is scheduled to start from the left end. The numbers are given in strictly increasing order, and are between 1 and 100, inclusive.

 

Output

For each test case, print a single integer: the minimum number of trains that should be canceled in order to prevent all crashes.

풀이

두개의 기차가 충돌하게 되는 조건은 같은 시간에 같은 위치에서 출발한 경우가 된다.

따라서 입력되는 2개의 배열에서 같은 숫자가 나오는 횟수를 출력하면 된다.

 

#include<stdio.h>
int main()
{
    int i,j,n,m,t,train[101],train2[101],cnt=0;
    scanf("%d\n",&t);
    while(t--)
    {
        scanf("%d %d\n",&n,&m);
        for(i=0;i<n;i++)
        {
            scanf("%d",&train[i]);
        }
        for(j=0;j<m;j++)
        {
            scanf("%d",&train2[j]);
        }
        cnt=0;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                if(train[i]==train2[j]) cnt++;
                else continue;
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}

[00:09 Pretest Passed(3)/Accepted]

 

한 문제만 풀었다.

B번 업솔빙 예정..

'대회 후기 > Codeforces' 카테고리의 다른 글

SIT STAR Contest 2021 practice  (0) 2021.02.08
SIT Contest A, B, C, D Editorial  (0) 2021.02.08
Codeforces Round 690 (Div.3) 후기  (0) 2020.12.20
Codeforces Round #687 (Div. 2) 후기  (2) 2020.12.01
Codeforces Round #686 (Div.3) 후기  (0) 2020.11.25

대회 시작 시간이 굉장히 특이하길래(보통은 밤 11시 35분 정도에 시작하지만 이번 대회는 시작 시간이 오후 4시 5분이었다) 냉큼 참가했다.
대회 시작부터 문제를 풀었고, 30분정도 풀다가 일이 있어 그만두었다. 그리고 대회 끝나기 약 30분 정도 전에 들어와서 15분 정도 풀다 접었다.
총 1문제를 풀었는데, 결론적으로 보면 1문제, 그것도 A번에 45분을 쏟았다.
Div.2 한문제 푸는데 45분 걸리는 흑우
서론은 이쯤 하고, 풀이로 들어가자.

 

A. Prison Break

Problem Statement

There is a prison that can be represented as a rectangular matrix with n rows and m columns. Therefore, there are n⋅m prison cells. There are also n⋅m prisoners, one in each prison cell. Let's denote the cell in the i-th row and the j-th column as (i,j).

There's a secret tunnel in the cell (r,c), that the prisoners will use to escape! However, to avoid the risk of getting caught, they will escape at night.

Before the night, every prisoner is in his own cell. When night comes, they can start moving to adjacent cells. Formally, in one second, a prisoner located in cell (i,j) can move to cells (i−1,j) , (i+1,j) , (i,j−1) , or (i,j+1), as long as the target cell is inside the prison. They can also choose to stay in cell (i,j).

The prisoners want to know the minimum number of seconds needed so that every prisoner can arrive to cell (r,c) if they move optimally. Note that there can be any number of prisoners in the same cell at the same time.

 

Input

The first line contains an integer t (1t10^4), the number of test cases.

Each of the next t lines contains four space-separated integers n, m, r, c (1rn10^9, 1cm10^9).

 

Output

Print t lines, the answers for each test case.

 

풀이

모든 방 안에 죄수가 꽉 차 있고, 죄수는 움직이지 않을 수도 있으므로 문제에서 구하고자 하는 시간은 탈출구에서 가장 멀리 떨어져 있는 죄수가 탈출구로 이동하는 시간과 같다.

탈출구에서 가장 멀리 떨어져 있는 죄수는 항상 감옥의 4 꼭짓점(귀퉁이)에 있음을 알 수 있다.

따라서 4 귀퉁이에서 탈출구까지 가는 최단거리를 비교해서 가장 큰 값을 출력하면 된다.

 

#include<stdio.h>
int max(int a, int b){if(a>=b){return a;}else{return b;}}
int main()
{
    int a,b,c,d,t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d %d %d",&a,&b,&c,&d);
        printf("%d\n",max(max(max(c+d-2,a-c+b-d),a-c+d-1),c-1+b-d));
    }
}

이걸 45분 고민했다

[00:12 Wrong Answer on pretest 1]

[00:14 Wrong Answer on pretest 2]

[00:16 Wrong Answer on pretest 2]

[00:51 Wrong Answer on pretest 2]

[01:00 Wrong Answer on pretest 1]

[01:12 Wrong Answer on pretest 2]

[01:34 Pretests passed, Accepted(9)]

 

 

 

이런 실수는 하지 말자.... ㅠㅠ

B번은 업솔빙 예정

'대회 후기 > Codeforces' 카테고리의 다른 글

SIT STAR Contest 2021 practice  (0) 2021.02.08
SIT Contest A, B, C, D Editorial  (0) 2021.02.08
Codeforces Round 690 (Div.3) 후기  (0) 2020.12.20
Codeforces Round #688 (Div. 2) 후기  (0) 2020.12.14
Codeforces Round #686 (Div.3) 후기  (0) 2020.11.25

+ Recent posts