백준에서 개최되었던 대회이다.

백준 대회에서 처음으로 3솔 해서 간단하게나마 블로그에 정리해 본다.

푼 문제가 다 브론즈다 ㅠㅠ

시작하자마자 문제를 풀었고, 푸는 속도도 나름 괜찮았는지 초반에는 등수가 상당히 작은 한자리 수였다.

4등까지 올라갔던 것 같다.

하지만 시간이 지나면서 고수분들은 어려운 문제들을 척척 푸시고, 나는 그러지 못해서 결국은 등수가 큰 2자리 수로 내려갔다 ㅠㅠ

그럼 풀이로 들어가자.

 

PA. 세금

-> 간단한 수학 문제이다.

-> 문제에서 전체 상금의 22%를 제세공과금으로 납부하는 경우와 상금의 80%를 필요 경비로 인정받고, 나머지 금액        중 22%만을 제세공과금으로 납부하는 경우의 수령 금액을 구하라고 했는데, 이를 수학으로 풀면 된다.

#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    printf("%d %d",n-(n*22/100),n-(n*20/100)*22/100);
}

[00:03 맞았습니다!]

 

이 문제에서 처음에 너무 복잡하게 생각해서 코드를 이상하게 짜는 바람에 1번 미스가 나서 시간을 너무 많이 쏟아 버렸다.

쉬운 문제는 쉽게 생각해야 한다. 이것은 코포 div.3에서도 적용된다.

(나는 자꾸 쉬운 문제를 어렵게 생각하고 긴장해서 1분만에 풀 것을 10분도 넘게 걸린다 ㅠㅠ)

PA번 다음 문제는 PB번인데, 내가 PB번을 봤을 때 첫인상이 너무 어려워 보였다.

그래서 다음 문제들을 슥 훑어보던 도중 굉장히 쉬운 문제를 또 찾게 되었는데, 바로 D번이다.

D번을 빨리 찾은 것이 신의 한 수였다.

 

D. Darius님 한타 안 함?

-> 역시 간단한 문제이다.

-> 조건문으로 a+c<b 또는 b=0 이면 hasu를 출력하고, 아니면 gosu를 출력하면 된다.

#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d/%d/%d",&a,&b,&c);
    if(a+c<b||b==0) puts("hasu");
    else puts("gosu");
}

[00:05 맞았습니다!]

 

이 문제를 푸는데 걸린 시간이 PA번 푸는데 걸린 시간보다 짧다,,

그만큼 PA에서 긴장한 것 같다.

이 문제를 품으로써 나는 비록 초반이지만 5분만에 2문제를 푼 상위권으로 올라가게 되었다.

그리고 다른 문제들을 스캔하던 중 E번이 눈에 들어와서 고민을 해 보았다.

하지만 아무리 생각해도 답이 나오질 않아서 포기하고 J번을 보았더니 조합 문제였다.

교란순열 관련 문제여서 간단하게 짜서 컴파일러에서 돌려보니 정답이 잘 나와서 제출하려는 순간..

뭔가 큰 테케에서 틀릴 것 같았다.

내 감은 틀리지 않았고, 최대치를 입력해본 결과 실행시간이 압도적으로 길어졌다.

그래서 어떻게 하면 교란순열 구하는 과정을 최적화할 수 있을 까 고민하다가 그냥 포기하고 공부하러 들어갔다.

그리고 대회 시작 약 2시간 후에 나와서 다시 문제를 훑어보는데..

뭔가PC번에서 느낌적인 느낌으로 두 문자열의 길이를 더한 것이 답일 것 같았다.

그래서 PC번을 풀게 되었다(...)

 

PC. 스시

-> 처음 볼 때는 상당히 어려워 보인다.

-> 하지만 문제를 잘 관찰해 보면 두 문자열의 길이를 더한 것이 답이 됨을 알 수 있다.

#include<stdio.h>
#include<string.h>
int main()
{
    int n,cnt=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        char str[101];
        scanf("%s",str);
        cnt+=strlen(str);
    }
    printf("%d",cnt);
}

[02:32 맞았습니다!]

 

진짜 감이 잘 들어맞은 문제였다.. ㄷㄷ

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

KOI 오픈 컨테스트 후기  (0) 2020.11.16

 

A랑 B 빨리 풀었다고 신났다가 망함..;;

바로 풀이로 들어가자.

 

A. Brick

Problem Statement

We have a truck, which can carry at most kilograms.

We will load bricks onto this truck, each of which weighs  kilograms. At most how many bricks can be loaded?

 

Constraints

  • 1≤N,W≤1000
  •  and  are integers.

Input

Input is given from Standard Input in the following format:

N W

Output

Print an integer representing the maximum number of bricks that can be loaded onto the truck.

풀이

n 킬로그램까지 실을 수 있는 트럭에 w킬로그램 나가는 물건을 얼마나 실을 수 있는지 물어보는 문제이다.

C, C++에서는 그냥 나누면 되고, 파이썬은 정수 나눗셈을 이용한 풀이를 할 수 있다.

정말 쉬운 문제이고, 27초 만에 풀어서 그때 스코어보드 97등이었다. XD

A번 최고기록

#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d",a/b);
    return 0;
}

[00:27 Accepted]

 

B. Blocks on Grid

Problem Statement

We have a grid with  horizontal rows and vertical columns. The square at the i-th row from the top and j-th column from the left has Ai,j blocks stacked on it.

At least how many blocks must be removed to make all squares have the same number of blocks?

Constraints

  • 1≤H,W≤100

Input

Input is given from Standard Input in the following format:

W

A1,1  

AH,1 AH,2 AH,W

Output

Print the minimum number of blocks that must be removed.

풀이

모든 블럭의 개수를 체크해서 가장 작은 값으로 만들어야 한다. 따라서 모든 블럭의 개수만큼 반복문을 돌리고, 해당 칸의 블록의 개수에서 가장 적은 블록의 개수를 뺀 것들의 합이 정답이 된다.

#include<stdio.h>
int main()
{
    int a,b,min = 99999999,i,j;
    int sum=0;
    int arr[1001][1001];
    scanf("%d%d",&a,&b);
    for(i=0;i<a;i++)
    {
        for(j=0;j<b;j++)
        {
            scanf("%d",&arr[i][j]);
            if(arr[i][j]<min)
            {
                min = arr[i][j];
            }
        }
    }
    for(i=0;i<a;i++)
    {
        for(j=0;j<b;j++)
        {
            sum = sum + (arr[i][j]-min);
        }
    }
    printf("%lld",sum);
    return 0;
}

[04:12 Accepted]

 

 

여기까지는 나의 ABC 최고기록이었다.

그리고 C, D, E에서 동시에 뇌절하는 바람에 더 못풀었다... ㅠㅠㅠ

 

C, D업솔빙 예정

 

UPD : C업솔빙 완료

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

AtCoder Beginner Contest 189 후기  (0) 2021.01.24
Atcoder Beginner contest 185 후기  (0) 2020.12.19
ABC 184 후기  (0) 2020.11.23

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번이 생각보다 쉬워서 좋았다.(--)

+ Recent posts