CODE FESTIVAL 2016 Exhibition

Submission #1306098

Source codeソースコード

#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill( x, y ) memset( x, y, sizeof x )
#define copy( x, y ) memcpy( x, y, sizeof x )
using namespace std;

typedef long long LL;
typedef pair < LL, LL > pa;

inline LL read()
{
	LL sc = 0, f = 1; char ch = getchar();
	while( ch < '0' || ch > '9' ) { if( ch == '-' ) f = -1; ch = getchar(); }
	while( ch >= '0' && ch <= '9' ) sc = sc * 10 + ch - '0', ch = getchar();
	return sc * f;
}

const int MAXN = 20005;

int n, ans;
LL a[MAXN], table[20];
vector < pa > f, g;

inline vector < pa > merge(vector < pa > a, vector < pa > b)
{
	vector < pa > ret;
	for( auto x : b ) a.pb( x );
	sort( a.begin(), a.end() );
	LL l = 0, r = 0;
	for( auto t : a )
		if( r < t.xx )
		{
			if( l && r ) ret.pb( mp( l, r ) );
			l = t.xx, r = t.yy;
		}
		else r = max( r, t.yy );
	ret.pb( mp( l, r ) );
	return ret;
}

inline bool cal(int x, int y)
{
	f.clear(); g.clear();
	f.pb( mp( table[ x ] * y, table[ x ] * ( y + 1 ) ) );
	for( int i = 1 ; i <= n ; i++ )
	{
		LL c = a[ i ] % table[ x + 1 ];
		g.clear();
		for( auto t : f )
		{
			if( t.xx <= c && c < t.yy ) return true;
			LL l = ( t.xx - c + table[ x + 1 ] ) % table[ x + 1 ], r = ( t.yy - c + table[ x + 1 ] ) % table[ x + 1 ];
			if( !r ) r = table[ x + 1 ];
			g.pb( mp( l, r ) );
		}
		f = merge( f, g );
	}
	return false;
}

int main()
{
#ifdef wxh010910
	freopen( "data.in", "r", stdin );
#endif
	n = read();
	for( int i = 1 ; i <= n ; i++ ) a[ i ] = read();
	table[ 0 ] = 1;
	for( int i = 1 ; i <= 18 ; i++ ) table[ i ] = table[ i - 1 ] * 10;
	for( int i = 0 ; i < 18 ; i++ )
		for( int j = 9 ; j ; j-- )
			if( cal( i, j ) )
			{
				ans += j;
				break;
			}
	return printf( "%d\n", ans ), 0;
}

Submission

