Submission #937853

#TimeUsernameProblemLanguageResultExecution timeMemory
937853antonCell Automaton (JOI23_cell)C++17
24 / 100
8087 ms148672 KiB
#include<bits/stdc++.h>

using namespace std;
#define int long long
#define pii pair<int, int>
pii delta[4] ={{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

vector<pii> find_adj(pii pos){
    vector<pii> res;
    for(int i = 0; i<4; i++){
        res.push_back({pos.first+delta[i].first, pos.second + delta[i].second});
    }
    return res;
}

map<pii, int> next(map<pii, int> cur){
    map<pii, int> res;
    for(auto e: cur){
        if(e.second >0){
            res[e.first] =e.second-1;
        }
    }

    for(auto e: cur){
        if(e.second ==2){
            for(auto ee: find_adj(e.first)){
                if(res.find(ee)==res.end()){
                    res[ee] = 2;
                }
            }
        }
    }
    return res;
}
const int sz= 10;

void display(map<pii, int>&m){
    for(int i = -sz; i<=sz; i++){
        for(int j = -sz; j<=sz; j++){
            if(m.find({i, j})!=m.end()){
                cout<<m[{i, j}];
            }
            else{
                cout<<"0";
            }
        }
        cout<<endl;
    }
    cout<<endl;
}

signed main(){
    int n, q;
    cin>>n>>q;



    vector<int> pos;
    map<pii, int> cur;
    bool diag= true;
    for(int i = 0; i<n; i++){
        int x, y;
        cin>>x>>y;
        pos.push_back(x);
        cur[{x, y}] = 2;
        if(x!=y){
            diag= false;
        }
    }

    if(diag){
        sort(pos.begin(), pos.end());

        for(int i = 0; i<q; i++){
            int t;
            cin>>t;
            vector<pii> groups;
            
            if(t==0){
                cout<<pos.size()<<endl;
                continue;
            }
            int r= 0;
            pii cur_g = {pos[0], pos[0]};
            for(int j = 1; j<n; j++){
                if(pos[j]-pos[j-1]<=t){
                    if(pos[j]-pos[j-1]==t){
                        r+=t-1;
                    }
                    cur_g.second= pos[j];

                }
                else{
                    groups.push_back(cur_g);
                    cur_g ={pos[j], pos[j]};
                }
            }
            groups.push_back(cur_g);
            for(auto e: groups){
                //cout<<e.first<<" "<<e.second<<endl;
                r+= 2*(e.second-e.first+t+1);
                r+= 2*(t-1);
            }

            cout<<r<<endl;  
        }
    }
    else{
        vector<int> ans(1000+1, -1);
        int r;

        for(int steps=  0; steps<1000+1; steps++){
            r=0;
            for(auto e: cur){
                if(e.second ==2){
                    r++;
                }
            }
            ans[steps] = r;
            cur = next(cur);
        }
        int max_s= 0;
        for(int i = 0; i<q; i++){
            int steps= 0;
            cin>>steps;
            cout<<ans[steps]<<endl;
        }
    }
    
}

Compilation message (stderr)

cell.cpp: In function 'int main()':
cell.cpp:122:13: warning: unused variable 'max_s' [-Wunused-variable]
  122 |         int max_s= 0;
      |             ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...