### A. Choosing a Smartphone

Author: Suhendry Effendy
Prepared By: Suhendry Effendy, Hutomo Widjaja

This is the easiest problem in the contest. Attention please, this specific write up (Problem A) is not intended for any experienced contestants; this problem is easy, any experienced contestants will surely be able to solve this under 5 minutes, 10 minutes at most

Abridge problem statement: given an array of N integers, determine its category (based on the sum of all elements). This problem simply asked you to sum all the elements, and classify the accumulated sum into one of 4 available classes:
```     0 < SUM ≤  16,000 : ANS = 16GB 16,000 < SUM ≤  32,000 : ANS = 32GB 32,000 < SUM ≤  64,000 : ANS = 64GB 64,000 < SUM ≤ 128,000 : ANS = 128GB```

Following is an example of accepted C++ solution for this problem.

```#include <cstdio> int main() { int T; scanf( "%d", &T ); for ( int tc = 1; tc <= T; tc++ ) { int N; int arr[105]; scanf( "%d", &N ); for ( int i = 0; i < N; i++ ) scanf( "%d", &arr[i] ); int sum = 0; for ( int i = 0; i < N; i++ ) sum += arr[i]; printf( "Case #%d: ", tc ); if ( sum <= 16000 ) puts( "16GB" ); if ( 16000 < sum && sum <= 32000 ) puts( "32GB" ); if ( 32000 < sum && sum <= 64000 ) puts( "64GB" ); if ( 64000 < sum && sum <= 128000 ) puts( "128GB" ); } return 0; }```

There were a lot of wrong submissions (from, which I assume, beginner teams) to this problem. Most of them have logic errors in their code. To all beginners (not all these can be applied to experienced team), you should always remember to:

• Follow the EXACT output format. If the problem asked you to output “Case #1:”, then output it exactly, DO NOT output “Case # 1:” or “Case#1:”. Difference in white spaces will cost you a Wrong Answer.
• If you got “No – Wrong Answer”, it simply means your code did not produce the correct output. Do not waste your time by arguing that you have tested your code and they’re correct. The judges have their own test data prepared to test the contestant’s submission. Of course they cannot share this test data with you, it’s secret, but you can be sure that the test data complies 100% with the problem’s constraint. If the problem said that N ≤ 100, then in judge’s test data, N will surely be ≤ 100. This also implies that you don’t need to do any input validation procedure. If you got “No – Wrong Answer”, it means your program did not produce the correct output for the judge’s test data, which means something is wrong in your code.
• The same also applies if you got “No – Runtime Error” or “No – Time Limit Exceed”. Runtime Error (RTE) means your program crashed when run with judge’s test data. Time Limit Exceed (TLE) means your program took longer than allowed time limit to produce the output; in other words, your program is not efficient enough to pass. What is the point of TLE? Imagine if one contestant argue that his code is correct, but you have to wait for 10 hours (or worse, years) for it to produce the output. In worst case, your program caught in infinite loop (you know … halting problem – determining whether a program will terminate – is undecidable). In some problem, we also want the contestant to device an efficient algorithm to solve the problem, e.g. brute-force compared to smart and fast algorithm.
• C++ users, make sure you first compile your code using console (command prompt in Windows or shell in Linux) before submitting. Usually this problem comes from teams who used IDE (e.g., DevC++, Code::Blocks, Microsoft Visual C++, Borland C++ – anyone using this? –, etc.) to code their solution. Your IDE might have different compile option than what is used by the judges (specified on the website: g++ -Wl,-stack=0x4000000 file.cpp -o file). What is the effect? In some cases, IDE can automatically include the needed libraries when you forgot to specify it in your code (#include). If you submit such code, then you might get “No – Compile Error”. Also, it’s better if you have the same compiler version as one used by the judge (we used MinGW 4.4.1). C++ compilers such as VCPP or BC are usually not compatible with MinGW. I understand that this might be confusing for you. But again, learning all these stuffs will help you a lot not only in programming contest, but in your future as programmer as well.

There are 961 submissions have been made for this problem, in which 306 teams managed to get accepted. The first team who solve this problem is Sylph (minute 3) from Bina Nusantara University.

### 27 Responses to “ACM-ICPC INC 2014”

1. “One popular approach was by first sorting all the strings and pair each succesive string whenever possible”, kode saya spt itu, hanya saja pasangkan dr yg terpanjang http://ideone.com/PGjPAq

2. komen untuk prob J

βOne popular approach was by first sorting all the strings and pair each succesive string whenever possibleβ, kode saya spt itu, hanya saja pasangkan dr yg terpanjang http://ideone.com/PGjPAq

• koreksi, prob G

• Ngga, kode kamu nggak seperti itu. Approach kamu itu jadi sama dengan approach greedy yang bener (pasangin dari leaves) — string yang paling panjang saat itu pasti leaf.

Yang dimaksud “pair each succesive string whenever possible” itu comparenya bener-bener cuma sama 1 string di sebelahnya aja (sorted); sedangkan kamu compare dengan yang panjangnya lebih pendek.

3. a bit curious about problem H. Did you use the real Kawal Pemilu data for judge’s test case? π

• According to the author: YES π

• Nice π

4. nice problem, nice editorial, pretty helpful, thx π

5. saya penasaran dgn problem yg blm sempat saya kerjakan (dan AC), apakah mungkin akan diupload ke situs online judge ?

saya dpt ide sederhana utk problem J dgn menelusuri apakah suatu nilai bisa jadi pivot (menjadi ‘L’), setelah itu cek apakah bs dr index tersebut menjadi good segment, jika tidak cetak impossible, kode saya : [[REMOVED]]

thx koreksinya π

• Lho, cara handle mod-nya (line 30, 41 – 43) jelas salah donk? Kenapa cuma consider pivot L yang ga punya pair-mod nya di dalam array input? Yang diminta kan pivot L yang segmentnya ga ada pair-mod nya.

contoh:
6 10
5 2 8 1 9 5

• karena “((SL + Si) mod M) ? 0, for all i where L ? i ? R.”

apakah mksdnya nilai di index L, jika dipasangkan dgn semua nilai dari L sampai R, modnya tdk akan 0 ?

utk input spt itu outputnya impossible bkn ?

• oh, bayangan sy sblmnya, segment L-R, jumlah bilangan yg berbeda harus sama dgn jml bilangan berbeda array 1 – N

• kelihatannya di situ kesalahannya, gara2 asumsi jml bil beda hrs sama dgn array input…

pertama baca merasa ada kemiripan dgn soal spoj DQUERY yg blm sy mengerti jg π

• Ho iya, “value” di soal J ini sama dengan nilai si d-query (number of distinct elements in a segment).

• “for all i where L <= i <= R" -- artinya cuma dipair dengan semua [L, R], bukan [1, N]; [L, R] itu segmentnya.

• permisi, mengganggu lagi :D, saya sdh mencoba membuat NOMOD utk range tertentu

semoga sudah benar :), [[REMOVED]]

