結果

問題 No.3110 Like CPCTF?
ユーザー tnakao0123
提出日時 2025-04-19 18:26:48
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 874 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 41,720 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-19 18:26:49
合計ジャッジ時間 1,061 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |   scanf("%d%s", &n, s);
      |   ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 3110.cc:  No.3110 Like CPCTF? - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 30;

/* typedef */

/* global variables */

char s[MAX_N + 4];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d%s", &n, s);

  if (n < 5) { puts("0"); return 0; }

  int cnt = 0;
  for (int i0 = 0; i0 + 5 <= n; i0++) {
    int c = s[i0] - 'A';
    for (int i1 = i0 + 1; i1 + 4 <= n; i1++) {
      int p = s[i1] - 'A';
      if (c != p)
	for (int i2 = i1 + 1; i2 + 3 <= n; i2++)
	  if (c == s[i2] - 'A')
	    for (int i3 = i2 + 1; i3 + 2 <= n; i3++) {
	      int t = s[i3] - 'A';
	      if (c != t && p != t)
		for (int i4 = i3 + 1; i4 + 1 <= n; i4++) {
		  int f = s[i4] - 'A';
		  if (c != f && p != f && t != f) cnt++;
		}
	    }
    }
  }
  
  printf("%d\n", cnt);
  
  return 0;
}
0