Submission #1666040
Source Code Expand
#include <bits/stdc++.h> using namespace std; int n; char s[5000020]; int a[5000020]; int f[5000020]; int main() { scanf("%d", &n); scanf("%s", s + 1); for (int i = 1; i <= n; i++) { if (s[i] == '1') { a[i] = a[i - 1]; } else { a[i] = i; } } for (int i = 1; i <= n; i++) { f[i] = f[i - 1]; if (s[i] == '1') { if (s[i - 1] == '0' && s[i - 2] == '1') { f[i] = max(f[i], f[a[i - 2]] + i - 2 - a[i - 2]); f[i] = max(f[i], f[a[i - 2] + 1] + i - 2 - (a[i - 2] + 1)); } if (s[a[i] - 1] == '1') { f[i] = max(f[i], f[a[i] - 2] + i - a[i]); } } } printf("%d\n", f[n]); return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - 101 to 010 |
User | Factorio |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 650 Byte |
Status | AC |
Exec Time | 9 ms |
Memory | 8448 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:8:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.cpp:9:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s", s + 1); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt |
All | 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, example0.txt, example1.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 4 ms | 7296 KB |
001.txt | AC | 3 ms | 4864 KB |
002.txt | AC | 4 ms | 5248 KB |
003.txt | AC | 3 ms | 4864 KB |
004.txt | AC | 4 ms | 4992 KB |
005.txt | AC | 5 ms | 5248 KB |
006.txt | AC | 3 ms | 4480 KB |
007.txt | AC | 3 ms | 4736 KB |
008.txt | AC | 2 ms | 4352 KB |
009.txt | AC | 6 ms | 7808 KB |
010.txt | AC | 5 ms | 8320 KB |
011.txt | AC | 6 ms | 8320 KB |
012.txt | AC | 7 ms | 8320 KB |
013.txt | AC | 8 ms | 8320 KB |
014.txt | AC | 8 ms | 8320 KB |
015.txt | AC | 9 ms | 8448 KB |
016.txt | AC | 9 ms | 8320 KB |
017.txt | AC | 8 ms | 8320 KB |
018.txt | AC | 8 ms | 8320 KB |
019.txt | AC | 7 ms | 8320 KB |
020.txt | AC | 6 ms | 8320 KB |
021.txt | AC | 6 ms | 8320 KB |
022.txt | AC | 6 ms | 8320 KB |
023.txt | AC | 7 ms | 8320 KB |
024.txt | AC | 7 ms | 8320 KB |
025.txt | AC | 7 ms | 8320 KB |
026.txt | AC | 7 ms | 8320 KB |
027.txt | AC | 7 ms | 8320 KB |
028.txt | AC | 7 ms | 8320 KB |
029.txt | AC | 7 ms | 8320 KB |
030.txt | AC | 7 ms | 8320 KB |
031.txt | AC | 7 ms | 8320 KB |
032.txt | AC | 7 ms | 8320 KB |
033.txt | AC | 7 ms | 8320 KB |
034.txt | AC | 7 ms | 8320 KB |
035.txt | AC | 7 ms | 8320 KB |
036.txt | AC | 7 ms | 8320 KB |
example0.txt | AC | 2 ms | 4352 KB |
example1.txt | AC | 2 ms | 4352 KB |