hanya saja kompleksitasnya NOMOD tdk O(N) karena menggunakan map, kalau ada unsorted map spt c++ 11, mgkn bs π

membaca tutorial kadang jd pengen kerjain lg, apakah bs diupload soalnya ke OJ ?

• aduh msh ada salah ><, setelah di-fix, smg uda bener [[REMOVED]]

• Oit, maap beberapa hari ini lagi away, baru bisa cek messagenya.

Solusi yang pertama (SbojVj) masih salah, tapi solusi yang kedua (5i1Mvi) AC π

Anyway, soal sedang diupload ke JOJ, sebentar lagi selesai.

• terima kasih banyak π

• Soal INC sudah diupload ke JOJ. Kode soal: INC14A … INC14J

http://jollybee.binus.ac.id/oj/site/problemset/problem/code/INC14A/

• ok pak, terima kasih, di grup fb ada yg minta sekalian saya post ya link-nya π

• oh ya, apa komen saya yg menyertakan kode yg hampir AC dan AC bs diedit link-nya, takutnya dicopas buat JOJ (kalau boleh copas buat JOJ ya tidak diedit tidak apa2)

saya wkt nulis di ideone tdk login waktu itu, jd tdk bs edit kode di ideone

• Sip, udah diremoved semua link ke code nya π

6. How about ACM-ICPC 2014 Jakarta write up?? Will it be published?

• Yes, it will.

I “lost” one week due to other events after ICPC (and I’ve just come back to my home). So, expect a few more days delay π

7. How can I get input data ?

Thank you for sharing.

• Ah… I didn’t notice this comment before >.< I'll not share the input data publicly. You can test your solution in some online-judges, e.g., tokilearning or joj. (I think) I have sent the test data to the admin on those sites.