Submission #3408707
Source Code Expand
/*input 7 1011101 50 10101000010011011110001001111110000101010111100110 8 101010101 */ #include <bits/stdc++.h> #define re(i,n) for(int i=0;i<n;++i) #define rep(i,l,r) for(int i=l;i<=r;i++) #define red(i,r,l) for(int i=r;i>=l;i--) #define db(x) cout<<#x<<"="<<(x)<<" " #define el cout<<endl using namespace std; const int MXN = 500010, MXM = 500010, mol = 1e9 + 7; int N; string str; int f[MXN][2]; std::vector<int> ve; int main() { scanf("%d", &N); cin >> str; str += "00"; int ans = 0, t = 0, s = 0; for (int i = 0; i < N + 2; ++i) { if (str[i] == '1') { t++; } else { if (t == 0) { //el; if (ve.size() > 1) { f[0][1] = ve[0]; f[0][0] = 0; for (int k = 1; k < ve.size(); ++k) { if (ve[k - 1] > 1) { f[k][1] = f[k - 1][0] + ve[k]; } else { if (k == 1) f[k][1] = ve[k]; else f[k][1] = f[k - 2][0] + ve[k]; } f[k][0] = f[k - 1][1]; } ans += max(f[ve.size() - 1][0], f[ve.size() - 1][1]); } s = 0; ve.clear(); } else { ve.push_back(t); /* db(t), db(f[0]), db(f[1]), el; int x = f[1]; if (t == 1) { f[1] = f[0]; } else { f[1] = max(f[1], f[0] + t); f[0] = x; } */ s = t; t = 0; } } } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - 101 to 010 |
User | Laurant |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1965 Byte |
Status | WA |
Exec Time | 21 ms |
Memory | 900 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:23:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &N); ^
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | 10 ms | 644 KB |
001.txt | WA | 6 ms | 640 KB |
002.txt | WA | 10 ms | 644 KB |
003.txt | WA | 6 ms | 640 KB |
004.txt | WA | 8 ms | 640 KB |
005.txt | WA | 11 ms | 644 KB |
006.txt | WA | 3 ms | 384 KB |
007.txt | WA | 6 ms | 512 KB |
008.txt | WA | 2 ms | 256 KB |
009.txt | WA | 14 ms | 900 KB |
010.txt | AC | 17 ms | 900 KB |
011.txt | WA | 19 ms | 900 KB |
012.txt | WA | 19 ms | 900 KB |
013.txt | WA | 20 ms | 900 KB |
014.txt | WA | 21 ms | 900 KB |
015.txt | WA | 21 ms | 900 KB |
016.txt | WA | 21 ms | 900 KB |
017.txt | WA | 20 ms | 900 KB |
018.txt | WA | 19 ms | 900 KB |
019.txt | WA | 19 ms | 900 KB |
020.txt | AC | 18 ms | 900 KB |
021.txt | AC | 18 ms | 900 KB |
022.txt | AC | 18 ms | 900 KB |
023.txt | WA | 18 ms | 900 KB |
024.txt | WA | 20 ms | 900 KB |
025.txt | WA | 18 ms | 900 KB |
026.txt | WA | 18 ms | 900 KB |
027.txt | WA | 18 ms | 900 KB |
028.txt | WA | 18 ms | 900 KB |
029.txt | WA | 18 ms | 900 KB |
030.txt | WA | 18 ms | 900 KB |
031.txt | WA | 18 ms | 900 KB |
032.txt | WA | 18 ms | 900 KB |
033.txt | WA | 18 ms | 900 KB |
034.txt | WA | 18 ms | 900 KB |
035.txt | WA | 18 ms | 900 KB |
036.txt | WA | 18 ms | 900 KB |
example0.txt | AC | 1 ms | 256 KB |
example1.txt | AC | 1 ms | 256 KB |