結果
| 問題 | 
                            No.258 回転寿司(2)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             bal4u
                         | 
                    
| 提出日時 | 2019-08-21 04:06:10 | 
| 言語 | C  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 1,035 bytes | 
| コンパイル時間 | 295 ms | 
| コンパイル使用メモリ | 30,720 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-10-07 03:59:55 | 
| 合計ジャッジ時間 | 3,813 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 67 | 
コンパイルメッセージ
main.c: In function 'in':
main.c:8:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:16:24: note: in expansion of macro 'gc'
   16 |         int n = 0, c = gc();
      |                        ^~
main.c: In function 'out':
main.c:9:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
    9 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:24:21: note: in expansion of macro 'pc'
   24 |         while (i--) pc(b[i]);
      |                     ^~
            
            ソースコード
// yukicoder: No.258 回転寿司(2)
// 2019.8.21 bal4u
#include <stdio.h>
#include <stdlib.h>
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in() { // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}
void out(int n) { // 非負整数の表示(出力)
	int i; char b[30];
	i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
	while (i--) pc(b[i]);
}
int dp[1005], pre[1005];
int ans[1005]; int w = 1000;
void pr(int n) {
	while (n > 0) ans[--w] = n, n = pre[n];
	out(ans[w++]);
	while (ans[w]) pc(' '), out(ans[w++]);
	pc('\n');
}
int main()
{
	int i, j, v, vv, N;
	N = in();
	pre[1] = -1, dp[1] = vv = in();
	for (i = 2; i <= N; i++) {
		v = in();
		if (dp[i-1]-vv < dp[i-2]) pre[i] = i-2, dp[i] = dp[i-2]+v;
		else pre[i] = pre[i-1], dp[i] = dp[i-1]-vv+v;
		vv = v;
	}
	if (dp[N] > dp[N-1]) out(dp[N]), pc('\n'), pr(N);
	else out(dp[N-1]), pc('\n'), pr(N-1);
	return 0;
}
            
            
            
        
            
bal4u