結果

問題 No.327 アルファベット列
ユーザー Ysmr_Ry
提出日時 2016-03-03 20:25:43
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 875 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 38,144 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-06 23:05:00
合計ジャッジ時間 1,827 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:24:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |         scanf( "%lld", &N );
      |         ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

// yukicoder 327 (http://yukicoder.me/problems/904)
#include<cstdio>
#include<vector>
#define repd(i,a) for(int i=(a);i>=0;--i)

typedef long long ll;

ll N;

std::vector<ll> ts, vs;

ll powLL( ll x, ll n )
{
	ll ret = 1;

	for( ll i = 0; i < n; ++i )
		ret *= x;

	return ret;
}

int main()
{
	scanf( "%lld", &N );

	if( N <= 25 )
	{ putchar( 'A'+N ); puts(""); return 0; }	

	N -= 26;

	ll t = N;
	while( t > 0 )
		ts.push_back( t%26 ), t /= 26;

	if( ts.size() >= 3 ) repd( i, ts.size()-1 ) if( i >= 2 )
	{
		if( ts.size() >= 4 && i == ts.size()-1 && !ts[i-1] )
			continue;
		
		N -= powLL( 26, i );
	}

	while( N > 0 )
		vs.push_back( N%26 ), N /= 26;

	if( !( ts.size()>=4 && ts[ts.size()-1] == 1 && ts[ts.size()-2] == 0 ) ) while( vs.size() < 2 || vs.size() < ts.size() )
			vs.push_back( 0 );

	repd( i, vs.size()-1 )
		putchar( 'A'+vs[i] );

	puts("");

	return 0;
}
0