結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー mafuyu-akimafuyu-aki
提出日時 2017-04-08 15:12:53
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,926 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 27,988 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-24 23:25:13
合計ジャッジ時間 4,260 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,984 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define READ_BUFSIZE ( 128 )
#define READ_DELIMITER ( " " )


//標準入力取得(1行)

int GetStdin( char* pszStr, int lMaxLen )
{
	int lLen = 0;

    memset( pszStr, 0, lMaxLen );
    if( fgets( pszStr, lMaxLen, stdin ) )
    {
	    lLen = strlen( pszStr );
	    if( lLen >= 1 )
	    {
			if( pszStr[ lLen - 1 ] == 0x0A )
			{
				pszStr[ lLen - 1 ] = 0;
				lLen--;
			}
		}
	}
	
	return( lLen );
}

//標準入力を取得
//区切り文字で区切られている文字列を取り出す
//取り出した文字列のポインタをポインタ配列にセットする (数値型)
int split(char *pszStr, int lStrMax, const char *pszDelim, int *palOutList) {
    char *pszToken;
    int count = 0;
    char *pszNext_token = 0;
	int lLen = 0;
	int lNum = 0;

    memset( pszStr, 0, lStrMax );
    lLen = GetStdin( pszStr, lStrMax );
    
	if( lLen > 0 )
	{

	    pszToken = strtok( pszStr, pszDelim );

	    while ( pszToken != NULL ) 
	    {
            *palOutList = atoi( pszToken );
			lNum++;
//	        pszToken = strtok_s(NULL, pszDelim, &pszNext_token);
		    pszToken = strtok( NULL, pszDelim );
			palOutList++;
	    }
	}
    return lNum;
}

struct CRYSTAL
{
	int x;
	int y;
	int c;
};


int calc( int x, int y, int c, int Gx, int Gy, int F, CRYSTAL crystal[], int num, int cost )
{

	for( int i = 0; i < num; i++ )
	{
		int sum = c;
		int toho = 0;
		if ( x + crystal[i].x <=  Gx && y + crystal[i].y <= Gy )
		{
			sum += crystal[i].c;

			if( x + crystal[i].x != Gx )
				toho += F * ( Gx - ( x + crystal[i].x ) );

			if( y + crystal[i].y != Gy )
				toho += F * ( Gy - ( y + crystal[i].y ) );

			if( cost == 0 || cost > sum + toho )
				cost = sum + toho;

			if ( x + crystal[i].x < Gx || y + crystal[i].y < Gy )
				cost = calc( x + crystal[i].x, y + crystal[i].y, sum, Gx, Gy, F, &crystal[i+1], num-1, cost );
		}
		else
		{
			if( Gx -  x > 0 )
				sum += F * ( Gx -  x );
			if( Gy -  y > 0 )
				sum += F * ( Gy -  y );
//			sum += F * ( Gx - ( x + crystal[i].x ) );
//			sum += F * ( Gy - ( y + crystal[i].y ) );

			if( cost == 0 || cost > sum )
				cost = sum;
		}
			
	}

	return cost;

}

int main(int argc, char *argv[]) 
{
	char szRead[READ_BUFSIZE] = "";
	//char* psOutbuf[10000] = { 0 };
	int lInput[4] = {0};

	int lLen = split( szRead, READ_BUFSIZE, READ_DELIMITER, lInput );

	int Gx = lInput[0]; //目的地X
	int Gy = lInput[1];  //目的地Y
	int N = lInput[2];  //クリスタルの数
	int F = lInput[3];  //徒歩の通行料


	CRYSTAL Crystal[200];
	memset( Crystal, 0, sizeof( Crystal ));

		for( int i = 0; i < N; i++ )
	{
		 split( szRead, READ_BUFSIZE, READ_DELIMITER, lInput );
		 Crystal[i].x = lInput[0];
		 Crystal[i].y = lInput[1];
		 Crystal[i].c = lInput[2];
	}


	//全部歩いたら→(Gx+Gy)*F

	int sum = calc( 0, 0, 0, Gx, Gy, F, Crystal, N, (Gx+Gy)*F );

	printf( "%d\n", sum );

	return 0;

}

0