#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order(it return an iterator input is a value), order_of_key(input is index)
typedef tree<long long, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
template <class T>
void Distinct(T &v, bool sorting = true)
{
if (sorting)
sort(begin(v), end(v));
v.resize(unique(begin(v), end(v)) - begin(v));
}
const int BUF_SZ = 1 << 15;
inline namespace Input
{
char buf[BUF_SZ];
int pos;
int len;
char next_char()
{
if (pos == len)
{
pos = 0;
len = (int)fread(buf, 1, BUF_SZ, stdin);
if (!len)
{
return EOF;
}
}
return buf[pos++];
}
int read_int()
{
int x;
char ch;
int sgn = 1;
while (!isdigit(ch = next_char()))
{
if (ch == '-')
{
sgn *= -1;
}
}
x = ch - '0';
while (isdigit(ch = next_char()))
{
x = x * 10 + (ch - '0');
}
return x * sgn;
}
} // namespace Input
inline namespace Output
{
char buf[BUF_SZ];
int pos;
void flush_out()
{
fwrite(buf, 1, pos, stdout);
pos = 0;
}
void write_char(char c)
{
if (pos == BUF_SZ)
{
flush_out();
}
buf[pos++] = c;
}
void write_int(int x)
{
static char num_buf[100];
if (x < 0)
{
write_char('-');
x *= -1;
}
int len = 0;
for (; x >= 10; x /= 10)
{
num_buf[len++] = (char)('0' + (x % 10));
}
write_char((char)('0' + x));
while (len)
{
write_char(num_buf[--len]);
}
write_char('\n');
}
// auto-flush output when program exits
void init_output() { assert(atexit(flush_out) == 0); }
} // namespace Output
const int sz = 10000010;
const int sz1 = 10000010;
int Fenwick[sz] = {0};
int Fenwick1[sz1] = {0};
//----------------------------------------------------
void solve()
{
int n;
// n = read_int();
cin >> n;
vector<pair<int, int>> v(n);
int answer = 0;
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
v[i] = {a, b};
}
for (int i = 0; i < n; i++)
{
int a = v[i].first, b = v[i].second;
if (b == 1)
answer++;
else
{
bool f = 0;
if (i)
f |= (v[i - 1].second == 1);
if (i + 1 < n)
f |= (v[i + 1].second == 1);
if (!f)
answer++;
}
}
cout << answer;
// write_int(answer);
}
//----------------------------------------------------
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// init_output();
solve();
return 0;
}
//----------------------------------------------------
Compilation message
lightningrod.cpp: In function 'void solve()':
lightningrod.cpp:124:13: warning: unused variable 'a' [-Wunused-variable]
124 | int a = v[i].first, b = v[i].second;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1030 ms |
76120 KB |
Output is correct |
2 |
Correct |
1109 ms |
76120 KB |
Output is correct |
3 |
Correct |
1020 ms |
74076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1354 ms |
78432 KB |
Output is correct |
2 |
Correct |
1178 ms |
78172 KB |
Output is correct |
3 |
Correct |
1146 ms |
76476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1030 ms |
76120 KB |
Output is correct |
2 |
Correct |
1109 ms |
76120 KB |
Output is correct |
3 |
Correct |
1020 ms |
74076 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |