Submission #199823

#TimeUsernameProblemLanguageResultExecution timeMemory
199823MercenaryFlood (IOI07_flood)C++14
Compilation error
0 ms0 KiB
#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'; } #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 (stderr)

flood.cpp:87:11: error: redefinition of 'const int maxn'
 const int maxn = 2e5 + 5;
           ^~~~
flood.cpp:17:11: note: 'const int maxn' previously defined here
 const int maxn = 2e5 + 5;
           ^~~~
flood.cpp:88:5: error: redefinition of 'int n'
 int n , m;
     ^
flood.cpp:18:5: note: 'int n' previously declared here
 int n , m;
     ^
flood.cpp:88:9: error: redefinition of 'int m'
 int n , m;
         ^
flood.cpp:18:9: note: 'int m' previously declared here
 int n , m;
         ^
flood.cpp:89:14: error: redefinition of 'int d [200005][4]'
 int d[maxn][4];
              ^
flood.cpp:19:5: note: 'int d [200005][4]' previously declared here
 int d[maxn][4];
     ^
flood.cpp:90:10: error: redefinition of 'ii a [200005]'
 ii a[maxn];
          ^
flood.cpp:20:4: note: 'ii a [200005]' previously defined here
 ii a[maxn];
    ^
flood.cpp:91:13: error: redefinition of 'std::vector<int> res'
 vector<int> res;
             ^~~
flood.cpp:21:13: note: 'std::vector<int> res' previously declared here
 vector<int> res;
             ^~~
flood.cpp:92:10: error: redefinition of 'ii b [200005]'
 ii b[maxn];
          ^
flood.cpp:22:4: note: 'ii b [200005]' previously defined here
 ii b[maxn];
    ^
flood.cpp: In function 'int dir(int, int)':
flood.cpp:94:5: error: redefinition of 'int dir(int, int)'
 int dir(int x , int y){
     ^~~
flood.cpp:24:5: note: 'int dir(int, int)' previously defined here
 int dir(int x , int y){
     ^~~
flood.cpp: At global scope:
flood.cpp:99:14: error: redefinition of 'bool vis [200005]'
 bool vis[maxn];
              ^
flood.cpp:29:6: note: 'bool vis [200005]' previously declared here
 bool vis[maxn];
      ^~~
flood.cpp: In function 'int dfs(int, int)':
flood.cpp:101:5: error: redefinition of 'int dfs(int, int)'
 int dfs(int u , int dir){
     ^~~
flood.cpp:31:5: note: 'int dfs(int, int)' previously defined here
 int dfs(int u , int dir){
     ^~~
flood.cpp: In function 'int main()':
flood.cpp:120:5: error: redefinition of 'int main()'
 int main()
     ^~~~
flood.cpp:50:5: note: 'int main()' previously defined here
 int main()
     ^~~~
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);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
flood.cpp: In function 'int main()':
flood.cpp:125: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:126: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);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~