QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#66062#5112. Where Am I?bili2002#RE 0ms0kbC++175.6kb2022-12-06 03:25:092022-12-06 03:25:10

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-06 03:25:10]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2022-12-06 03:25:09]
  • 提交

answer

#include <bits/stdc++.h>
#define f first
#define s second
#define sz(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back

using namespace std;
using ll = long long;

template<class T, class T2> inline bool chkmax(T &x, const T2 & y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 & y) { return x > y ? x = y, 1 : 0; }
template<class T, class T2> inline istream &operator>>(istream &is,       pair<T, T2> &p)             { is>>p.f>>p.s;        return is; }
template<class T, class T2> inline ostream &operator<<(ostream &os, const pair<T, T2> &p)             { os<<p.f<<' '<<p.s;   return os; }
template<class T>           inline istream &operator>>(istream &is,       vector<T> &v)               { for (auto &id : v)   is>>id;       return is; }
template<class T>           inline ostream &operator<<(ostream &os, const vector<T> &v)               { for (auto id : v)    os<<id<<' ';  return os; }
template<class T, class T2> inline ostream &operator<<(ostream &os, const map<T, T2> &m)              { for (auto id : m)    os<<id<<'\n'; return os; }
template<class T, class T2> inline ostream &operator<<(ostream &os, const unordered_map<T, T2> &um)   { for (auto id : um)   os<<id<<'\n'; return os; }
template<class T>           inline ostream &operator<<(ostream &os, const list<T> &l)                 { for (auto id : l)    os<<id<<' ';  return os; }
template<class T>           inline ostream &operator<<(ostream &os, const set<T> &s)                  { for (auto id : s)    os<<id<<' ';  return os; }
template<class T>           inline ostream &operator<<(ostream &os, const unordered_set<T> &us)       { for (auto id : us)   os<<id<<' ';  return os; }
const long long INF = 1e18;
const bool hasTests = 0;

int n, m;
struct coordi {
    int x, y;
};
vector<coordi> coor;

void input() {
    cin>>m>>n;

    char c;
    for (int j=1; j<=n; j++) {
        for (int i=1; i<=m; i++) {
            cin>>c;
            if (c == 'X') {
                coor.pb({j, i});
            }
        }
    }
}

double ansMean;
int maxx;
vector<pair<int, int>> mxV;

void output() {
    cout<<fixed<<setprecision(3)<<ansMean<<endl;
    cout<<maxx<<endl;
    for (auto& curr : mxV) {
        cout<<'('<<curr.f<<','<<curr.s<<") ";
    }
    cout<<endl;
}

const int MAXN = 420;
int grid[MAXN][MAXN];

void calcGrid() {
    int cnt = 1;
    int step = 2;
    int x = MAXN/2 - 1, y = MAXN/2;

    while (x > 0) {
        for (int i=0; i<step-1; i++) {
            grid[x][y++] = cnt++;
        }
        for (int i=0; i<step; i++) {
            grid[x++][y] = cnt++;
        }
        for (int i=0; i<step; i++) {
            grid[x][y--] = cnt++;
        }
        for (int i=0; i<step+1; i++) {
            grid[x--][y] = cnt++;
        }
        step += 2;
    }

    /*for (int i=0; i<MAXN; i++) {
        for (int j=0; j<MAXN; j++) {
            cerr<<grid[i][j]<<' ';
        }
        cerr<<'\n';
    }*/
}

const int mean = MAXN / 2;
vector<int> xs[MAXN][MAXN];
int ans[MAXN][MAXN];
int cmp;

struct csort {
    bool operator()(const pair<int, int>& l, const pair<int, int>& r) {
        return xs[l.f][l.s][cmp] < xs[r.f][r.s][cmp];
    }
};

struct csort2 {
    bool operator()(const pair<int, int>& l, const pair<int, int>& r) {
        if (l.s == r.s) {
            return l.f < r.s;
        }
        return l.s < r.s;
    }
};

void func(vector<pair<int, int>>& pairs, int num) {
    cmp = num;
    sort(all(pairs), csort());
    //cerr<<num<<"  -  "<<pairs<<endl;

    vector<pair<int, int>> nowIn;
    for (auto& curr : pairs) {
        if (nowIn.empty()) {
            nowIn.pb(curr);
        } else if (xs[nowIn[0].f][nowIn[0].s][num] == xs[curr.f][curr.s][num]) {
            nowIn.pb(curr);
        } else if (nowIn.size() == 1) {
            ans[nowIn[0].f][nowIn[0].s] = xs[nowIn[0].f][nowIn[0].s][num];
            nowIn.clear();
            nowIn.pb(curr);
        } else {
            func(nowIn, num+1);
            nowIn.clear();
            nowIn.pb(curr);
        }
    }

    if (nowIn.size() == 1) {
        ans[nowIn[0].f][nowIn[0].s] = xs[pairs[pairs.size()-2].f][pairs[pairs.size()-2].s][num];
    } else {
        func(nowIn, num+1);
    }
}

void solve() {
    calcGrid();

    for (int i=1; i<=n; i++) {
        for (int j=1; j<=m; j++) {
            for (auto& curr : coor) {
                xs[i][j].pb(grid[mean - i + curr.x][mean - j + curr.y]);
            }
            sort(all(xs[i][j]));
        }
    }

    vector<pair<int, int>> pairs;
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=m; j++) {
            pairs.pb({i, j});
        }
    }

    func(pairs, 0);

    for (int i=1; i<=n; i++) {
        for (int j=1; j<=m; j++) {
            //cerr<<ans[i][j]<<' ';
            ansMean += ans[i][j];
            if (maxx < ans[i][j]) {
                mxV.clear();
                maxx = ans[i][j];
                mxV.pb({j, n - i + 1});
            } else if (maxx == ans[i][j]) {
                mxV.pb({j, n - i + 1});
            }
        }
        //cerr<<endl;
    }

    sort(all(mxV), csort2());

    ansMean = ansMean / (n*m);
}

void start() {
    int t = 1;
    if (hasTests) {
        cin>>t;
    }

    for (int i=1; i<=t; i++) {
        input();
        solve();
        //cout<<"Case #"<<i<<": ";
        output();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    start();
    return 0;
}

/*
2 2
..
X.
*/



详细

Test #1:

score: 0
Runtime Error

input:

1 1
X

output:


result: