1 # include < stdio.h> 2 # include < string.h> 3 4 int main (){ 5 char str [222]; 6 scanf ("%s", str ); 7 int n= strlen ( str ); 8 for ( int i=n -2; i

Similar documents
AtCoder Regular Contest 073 Editorial Kohei Morita(yosupo) A: Shiritori if python3 a, b, c = input().split() if a[len(a)-1] == b[0] and b[len(

25 II :30 16:00 (1),. Do not open this problem booklet until the start of the examination is announced. (2) 3.. Answer the following 3 proble

B : Find Symmetries (A, B) (A + 1, B + 1) A + 1 B + 1 N + k k (A, B) (0, 0), (0, 1),..., (0.N 1) N O(N 2 ) N O(N 3 ) 2

diverta 2019 Programming Contest camypaper For International Readers: English editorial starts on page 8. A: Consecutive Integers K 1 N K +

h23w1.dvi

B: flip / 2 k l k(m l) + (N k)l k, l k(m l) + (N k)l = K O(NM) O(N) 2

Page 1 of 6 B (The World of Mathematics) November 20, 2006 Final Exam 2006 Division: ID#: Name: 1. p, q, r (Let p, q, r are propositions. ) (10pts) (a

M-SOLUTIONS writer: yokozuna A: Sum of Interior Angles For International Readers: English editorial starts on page 7. N 180(N 2) C++ #i n

L3 Japanese (90570) 2008

2


はじめに

L1 What Can You Blood Type Tell Us? Part 1 Can you guess/ my blood type? Well,/ you re very serious person/ so/ I think/ your blood type is A. Wow!/ G

open / window / I / shall / the? something / want / drink / I / to the way / you / tell / the library / would / to / me

untitled

西川町広報誌NETWORKにしかわ2011年1月号

x p v p (x) x p p-adic valuation of x v 2 (8) = 3, v 3 (12) = 1, v 5 (10000) = 4, x 8 = 2 3, 12 = 2 2 3, = 10 4 = n a, b a

T rank A max{rank Q[R Q, J] t-rank T [R T, C \ J] J C} 2 ([1, p.138, Theorem 4.2.5]) A = ( ) Q rank A = min{ρ(j) γ(j) J J C} C, (5) ρ(j) = rank Q[R Q,

C. S2 X D. E.. (1) X S1 10 S2 X+S1 3 X+S S1S2 X+S1+S2 X S1 X+S S X+S2 X A. S1 2 a. b. c. d. e. 2


™…

1 ( 8:12) Eccles. 1:8 2 2

超初心者用

elemmay09.pub

126 学習院大学人文科学論集 ⅩⅩⅡ(2013) 1 2

Microsoft Word - Win-Outlook.docx



戦争詩人たちの「死」と「大地」(1) : Brooke とGrenfell について

24 Depth scaling of binocular stereopsis by observer s own movements

AN 100: ISPを使用するためのガイドライン

AGC 034 yosupo, sigma For International Readers: English editorial starts on page 8. 1

「プログラミング言語」 SICP 第4章 ~超言語的抽象~ その6


1 Fig. 1 Extraction of motion,.,,, 4,,, 3., 1, 2. 2.,. CHLAC,. 2.1,. (256 ).,., CHLAC. CHLAC, HLAC. 2.3 (HLAC ) r,.,. HLAC. N. 2 HLAC Fig. 2

LC304_manual.ai

soturon.dvi

MEET 270

What s your name? Help me carry the baggage, please. politeness What s your name? Help me carry the baggage, please. iii

A5 PDF.pwd

浜松医科大学紀要

How to read the marks and remarks used in this parts book. Section 1 : Explanation of Code Use In MRK Column OO : Interchangeable between the new part

SPSS


アンケート2

How to read the marks and remarks used in this parts book. Section 1 : Explanation of Code Use In MRK Column OO : Interchangeable between the new part

How to read the marks and remarks used in this parts book. Section 1 : Explanation of Code Use In MRK Column OO : Interchangeable between the new part

Microsoft Word - j201drills27.doc

How to read the marks and remarks used in this parts book. Section 1 : Explanation of Code Use In MRK Column OO : Interchangeable between the new part

NO

CONTENTS Public relations brochure of Higashikawa November No.745 Higashikawa 215 November 2

On the Wireless Beam of Short Electric Waves. (VII) (A New Electric Wave Projector.) By S. UDA, Member (Tohoku Imperial University.) Abstract. A new e

P

Quiz 1 ID#: Name: 1. p, q, r (Let p, q and r be propositions. Determine whether the following equation holds or not by completing the truth table belo


Microsoft Word - j201drills27.doc

null element [...] An element which, in some particular description, is posited as existing at a certain point in a structure even though there is no

joho09.ppt

ohp03.dvi

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

S1Šû‘KŒâ‚è


第16回ニュージェネレーション_cs4.indd

4.1 % 7.5 %

fx-9860G Manager PLUS_J


Vol92.indd

PowerPoint Presentation

2 236


Literacy 2 Mathematica Mathematica 3 Hiroshi Toyoizumi Univ. of Aizu REFERENCES [1] C.P Williams [2] [3] 1 Literacy 2 Mathematica Ma

先端社会研究 ★5★号/4.山崎


VE-GP32DL_DW_ZA

高2SL高1HL 文法後期後半_テキスト-0108.indd

Motivation and Purpose There is no definition about whether seatbelt anchorage should be fixed or not. We tested the same test conditions except for t

,,,,., C Java,,.,,.,., ,,.,, i


国際恋愛で避けるべき7つの失敗と解決策

How to read the marks and remarks used in this parts book. Section 1 : Explanation of Code Use In MRK Column OO : Interchangeable between the new part

RX600 & RX200シリーズ アプリケーションノート RX用仮想EEPROM


Read the following text messages. Study the names carefully. 次のメッセージを読みましょう 名前をしっかり覚えましょう Dear Jenny, Iʼm Kim Garcia. Iʼm your new classmate. These ar

lagged behind social progress. During the wartime Chonaikai did cooperate with military activities. But it was not Chonaikai alone that cooperated. Al

平成 31 年度 筑波大学大学院博士課程 システム情報工学研究科 コンピュータサイエンス専攻 博士前期課程 ( 一般入学試験 8 月期 ) 試験問題基礎科目 ( 数学, 情報基礎 ) Mathematics/Fundamentals of Computer Science [ 注意事項 ][Inst


日本語教育紀要 7/pdf用 表紙

16_.....E...._.I.v2006



Level 3 Japanese (90570) 2011

Kyushu Communication Studies 第2号

GP05取説.indb

JOURNAL OF THE JAPANESE ASSOCIATION FOR PETROLEUM TECHNOLOGY VOL. 66, NO. 6 (Nov., 2001) (Received August 10, 2001; accepted November 9, 2001) Alterna

WASEDA RILAS JOURNAL 1Q84 book1 book One Piece

Hospitality-mae.indd

„h‹¤.05.07

Anl_MonzaJAP.indd

1 2 3

n 2 n (Dynamic Programming : DP) (Genetic Algorithm : GA) 2 i

Transcription:

ABC066 / ARC077 writer: nuip 2017 7 1 For International Readers: English editorial starts from page 8. A : ringring a + b b + c a + c a, b, c a + b + c 1 # include < stdio.h> 2 3 int main (){ 4 int a, b, c; 5 scanf ("%d %d %d", &a, &b, &c); 6 int max =a; 7 if(b>max ) max =b; 8 if(c>max ) max =c; 9 printf ("%d\n", a+b+c-max ); 10 return 0; 11 } B : ss S 2 S 4 1

1 # include < stdio.h> 2 # include < string.h> 3 4 int main (){ 5 char str [222]; 6 scanf ("%s", str ); 7 int n= strlen ( str ); 8 for ( int i=n -2; i; i -=2) { 9 if( strncmp (str, str +i/2, i /2) ==0) { 10 printf ("%d\n",i); 11 return 0; 12 } 13 } 14 return 0; 15 } C : pushpush (O(n 2 )) a i 1. i n a i 2. i n a i C++ stl::deque C 1 # include < stdio.h> 2 3 int array [512345]; 2

4 int a [212345]; 5 6 int main (){ 7 int n; 8 scanf ("%d", &n); 9 for ( int i =0; i<n; ++i) scanf ("%d", &a[i]); 10 int left =212345, right = left +1; 11 for ( int i =0; i<n; ++i){ 12 if(i%2 == (n -1) %2) { 13 array [left - -]=a[i]; 14 } else { 15 array [ right ++]= a[i]; 16 } 17 } 18 for ( int i= left +1; i< right ; ++i){ 19 printf ("%d ",array [i]); 20 } 21 return 0; 22 } D : 11 n n + 1 1 1 1 n + 1 k n+1 C k 1 n+1 C k 1 2 23145167 1 : 3

1 1 256 23145167 1 2 211 23145167 1 2 1 1 4, 5 1 1 1 51 23145167 1 1 2 1 1 4, 5 1 31 23145167? 23145167? a l, a r (l < r) a l a r a l a r k 1 a l a r a l l 1 a r n r l 1+n r C k 1 k n+1 C k l 1+n r C k 1 nc k ABC042/ARC058 D http://arc058.contest.atcoder.jp/data/arc/058/editorial.pdf E : guruguru A B A B B A A > B B + N A (B + N A)%N x%y x y 4

1 + (B + N X)%N (B + N A)%N a i a i+1 a i+1 x x x + 1 a i+1 = x i 1 (a i+1 + N a i )%N a i a i+1 x i 1 a i+1 = x i (a i+1 + N a i )%N 1 a i a i+1 x i a i a i+1 x i O(n + m) imos a i+1 = x i n x = 0 x = i x = i + 1 x F : SS f A,B,C 1 ABCABC 2 ABCABC?? 5

AB BC 2k S 1 S 2... S n S 1 S 2... S k S k+1... S n X 1 X 2... X 2k S n k S k + 1 S k X 1 X 2... X 2k S k 2k 2 f(s) S k S n S n abc 3 abcabcabc S 2 S g g g(s) 2 = f(s 2) g(s) g(s) f(s) f 10100 (S) g 10100 (S) g S x S x T n S T T S = T n + T x S S = T n f(s 2) = f(t 2n) = T (2n + 2) g(t n) = T (n + 1) g(s) S + x g(s) = T n + T + T 2 (X 1 X 2... X n ) = (S n k+1 S n k+2... S n S 1 S 2... S k ) 6

x T n+t +T T n+t g g 2 (S) = g(t n + T + T ) = (T n + T + T ) + (T n + T ) = g(s) + S S g n+2 (S) = g n+1 (S) + g n (S) c g n (S) i c 7

ABC066 / ARC077 Editorial writer: nuip July 1st, 2017 A : ringring 1 # include < stdio.h> 2 3 int main (){ 4 int a, b, c; 5 scanf ("%d %d %d", &a, &b, &c); 6 int max =a; 7 if(b>max ) max =b; 8 if(c>max ) max =c; 9 printf ("%d\n", a+b+c-max ); 10 return 0; 11 } 1

B : ss 1 # include < stdio.h> 2 # include < string.h> 3 4 int main (){ 5 char str [222]; 6 scanf ("%s", str ); 7 int n= strlen ( str ); 8 for ( int i=n -2; i; i -=2) { 9 if( strncmp (str, str +i/2, i /2) ==0) { 10 printf ("%d\n",i); 11 return 0; 12 } 13 } 14 return 0; 15 } 2

C : pushpush You can observe that a i are appended to the beginning or the end, alternately. The last element (a n ) will be appended to the beginning. Therefore, we start from an empty sequence, and in the order a 1,..., a n, 1. If i and n have the same parity, append a i to the beginning of the sequence. 2. If i and n have different parities, append a i to the end of the sequence. This can be implemented in O(n) with a deque. 3

D : 11 There are ( ) n+1 k ways to choose k elements from the sequence, but this way we may count the same subsequence multiple times. For example, consider the following case: 23145167 Fix a subsequence s of this sequence. How many times will s be counted? We can observe that: If s contains two 1s, the positions can be uniquely determined and it will be counted only once. If s contains no 1, the positions can be uniquely determined and it will be counted only once. If s contains 4 or 5, the positions can be uniquely determined and it will be counted only once. Otherwise, we can t determine which 1 we chose; it will be counted twice. So, we must subtract the number of ways to choose k 1 elements from 2, 3, 6, 7. In general, if the distance between two elements of the same value is d, the answer is ( ) ( n+1 k n d k 1). 4

E : guruguru Let f(s, t, x) be the number of buttons we must push to change the brightness from s to t, when the favorite brightness is set to x. First consider the following slow solution. We have an array c of length m. Initially all values are zeroes. Then, for each i and x, we add f(a i, a i+1, x) to c[x]. The answer is the minimum value in the sequence c. How can we improve this solution? We want to do this efficiently for a fixed i. Let s fix i, and let s = a i, t = a i+1. Assume that s < t (the other case can be handled similarly). If x s, f(s, t, x) = t s. If s < x t, f(s, t, x) = t x + 1. If t < x, f(s, t, x) = t s. Notice that in all three cases, the value of f is a linear function of x. Thus, we can solve this problem by adding O(N) linear functions to given ranges of c. This can be done by two prefix sums: one for linear part and one for constant part. 5

F : SS Suppose that initially we have a string of length 2n. S 1 S 2... S n S 1 S 2... S n Can we make it an even string by appending 2k characters? S 1 S 2... S n S 1 S 2... S k S k+1... S n X 1 X 2... X 2k From this, you see that the first n k characters of S 1 S 2... S n and the last n k characters of S 1 S 2... S n must be the same. It means that S 1 S 2... S n has a period of k. In general, f(ss) = ST ST, where T is the first k characters of S, where k is the shortest period of S. Let s define g(s) = ST, where T is defined in the same way. We can prove the following: If g(s) = ST and T is a divisor of S, g(st ) = ST T. If g(s) = ST and T is not a divisor of S, g(st ) = ST S. By repeating this, we get: If g(s) = ST and T is a divisor of S, g (S) = ST T T T T... If g(s) = ST and T is not a divisor of S, g i+2 (S) = g i+1 (S) + g i (S) for each i. The remaining part is not very hard. Note that in the actual implementation you don t need to consider the first case: you get the same value for g (ST ) from the second case anyway. === Sketch of the proof for the second case (the first case is easy). Suppose that S = T n + T where n is a positive integer, T is the shortest period of S, and T is a non-trivial prefix of T. We want to prove that the shortest period of g(s) = T n + T + T is T n + T. Assume that there exists a shorter period x < t n + T. 6

If x T (mod T ) and x < t n + T, we can prove that T has a period of gcd( T, x T ). Thus, S also has a period of gcd( T, x T ), and it contradicts the fact that the shortest period of S is T. Otherwise, x 0 (mod T ) and x t (n 1) + T. In this case we can prove that S has a period of gcd( T, x), and again we get a contradiction. 7