Task問題 B - Exact Payment
User nameユーザ名 wxh010910
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 1500
Source lengthソースコード長 1833 Byte
File nameファイル名
Exec time実行時間 460 ms
Memory usageメモリ使用量 512 KB

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt
All 1500 / 1500 sample-01.txt,sample-02.txt,01-01.txt,01-02.txt,01-03.txt,01-04.txt,01-05.txt,01-06.txt,01-07.txt,01-08.txt,01-09.txt,01-10.txt,01-11.txt,01-12.txt,01-13.txt,01-14.txt,01-15.txt,01-16.txt,01-17.txt,01-18.txt,01-19.txt,01-20.txt,01-21.txt,01-22.txt,01-23.txt,01-24.txt,01-25.txt,01-26.txt,01-27.txt,01-28.txt,01-29.txt,01-30.txt,01-31.txt,01-32.txt,01-33.txt,01-34.txt,01-35.txt,01-36.txt,01-37.txt,01-38.txt,01-39.txt,01-40.txt,01-41.txt,01-42.txt,01-43.txt,01-44.txt,01-45.txt,01-46.txt,01-47.txt,01-48.txt,01-49.txt,01-50.txt,01-51.txt,01-52.txt,01-53.txt,01-54.txt,01-55.txt,01-56.txt,01-57.txt,01-58.txt,01-59.txt,01-60.txt,01-61.txt,01-62.txt,01-63.txt,01-64.txt,01-65.txt,01-66.txt,01-67.txt,01-68.txt,01-69.txt,01-70.txt,01-71.txt,01-72.txt,01-73.txt,01-74.txt,01-75.txt,01-76.txt,01-77.txt,01-78.txt,01-79.txt,01-80.txt,01-81.txt,01-82.txt,01-83.txt,01-84.txt,01-85.txt,01-86.txt,01-87.txt,01-88.txt,01-89.txt,01-90.txt,01-91.txt,01-92.txt,01-93.txt,01-94.txt,01-95.txt,01-96.txt,01-97.txt,01-98.txt,sample-01.txt,sample-02.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 1 ms 256 KB
01-02.txt AC 1 ms 256 KB
01-03.txt AC 1 ms 256 KB
01-04.txt AC 1 ms 256 KB
01-05.txt AC 1 ms 256 KB
01-06.txt AC 72 ms 384 KB
01-07.txt AC 82 ms 384 KB
01-08.txt AC 93 ms 384 KB
01-09.txt AC 113 ms 384 KB
01-10.txt AC 215 ms 384 KB
01-11.txt AC 201 ms 384 KB
01-12.txt AC 82 ms 384 KB
01-13.txt AC 87 ms 384 KB
01-14.txt AC 78 ms 384 KB
01-15.txt AC 88 ms 384 KB
01-16.txt AC 109 ms 384 KB
01-17.txt AC 86 ms 384 KB
01-18.txt AC 87 ms 384 KB
01-19.txt AC 94 ms 384 KB
01-20.txt AC 87 ms 384 KB
01-21.txt AC 87 ms 384 KB
01-22.txt AC 86 ms 384 KB
01-23.txt AC 85 ms 384 KB
01-24.txt AC 96 ms 384 KB
01-25.txt AC 96 ms 384 KB
01-26.txt AC 86 ms 384 KB
01-27.txt AC 79 ms 384 KB
01-28.txt AC 79 ms 384 KB
01-29.txt AC 102 ms 384 KB
01-30.txt AC 85 ms 384 KB
01-31.txt AC 85 ms 384 KB
01-32.txt AC 102 ms 384 KB
01-33.txt AC 102 ms 384 KB
01-34.txt AC 85 ms 384 KB
01-35.txt AC 81 ms 384 KB
01-36.txt AC 96 ms 384 KB
01-37.txt AC 74 ms 384 KB
01-38.txt AC 85 ms 384 KB
01-39.txt AC 87 ms 384 KB
01-40.txt AC 85 ms 384 KB
01-41.txt AC 87 ms 384 KB
01-42.txt AC 85 ms 384 KB
01-43.txt AC 86 ms 384 KB
01-44.txt AC 77 ms 384 KB
01-45.txt AC 75 ms 384 KB
01-46.txt AC 71 ms 384 KB
01-47.txt AC 72 ms 384 KB
01-48.txt AC 71 ms 384 KB
01-49.txt AC 71 ms 384 KB
01-50.txt AC 71 ms 384 KB
01-51.txt AC 69 ms 384 KB
01-52.txt AC 73 ms 384 KB
01-53.txt AC 72 ms 384 KB
01-54.txt AC 70 ms 384 KB
01-55.txt AC 72 ms 384 KB
01-56.txt AC 72 ms 384 KB
01-57.txt AC 71 ms 384 KB
01-58.txt AC 71 ms 384 KB
01-59.txt AC 72 ms 384 KB
01-60.txt AC 71 ms 384 KB
01-61.txt AC 71 ms 384 KB
01-62.txt AC 71 ms 384 KB
01-63.txt AC 71 ms 384 KB
01-64.txt AC 71 ms 384 KB
01-65.txt AC 71 ms 384 KB
01-66.txt AC 460 ms 384 KB
01-67.txt AC 159 ms 384 KB
01-68.txt AC 120 ms 384 KB
01-69.txt AC 124 ms 384 KB
01-70.txt AC 118 ms 384 KB
01-71.txt AC 301 ms 384 KB
01-72.txt AC 291 ms 384 KB
01-73.txt AC 297 ms 384 KB
01-74.txt AC 346 ms 384 KB
01-75.txt AC 381 ms 384 KB
01-76.txt AC 398 ms 384 KB
01-77.txt AC 114 ms 384 KB
01-78.txt AC 283 ms 384 KB
01-79.txt AC 247 ms 384 KB
01-80.txt AC 268 ms 384 KB
01-81.txt AC 251 ms 384 KB
01-82.txt AC 255 ms 384 KB
01-83.txt AC 323 ms 512 KB
01-84.txt AC 315 ms 384 KB
01-85.txt AC 308 ms 384 KB
01-86.txt AC 310 ms 384 KB
01-87.txt AC 316 ms 384 KB
01-88.txt AC 319 ms 384 KB
01-89.txt AC 349 ms 384 KB
01-90.txt AC 90 ms 384 KB
01-91.txt AC 229 ms 384 KB
01-92.txt AC 282 ms 384 KB
01-93.txt AC 268 ms 384 KB
01-94.txt AC 270 ms 384 KB
01-95.txt AC 263 ms 384 KB
01-96.txt AC 86 ms 384 KB
01-97.txt AC 230 ms 384 KB
01-98.txt AC 249 ms 384 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB