Japan Alumni Group Summer Camp 2013 Warming Up

Submission #813934

Source codeソースコード

#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

int n,m;

using state=pair<int,int>;
vector<state> ary;

const int nmax=200000;

int s[nmax],t[nmax];
int nxt[nmax][20];

int main(void){
	cin >> n >> m;
	rep(i,n){
		cin >> s[i] >> t[i];
		if(s[i]>t[i]) t[i]+=m;
		s[n+i]=s[i]+m;
		t[n+i]=t[i]+m;
	}

	const int all=2*n;
	rep(i,all){
		ary.push_back(state(t[i],i));
		ary.push_back(state(s[i],all+i));
	}

	sort(_all(ary));

	int last=-1;

	rrep(i,2*all){
		int id=ary[i].second;
		if(id<all){
			nxt[id][0]=last;
		}else{
			id-=all;
			if(last==all || t[last]>t[id]) last=id;
		}
	}

	rep(k,20)rep(i,all){
		if(nxt[i][k]<0)
			nxt[i][k+1]=-1;
		else
			nxt[i][k+1]=nxt[nxt[i][k]][k];
	}

	int ans=0;

	rep(i,n){
		int cur=i,num=0;
		rrep(k,20){
			int tar=nxt[cur][k];
			if(tar>=0 && t[tar]<=s[i]+m){
				cur=tar;
				num|=1<<k;
			}
		}
		chmax(ans,num+1);
	}

	cout << ans << endl;
	return 0;
}

Submission

Task問題 A - Anime Master
User nameユーザ名 074_Hec
Created time投稿日時
Language言語 C++11 (GCC 4.8.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 1854 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
All 0 / 100 1,10,11,12,13,14,15,16,17,18,19,2,20,21,22,23,24,25,26,27,28,29,3,30,31,32,33,34,35,36,37,38,39,4,40,41,42,43,44,45,46,47,48,49,5,50,51,52,53,54,55,56,57,58,59,6,60,61,62,63,64,65,66,67,68,69,7,70,71,72,73,74,75,76,77,78,79,8,80,81,82,83,84,85,86,87,88,89,9

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
1 WA
10 WA
11 WA
12 WA
13 WA
14 WA
15 WA
16 WA
17 WA
18 WA
19 WA
2 WA
20 WA
21 WA
22 WA
23 WA
24 WA
25 WA
26 WA
27 WA
28 WA
29 WA
3 AC 24 ms 880 KB
30 WA
31 WA
32 WA
33 WA
34 WA
35 WA
36 WA
37 WA
38 WA
39 WA
4 AC 26 ms 876 KB
40 WA
41 WA
42 WA
43 WA
44 WA
45 WA
46 WA
47 WA
48 AC 24 ms 928 KB
49 WA
5 WA
50 WA
51 WA
52 WA
53 AC 26 ms 924 KB
54 WA
55 WA
56 WA
57 WA
58 WA
59 WA
6 AC 27 ms 872 KB
60 AC 270 ms 21312 KB
61 WA
62 WA
63 WA
64 WA
65 WA
66 WA
67 WA
68 WA
69 WA
7 WA
70 WA
71 WA
72 WA
73 WA
74 WA
75 WA
76 WA
77 WA
78 WA
79 WA
8 WA
80 WA
81 WA
82 WA
83 WA
84 WA
85 WA
86 WA
87 WA
88 WA
89 WA
9 WA