Submission #1690886
Source Code Expand
import std.stdio, std.conv, std.string, std.container, std.typecons, std.algorithm; alias Tuple!(int,int) dat; int AlgoA(int N, int [] A, string S) { int cnt = 0; foreach(i;S) { if(i == 'M') cnt++; } BinaryHeap!(Array!dat) hq; foreach(i;0..cnt) { hq.insert(dat(A[i],i)); } int res = 100_000; foreach(i;cnt..N) { hq.insert(dat(A[i],i)); dat t; while(hq.front()[1] < i-cnt) hq.removeFront(); res = min(res, hq.front()[0]); } return res; } int AlgoB(int N, int [] A, string S) { dat [] tmp; foreach(i;0..N) { tmp ~= dat(A[i],i); } auto hq = heapify(tmp); while(hq.length()) { dat t = hq.front(); if( (t[1]!=0 && A[t[1]-1] > t[0]) && (t[1] != N-1 && A[t[1]+1] > t[0]) ) { A[t[1]] = min(A[t[1]-1], A[t[1]+1]); } hq.removeFront(); } if(N % 2 == 1) { return A[N/2]; } else { return max(A[N/2],A[N/2-1]); } } void main() { int N = to!int(readln().chomp()); int [] A; A = readln().chomp().split().to!(int[]); auto hq = heapify(A); string S = readln().chomp(); int cnt = 0; foreach(i;1..(N-1)) { if(S[i] != S[i-1]) cnt++; } if(cnt == 1 && S[0]=='M') { writeln(AlgoA(N,A,S)); } else if(cnt == N-2 && S[0]=='M') { writeln(AlgoB(N,A,S)); } else { writeln("not implemented"); } }
Submission Info
Submission Time | |
---|---|
Task | B - Compression |
User | konjo |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1305 Byte |
Status | CE |
Compile Error
./Main.cpp:11:12: error: too many decimal points in number foreach(i;0..cnt) { ^ ./Main.cpp:26:12: error: too many decimal points in number foreach(i;0..N) { ^ ./Main.cpp:52:12: error: too many decimal points in number foreach(i;1..(N-1)) { ^ ./Main.cpp:1:1: error: ‘import’ does not name a type import std.stdio, std.conv, std.string, std.container, std.typecons, std.algorithm; ^ ./Main.cpp:3:1: error: ‘alias’ does not name a type alias Tuple!(int,int) dat; ^ ./Main.cpp:5:25: error: expected ‘,’ or ‘...’ before ‘A’ int AlgoA(int N, int [] A, string S) { ^ ./Main.cpp: In function ‘int AlgoA(int, int*)’: ./Main.cpp:7:10: error: ‘i’ was not declared in this scope foreach(i;S) { ^ ./Main.cpp:7:12: error: ‘S’ was not declared in this scope foreach(i;S) { ^ ./Main.cpp:10:2: error: ‘BinaryHeap’ was not declared in this scope BinaryHeap!(Array!dat) hq; ^ ./Main.cpp:11:11: error: expected ‘)’ before ‘;’ token ...