QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#184961#3589. Invested MoneyZhou_JKTL 0ms1716kbC++233.2kb2023-09-21 14:58:462023-09-21 14:58:47

Judging History

This is the latest submission verdict.

  • [2023-09-21 14:58:47]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 1716kb
  • [2023-09-21 14:58:46]
  • Submitted

answer

/*
 * i.cpp 2023-09-21
 * Copyright (C) 2023 Woshiluo Luo <[email protected]>
 *
 * 「Two roads diverged in a wood,and I—
 * I took the one less traveled by,
 * And that has made all the difference.」
 *
 * Distributed under terms of the GNU GNU AGPLv3+ license.
 */

#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <vector>
#include <algorithm>

typedef const int cint;
typedef long long ll;
typedef unsigned long long ull;

inline bool isdigit( const char cur ) { return cur >= '0' && cur <= '9'; }/*{{{*/
template <class T> 
T Max( T a, T b ) { return a > b? a: b; }
template <class T> 
T Min( T a, T b ) { return a < b? a: b; }
template <class T> 
void chk_Max( T &a, T b ) { if( b > a ) a = b; }
template <class T> 
void chk_Min( T &a, T b ) { if( b < a ) a = b; }
template <typename T>
T read() { 
	T sum = 0, fl = 1; 
	char ch = getchar();
	for (; isdigit(ch) == 0; ch = getchar())
		if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = sum * 10 + ch - '0';
	return sum * fl;
}
template <class T> 
T pow( T a, int p ) {
	T res = 1;
	while( p ) {
		if( p & 1 ) 
			res = res * a;
		a = a * a;
		p >>= 1;
	}
	return res;
}/*}}}*/

char weekdays[7][5] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };

int check_weekday( char readin[] ) {
	for( int i = 0; i < 7; i ++ ) {
		if( strcmp( weekdays[i], readin ) == 0 ) 
			return i;
	}
	std::exit(-1);
}

int main() {
#ifdef woshiluo
	freopen( "i.in", "r", stdin );
	freopen( "i.out", "w", stdout );
#endif

	int n;
	static char readin[10];
	scanf( "%s%d", readin, &n );

	int ans = 40;
	cint today = check_weekday(readin);
	for( int i = 1; i <= n; i ++ ) {
		int cur = read<int>();
		if( cur == 0 ) {
			int nxt = ( today + 30 ) % 7;
			int res = 30;
			if( nxt == 5 ) 
				res += 2;
			if( nxt == 6 ) 
				res ++;
			chk_Min( ans, res );
			continue;
		}
		int pre = ( ( ( today -  cur ) % 7 ) + 7 ) % 7;
		while( cur != 0 && cur >= 30 ) {/*{{{*/
			if( pre == 2 ) {
				cur -= 30;
				pre = 4;
				continue;
			}
			if( pre == 4 ) {
				cur -= 30;
				pre = 6;
				continue;
			}
			if( pre == 1 ) {
				cur -= 30;
				pre = 3;
				continue;
			}
			if( pre == 3 ) {
				cur -= 30;
				pre = 5;
				continue;
			}
			if( pre == 5 ) {
				cur --;
				pre = 6;
				continue;
			}
			if( pre == 6 ) {
				cur --;
				pre = 0;
				continue;
			}
		}/*}}}*/
		if( pre == 0 ) {
			cur %= 91;
		}
		while( cur >= 30 ) {/*{{{*/
			if( pre == 0 ) {
				cur -= 30;
				pre = 2;
				continue;
			}
			if( pre == 2 ) {
				cur -= 30;
				pre = 4;
				continue;
			}
			if( pre == 4 ) {
				cur -= 30;
				pre = 6;
				continue;
			}
			if( pre == 1 ) {
				cur -= 30;
				pre = 3;
				continue;
			}
			if( pre == 3 ) {
				cur -= 30;
				pre = 5;
				continue;
			}
			if( pre == 5 ) {
				cur --;
				pre = 6;
				continue;
			}
			if( pre == 6 ) {
				cur --;
				pre = 0;
				continue;
			}
		}/*}}}*/

		int res = ( 30 - cur ) % 30;
		cint nxt = ( today + res ) % 7;
		if( nxt == 5 ) 
			res += 2;
		if( nxt == 6 ) 
			res ++;

		chk_Min( ans, res );
	}

	printf( "%d\n", ans );
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 1716kb

input:

Sat 5
5 4 3 1 1

output:

25

result:

ok single line: '25'

Test #2:

score: -100
Time Limit Exceeded

input:

Fri 91
60 86 79 109 74 120 50 105 121 15 80 24 52 127 57 4 9 102 93 91 46 122 22 8 21 31 67 81 95 88 115 43 78 37 128 28 38 112 99 130 106 49 116 39 108 119 16 84 18 129 114 10 44 123 113 45 29 14 72 23 87 126 56 77 58 30 51 63 70 101 100 7 92 107 64 85 53 25 98 17 71 35 66 32 73 65 94 42 36 59 11

output:


result: