結果
| 問題 |
No.393 2本の竹
|
| コンテスト | |
| ユーザー |
asugen0402
|
| 提出日時 | 2019-04-02 09:20:26 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 4,351 bytes |
| コンパイル時間 | 1,829 ms |
| コンパイル使用メモリ | 32,256 KB |
| 実行使用メモリ | 54,516 KB |
| 最終ジャッジ日時 | 2024-11-28 17:48:34 |
| 合計ジャッジ時間 | 8,088 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 TLE * 2 |
ソースコード
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// 内部定数
#define D_ON 1 // 汎用フラグ - ON
#define D_OFF 0 // 汎用フラグ - OFF
#define D_ORD_MAX 65 // 最大注文数
#define D_LEN_MAX 100005 // 最大長
// 内部変数
static FILE *szpFpI; // 入力
static int si1BLen[2]; // 竹長さ
static int si1Ord[D_ORD_MAX]; // 注文
static int siOCnt; // 注文数
static int si2MCnt[D_ORD_MAX][D_LEN_MAX]; // 作成数[注文][竹長さ]
static int siMax; // 最大作成数
// 内部変数 - テスト用
#ifdef D_TEST
static int siRes;
static FILE *szpFpA;
static int siTNo;
#endif
// 出力
int
fOut(
char *pcpLine // <I> 1行
)
{
char lc1Buf[1024];
#ifdef D_TEST
fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
if (strcmp(lc1Buf, pcpLine)) {
siRes = -1;
}
#else
printf("%s", pcpLine);
#endif
return 0;
}
// 数値(int) - 入れ替え
int
fSwap(
int *pipVal1 // <IO> 値1
, int *pipVal2 // <IO> 値2
)
{
int liWork = *pipVal1;
*pipVal1 = *pipVal2;
*pipVal2 = liWork;
return 0;
}
// ソート関数 - int昇順
int
fSortFnc(
const void *pzpVal1 // <I> 値1
, const void *pzpVal2 // <I> 値2
)
{
int *lipVal1 = (int *)pzpVal1;
int *lipVal2 = (int *)pzpVal2;
// int昇順
if (*lipVal1 > *lipVal2) {
return 1;
}
else if (*lipVal1 < *lipVal2) {
return -1;
}
return 0;
}
// 作成数 - セット
int
fSeMCnt(
int piONo // <I> 注文 0~
, int *pipSel // <I> 選択
, int piSCnt // <I> 選択数
, int piSSum // <I> 選択合計
)
{
int i;
// 作成数 - 竹1 + 竹2
int liSum = 0;
int liMCntS = piSCnt;
for (i = 0; i < siOCnt; i++) {
if (pipSel[i] == D_OFF) {
liSum += si1Ord[i];
if (liSum > si1BLen[1]) {
break;
}
liMCntS++;
}
}
// 作成数
if (si2MCnt[piONo][piSSum] >= liMCntS) {
return 0;
}
si2MCnt[piONo][piSSum] = liMCntS;
// 最大作成数
if (siMax < liMCntS) {
siMax = liMCntS;
}
// 選択終了
if (piONo >= siOCnt) {
return 0;
}
// 選択 - あり
if (piSSum + si1Ord[piONo] <= si1BLen[0]) {
pipSel[piONo] = D_ON;
fSeMCnt(piONo + 1, pipSel, piSCnt + 1, piSSum + si1Ord[piONo]);
pipSel[piONo] = D_OFF;
}
// 選択 - なし
fSeMCnt(piONo + 1, pipSel, piSCnt, piSSum);
return 0;
}
// 実行メイン
int
fMain(
)
{
int i;
char lc1Buf[1024];
// データ - 初期化
memset(si2MCnt, 0, sizeof(si2MCnt)); // 作成数
siMax = 0; // 最大作成数
// 竹長さ - 取得
fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
sscanf(lc1Buf, "%d%d", &si1BLen[0], &si1BLen[1]);
if (si1BLen[0] > si1BLen[1]) {
fSwap(&si1BLen[0], &si1BLen[1]);
}
// 注文数 - 取得
fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
sscanf(lc1Buf, "%d", &siOCnt);
// 注文 - 取得
for (i = 0; i < siOCnt; i++) {
fscanf(szpFpI, "%d", &si1Ord[i]);
}
fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
// 注文 - ソート
qsort(si1Ord, siOCnt, sizeof(int), fSortFnc);
// 作成数 - セット
int li1Sel[D_ORD_MAX];
memset(li1Sel, D_OFF, sizeof(li1Sel));
fSeMCnt(0, li1Sel, 0, 0);
return 0;
}
// 1回実行
int
fOne(
)
{
int i;
char lc1Buf[1024];
// 入力 - セット
#ifdef D_TEST
sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
szpFpI = fopen(lc1Buf, "r");
sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
szpFpA = fopen(lc1Buf, "r");
siRes = 0;
#else
szpFpI = stdin;
#endif
// データ数 - 取得
int liDCnt;
fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
sscanf(lc1Buf, "%d", &liDCnt);
// 実行メイン
for (i = 0; i < liDCnt; i++) {
fMain();
// 結果 - セット
sprintf(lc1Buf, "%d\n", siMax);
// 結果 - 出力
fOut(lc1Buf);
}
// 残データ有無
#ifdef D_TEST
lc1Buf[0] = '\0';
fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
if (strcmp(lc1Buf, "")) {
siRes = -1;
}
#endif
// テストファイルクローズ
#ifdef D_TEST
fclose(szpFpI);
fclose(szpFpA);
#endif
// テスト結果
#ifdef D_TEST
if (siRes == 0) {
printf("OK %d\n", siTNo);
}
else {
printf("NG %d\n", siTNo);
}
#endif
return 0;
}
// プログラム開始
int
main()
{
#ifdef D_TEST
int i;
for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
siTNo = i;
fOne();
}
#else
fOne();
#endif
return 0;
}
asugen0402