baekjoon 20251222

This commit is contained in:
songyc macbook 2025-12-22 23:19:07 +09:00
parent cb2a409fa9
commit bf5bc90a57
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,23 @@
#include <stdio.h>
#include <string.h>
int main() {
int N;
char str[52];
scanf("%d",&N);
getchar();
for(int i=1; i<=N; i++) {
fgets(str, sizeof(str), stdin);
// int j = 0;
// while(str[j] != '\n' && str[j] != '\0') j++;
// if(str[j] == '\n') str[j] = '\0';
str[strcspn(str, "\n")] = '\0';
printf("%d. %s\n",i,str);
}
return 0;
}

View File

@ -0,0 +1,20 @@
import sys
input = sys.stdin.readline
N = int(input())
seq = [0] + list(map(int, input().split()))
dp = [[0]*(N+1) for _ in range(N+1)]
for i in range(1,N+1) :
dp[i][i] = 1
if i != N and seq[i] == seq[i+1] :
dp[i][i+1] = 1
for l in range(3,N+1) :
for start in range(1, N - l + 2) :
end = start + l - 1
if seq[start] == seq[end] and dp[start+1][end-1]:
dp[start][end] = 1
M = int(input())
print('\n'.join(list((lambda x: str(dp[x[0]][x[1]]))(list(map(int, input().split()))) for _ in range(M))))