Submission #918258

# Submission time Handle Problem Language Result Execution time Memory
918258 2024-01-29T13:52:27 Z devkudawla Lightning Rod (NOI18_lightningrod) C++17
14 / 100
264 ms 174716 KB
#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

//----------------------------------------------------
void solve()
{
    int n;
    n = read_int();
    vector<pair<int, int>> v(n);
    int answer = 0;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        a = read_int();
        b = read_int();
        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++;
        }
    }
    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:120:13: warning: unused variable 'a' [-Wunused-variable]
  120 |         int a = v[i].first, b = v[i].second;
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 176 ms 76376 KB Output is correct
2 Correct 198 ms 76132 KB Output is correct
3 Correct 171 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 210 ms 78428 KB Output is correct
2 Correct 264 ms 174716 KB Output is correct
3 Correct 246 ms 170680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 176 ms 76376 KB Output is correct
2 Correct 198 ms 76132 KB Output is correct
3 Correct 171 ms 74076 KB Output is correct
4 Incorrect 0 ms 344 KB Output isn't correct
5 Halted 0 ms 0 KB -