結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-04-13 00:48:56 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,548 bytes |
| コンパイル時間 | 184 ms |
| コンパイル使用メモリ | 25,600 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-18 10:27:31 |
| 合計ジャッジ時間 | 2,659 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 RE * 9 |
ソースコード
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define READ_BUFSIZE ( 3*100+100+1 )
#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 );
}
struct stQ
{
int index;
int sum;
};
//標準入力を取得
//区切り文字で区切られている文字列を取り出す
//取り出した文字列のポインタをポインタ配列にセットする (数値型)
//戻り値に合計を返す
//lMaxに最大値を返す
int split(char *pszStr, int lStrMax, const char *pszDelim, int *palOutList, stQ *pQ, int &lMax)
{
char *pszToken;
int count = 0;
char *pszNext_token = 0;
int lLen = 0;
int lNum = 0;
int lSum = 0;
lMax = 0;
memset( pszStr, 0, lStrMax );
lLen = GetStdin( pszStr, lStrMax );
if( lLen > 0 )
{
pszToken = strtok( pszStr, pszDelim );
while ( pszToken != NULL )
{
*palOutList = atoi( pszToken );
pQ->index = lNum;
pQ->sum = *palOutList;
lSum += *palOutList;
if( *palOutList > lMax )
lMax = *palOutList;
lNum++;
// pszToken = strtok_s(NULL, pszDelim, &pszNext_token);
pszToken = strtok( NULL, pszDelim );
palOutList++;
pQ++;
}
}
return lSum;
}
int main(int argc, char *argv[])
{
char szRead[READ_BUFSIZE] = "";
//char* psOutbuf[10000] = { 0 };
int lInput[4] = {0};
GetStdin( szRead, READ_BUFSIZE );
int N = atoi( szRead );
int W[100+1] = {0};
stQ *Q = new stQ[100*1000];
memset( Q, 0, sizeof( stQ )*100*1000 );
int max = 0;
int sum = split( szRead, READ_BUFSIZE, READ_DELIMITER, W, Q, max );
if( sum % 2 || ( max > (sum / 2) ) )
{
printf( "impossible\n" );
return 0;
}
int add = N;
bool possible = false;
for( int i = 0; Q[i].sum != 0 && !possible; i++ )
{
if( Q[i].sum == (sum / 2) )
{
possible = true;
break;
}
for( int j = Q[i].index+1; W[j] !=0; j++ )
{
if( ( Q[i].sum + W[j] ) < (sum / 2) )
{
Q[add].index = j;
Q[add].sum = Q[i].sum + W[j];
//printf( "i=%d add=%d Q[add].sum=%d\n", i, add, Q[add].sum );
add++;
}
else if( ( Q[i].sum + W[j] ) == (sum / 2) )
{
possible = true;
break;
}
}
}
if( possible )
printf( "possible\n" );
else
printf( "impossible\n" );
return 0;
}