AtCoder Grand Contest 001

Submission #810011

Source codeソースコード

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

const int INF = 2100000000;

struct segtree
{
	static const int DEPTH = 19;
	static const int N = 1 << DEPTH;
	int val[2 * N];

	segtree() {
		for (int i = 0; i < 2 * N; ++i) val[i] = INF;
	}
	void update(int p, int v) {
		p += N; val[p] = v; p >>= 1;
		while (p) {
			val[p] = min(val[p * 2], val[p * 2 + 1]);
			p >>= 1;
		}
	}
	int query(int L, int R) {
		L += N; R += N;
		int ret = INF;
		while (L < R) {
			if (L & 1) ret = min(ret, val[L++]);
			if (R & 1) ret = min(ret, val[--R]);
			L >>= 1; R >>= 1;
		}
		return ret;
	}
};

segtree seg;
int N, K, P[505050];
bool visited[505050];
int ans[505050], al;

void decide(int idx)
{
	for (;;) {
		int least = seg.query(0, P[idx]);
		if (least >= idx + K) break;
		decide(least);
	}
	ans[idx] = al++;
	visited[idx] = true;
	seg.update(P[idx], INF);
}

int main()
{
	scanf("%d%d", &N, &K);
	for (int i = 0; i < N; ++i) {
		scanf("%d", P + i); --P[i];
		visited[i] = false;
		seg.update(P[i], i);
	}
	al = 0;
	for (int i = 0; i < N; ++i) if (!visited[i]) decide(i);
	for (int i = 0; i < N; ++i) printf("%d\n", ans[i] + 1);
	return 0;
}

Submission

Task問題 F - Wide Swap
User nameユーザ名 semiexp
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 2000
Source lengthソースコード長 1548 Byte
File nameファイル名
Exec time実行時間 459 ms
Memory usageメモリ使用量 27648 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:67:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &K);
^
./Main.cpp:69:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", P + i); --P[i];
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample-01.txt,sample-02.txt,sample-03.txt
All 2000 / 2000 000.txt,001.txt,002.txt,003.txt,004.txt,005.txt,006.txt,007.txt,008.txt,009.txt,010.txt,011.txt,012.txt,013.txt,014.txt,015.txt,016.txt,017.txt,018.txt,019.txt,020.txt,021.txt,022.txt,023.txt,024.txt,025.txt,026.txt,027.txt,028.txt,029.txt,030.txt,031.txt,032.txt,033.txt,034.txt,035.txt,036.txt,037.txt,038.txt,039.txt,040.txt,041.txt,042.txt,043.txt,044.txt,045.txt,046.txt,047.txt,048.txt,049.txt,050.txt,051.txt,052.txt,053.txt,054.txt,055.txt,056.txt,057.txt,058.txt,059.txt,060.txt,061.txt,062.txt,063.txt,064.txt,065.txt,066.txt,067.txt,068.txt,069.txt,070.txt,071.txt,072.txt,073.txt,074.txt,075.txt,076.txt,077.txt,078.txt,079.txt,080.txt,081.txt,082.txt,083.txt,084.txt,085.txt,086.txt,087.txt,088.txt,089.txt,090.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
000.txt AC 10 ms 4352 KB
001.txt AC 10 ms 4352 KB
002.txt AC 10 ms 4352 KB
003.txt AC 10 ms 4352 KB
004.txt AC 10 ms 4352 KB
005.txt AC 10 ms 4352 KB
006.txt AC 10 ms 4352 KB
007.txt AC 10 ms 4352 KB
008.txt AC 10 ms 4352 KB
009.txt AC 11 ms 4352 KB
010.txt AC 11 ms 4352 KB
011.txt AC 11 ms 4352 KB
012.txt AC 11 ms 4352 KB
013.txt AC 11 ms 4352 KB
014.txt AC 11 ms 4352 KB
015.txt AC 11 ms 4352 KB
016.txt AC 11 ms 4352 KB
017.txt AC 11 ms 4352 KB
018.txt AC 11 ms 4352 KB
019.txt AC 12 ms 4352 KB
020.txt AC 11 ms 4352 KB
021.txt AC 10 ms 4352 KB
022.txt AC 11 ms 4352 KB
023.txt AC 11 ms 4352 KB
024.txt AC 11 ms 4352 KB
025.txt AC 11 ms 4352 KB
026.txt AC 11 ms 4352 KB
027.txt AC 11 ms 4352 KB
028.txt AC 10 ms 4352 KB
029.txt AC 11 ms 4352 KB
030.txt AC 11 ms 4352 KB
031.txt AC 11 ms 4352 KB
032.txt AC 11 ms 4352 KB
033.txt AC 11 ms 4352 KB
034.txt AC 13 ms 4352 KB
035.txt AC 12 ms 4352 KB
036.txt AC 11 ms 4352 KB
037.txt AC 11 ms 4352 KB
038.txt AC 11 ms 4352 KB
039.txt AC 411 ms 12032 KB
040.txt AC 438 ms 12032 KB
041.txt AC 416 ms 12032 KB
042.txt AC 427 ms 12032 KB
043.txt AC 435 ms 12032 KB
044.txt AC 408 ms 12032 KB
045.txt AC 459 ms 12032 KB
046.txt AC 412 ms 12032 KB
047.txt AC 429 ms 12032 KB
048.txt AC 443 ms 12032 KB
049.txt AC 189 ms 7552 KB
050.txt AC 232 ms 8576 KB
051.txt AC 211 ms 8064 KB
052.txt AC 373 ms 11264 KB
053.txt AC 75 ms 5760 KB
054.txt AC 281 ms 9472 KB
055.txt AC 12 ms 4352 KB
056.txt AC 57 ms 5248 KB
057.txt AC 216 ms 8064 KB
058.txt AC 62 ms 5248 KB
059.txt AC 373 ms 12032 KB
060.txt AC 411 ms 12032 KB
061.txt AC 415 ms 12032 KB
062.txt AC 413 ms 12032 KB
063.txt AC 431 ms 12032 KB
064.txt AC 411 ms 12032 KB
065.txt AC 433 ms 12032 KB
066.txt AC 407 ms 12032 KB
067.txt AC 429 ms 12032 KB
068.txt AC 414 ms 12032 KB
069.txt AC 377 ms 18944 KB
070.txt AC 373 ms 18944 KB
071.txt AC 369 ms 13568 KB
072.txt AC 340 ms 12032 KB
073.txt AC 371 ms 17152 KB
074.txt AC 340 ms 12032 KB
075.txt AC 362 ms 12032 KB
076.txt AC 361 ms 12032 KB
077.txt AC 369 ms 15104 KB
078.txt AC 372 ms 17280 KB
079.txt AC 108 ms 6528 KB
080.txt AC 24 ms 4992 KB
081.txt AC 42 ms 5120 KB
082.txt AC 189 ms 8960 KB
083.txt AC 68 ms 6528 KB
084.txt AC 68 ms 5632 KB
085.txt AC 56 ms 5376 KB
086.txt AC 23 ms 4736 KB
087.txt AC 108 ms 6656 KB
088.txt AC 79 ms 7680 KB
089.txt AC 316 ms 12032 KB
090.txt AC 393 ms 27648 KB
sample-01.txt AC 11 ms 4352 KB
sample-02.txt AC 11 ms 4352 KB
sample-03.txt AC 10 ms 4352 KB