QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#397945 | #3756. 字典序 | SamponYW# | RE | 0ms | 0kb | C++14 | 1.9kb | 2024-04-24 20:34:12 | 2024-04-24 20:34:13 |
Judging History
answer
#include <bits/stdc++.h>
#define db double
#define il inline
#define re register
#define ll long long
#define ui unsigned
#define ull ui ll
#define i128 __int128
#define pii pair<int, int>
#define fi first
#define se second
#define eb emplace_back
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define mems(v, x) memset(v, x, sizeof(v))
#define memc(a, b) memcpy(a, b, sizeof(a))
#define FOR(i, L, R) for(re int i = (L); i <= (R); ++i)
#define ROF(i, R, L) for(re int i = (R); i >= (L); --i)
#define LS i << 1, l, mid
#define RS i << 1 | 1, mid + 1, r
#define popc(x) __builtin_popcount(x)
using namespace std;
#define N 2005
#define P 1000000007
il int add(int x, int y) {return x + y < P ? x + y : x + y - P;}
il void addr(int &x, int y) {(x += y) >= P && (x -= P);}
il int qpow(int p, int n = P - 2) {
int s = 1;
while(n) {
if(n & 1) s = 1ll * s * p % P;
p = 1ll * p * p % P, n >>= 1;
}
return s;
}
int n, m, a[N][N], cnt[N], ans[N];
vector<int> p[N]; bool u[N];
il void WORK() {
FOR(i, 1, n) {
FOR(j, 1, m) cin >> a[i][j];
vector<int>().swap(p[i]), u[i] = 0;
}
priority_queue<int, vector<int>, greater<int>> Q;
FOR(i, 1, m) {
cnt[i] = 0;
FOR(j, 1, n - 1) if(a[j][i] > a[j + 1][i])
++cnt[i], p[j].eb(i);
if(!cnt[i]) Q.emplace(i);
}
FOR(i, 1, m) {
// cerr << i << "\n";
if(Q.empty()) {cout << "-1\n"; return ;}
int x = Q.top(); ans[i] = x, Q.pop();
FOR(i, 1, n - 1) if(!u[i] && a[i][x] < a[i + 1][x]) {
u[i] = 1; for(auto j : p[i]) if(!--cnt[j]) Q.emplace(j);
}
}
FOR(i, 1, m) cout << ans[i] << " \n"[i == m];
}
int main() {
freopen("1.txt", "r", stdin);
freopen("2.txt", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
while(cin >> n >> m) WORK();
cerr << 1.0 * clock() / CLOCKS_PER_SEC;
return 0;
}
詳細信息
Test #1:
score: 0
Dangerous Syscalls
input:
8 3 6 1 2 3 2 2 7 2 2 7 2 2 7 2 2 9 2 2 10 2 2 4 10 2 6 2 3 1 3 4 3 4 3 7 3 7 3 8 7 7 1 3 3 2 6 3 3 1 3 3 2 6 3 3 1 3 3 2 6 3 3 6 3 3 2 1 4 3 6 3 3 2 4 4 3 7 2 4 2 4 10 6 7 3 4 10 4 3 3 4 3 2 3 9 2 4 9 2 4 9 2 4 9 8 10 9 6 6 3 6 10 1 8 2 5 9 6 6 3 6 10 1 9 2 5 5 3 8 6 7 2 1 7 2 10 5 10 8 7 4 7 1 4 8...