Submission #373966

# Submission time Handle Problem Language Result Execution time Memory
373966 2021-03-06T10:00:38 Z FEDIKUS Game (eJOI20_game) C++17
20 / 100
1 ms 364 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define xx first
#define yy second

using namespace std;

typedef pair<int,int> pii;

set<pair<pii,pii> > nesto;

bool bio[21][21];
int n,m;
int vel;

inline pair<pii,pii> srt(pii a,pii b){
    return mp(min(a,b),max(a,b));
}

inline bool moze(int x,int y){
    if(x<0 || x>=n || y<0 || y>=m) return false;
    return true;
}

void dfs(int y,int x){
    if(bio[y][x]) return;
    bio[y][x]=true;
    vel++;
    //cout<<x<<" "<<y<<" "<<vel<<"\n";
    if(moze(y,x+1) && nesto.find(srt(mp(x+1,y),mp(x+1,y+1)))==nesto.end()) dfs(y,x+1);
    if(moze(y,x-1) && nesto.find(srt(mp(x,y),mp(x,y+1)))==nesto.end()) dfs(y,x-1);
    if(moze(y+1,x) && nesto.find(srt(mp(x,y+1),mp(x+1,y+1)))==nesto.end()) dfs(y+1,x);
    if(moze(y-1,x) && nesto.find(srt(mp(x,y),mp(x+1,y)))==nesto.end()) dfs(y-1,x);
}

pii rek(int mask,int ko,vector<int> &velicine){
    int raz=INT_MIN;
    pii ret={0,0};
    for(int i=0;i<velicine.size();i++){
        if(mask&(1<<i)) continue;
        pii nesto=rek(mask|(1<<i),ko,velicine);
        if(nesto.yy-nesto.xx-velicine[i]>raz) raz=nesto.yy-nesto.xx-velicine[i];
        if(raz==nesto.yy-nesto.xx-velicine[i]) ret=mp(nesto.yy,nesto.xx+velicine[i]);
    }
    return ret;
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n+1;i++){
        for(int j=0;j<m;j++){
            char a;
            cin>>a;
            if(a=='1'){
                nesto.emplace(srt(mp(j,i),mp(j+1,i)));
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m+1;j++){
            char a;
            cin>>a;
            if(a=='1'){
                nesto.emplace(srt(mp(j,i),mp(j,i+1)));
            }
        }
    }
    //for(auto i:nesto){
    //    cout<<i.xx.xx<<" "<<i.xx.yy<<" "<<i.yy.xx<<" "<<i.yy.yy<<"\n";
    //}
    vector<int> velicine;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            vel=0;
            if(!bio[i][j]){
                dfs(i,j);
                if(vel==1){
                    int koliko=0;
                    if(nesto.find(srt(mp(j+1,i),mp(j+1,i+1)))==nesto.end()) koliko++;
                    if(nesto.find(srt(mp(j,i),mp(j,i+1)))==nesto.end()) koliko++;
                    if(nesto.find(srt(mp(j,i+1),mp(j+1,i+1)))==nesto.end()) koliko++;
                    if(nesto.find(srt(mp(j,i),mp(j+1,i)))==nesto.end()) koliko++;
                    if(koliko==0) continue;
                }
                velicine.pb(vel);
            }
        }
    }
    sort(velicine.begin(),velicine.end());
    //for(int i:velicine) cout<<i<<" ";
    //if(velicine.size()>2) return -1;
    int druga=0;
    int prva=0;
    //cout<<rek(0,1,velicine).xx-rek(0,1,velicine).yy<<"\n";
    for(int i=0;i<velicine.size();i++){
        if(i&1){
            prva+=velicine[i];
        }else druga+=velicine[i];
    }
    //cout<<prva<<" "<<druga<<" ";
    cout<<prva-druga;
    return 0;
}

Compilation message

game.cpp: In function 'pii rek(int, int, std::vector<int>&)':
game.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=0;i<velicine.size();i++){
      |                 ~^~~~~~~~~~~~~~~~
game.cpp: In function 'int main()':
game.cpp:97:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |     for(int i=0;i<velicine.size();i++){
      |                 ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Incorrect 1 ms 364 KB Output isn't correct
14 Halted 0 ms 0 KB -