Submission #199824

# Submission time Handle Problem Language Result Execution time Memory
199824 2020-02-03T14:38:54 Z Mercenary Flood (IOI07_flood) C++14
33 / 100
101 ms 5756 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 2e5 + 5;
int n , m;
int d[maxn][4];
ii a[maxn];
vector<int> res;
ii b[maxn];

int dir(int x , int y){
    if(a[x].first == a[y].first)return 2 * (a[x].second > a[y].second);
    return 1 + 2 * (a[x].first > a[y].first);
}

bool vis[maxn];

int dfs(int u , int dir){
    if(vis[u] == 1)return u;
    vis[u] = 1;
    for(int i = 1 ; i >= -2 ; --i){
        int cur = (dir + i + 4) % 4;
        if(!d[u][cur])continue;
        int c = d[u][cur];
        int v = b[c].first + b[c].second - u;
        d[u][cur] = d[v][(cur + 2) % 4] = 0;
        int tmp = dfs(v , dir);
        if(!tmp){
            res.pb(c);
            continue;
        }
        if(tmp != u)return vis[u] = 0 , tmp;
    }
    return vis[u] = 0;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    vector<int> val(n);iota(val.begin(),val.end(),1);
    for(int i = 1 ; i <= n ; ++i)cin >> a[i].first >> a[i].second;
    sort(val.begin(),val.end(),[&](int x , int y){return a[x] < a[y];});
    cin >> m;
    for(int i = 1 ; i <= m ; ++i){
        cin >> b[i].first >> b[i].second;
        d[b[i].first][dir(b[i].first,b[i].second)] = i;
        d[b[i].second][dir(b[i].second,b[i].first)] = i;
    }
    for(auto & c : val)dfs(c,2);
    cout << res.size() << '\n';for(auto & c : res)cout << c << '\n';
}

Compilation message

flood.cpp: In function 'int main()':
flood.cpp:55:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
flood.cpp:56:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1888 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 61 ms 5752 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 4344 KB Output is correct
2 Incorrect 100 ms 5756 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 98 ms 5496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 101 ms 5752 KB Output isn't correct
2 Halted 0 ms 0 KB -