QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#433582 | #8786. The Whole World | ucup-team159# | WA | 5ms | 3912kb | C++23 | 5.7kb | 2024-06-08 12:51:25 | 2024-06-08 12:51:26 |
Judging History
answer
#line 1 "F.cpp"
// #pragma GCC target("avx2,avx512f,avx512vl,avx512bw,avx512dq,avx512cd,avx512vbmi,avx512vbmi2,avx512vpopcntdq,avx512bitalg,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("Ofast")
#line 2 "/mnt/c/Users/tsigm/Documents/Cprogram/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb push_back
#define eb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> bool chmax(T& x, U y){
if(x<y){ x=y; return true; }
return false;
}
template<class T,class U> bool chmin(T& x, U y){
if(y<x){ x=y; return true; }
return false;
}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class T> int lwb(const V<T>& v, const T& a){return lower_bound(all(v),a) - v.begin();}
template<class T>
V<T> Vec(size_t a) {
return V<T>(a);
}
template<class T, class... Ts>
auto Vec(size_t a, Ts... ts) {
return V<decltype(Vec<T>(ts...))>(a, Vec<T>(ts...));
}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
o<<"{";
for(const T& v:vc) o<<v<<",";
o<<"}";
return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }
#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
os<<t<<" ~ ";
dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {"; \
for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif
template<class D> D divFloor(D a, D b){
return a / b - (((a ^ b) < 0 && a % b != 0) ? 1 : 0);
}
template<class D> D divCeil(D a, D b) {
return a / b + (((a ^ b) > 0 && a % b != 0) ? 1 : 0);
}
/*
x 0 1 2 3 4 5 6 7 8 9
bsr(x) -1 0 1 1 2 2 2 2 3 3
最上位bit
*/
int bsr(int x){
return x == 0 ? -1 : 31 ^ __builtin_clz(x);
}
int bsr(uint x){
return x == 0 ? -1 : 31 ^ __builtin_clz(x);
}
int bsr(ll x){
return x == 0 ? -1 : 63 ^ __builtin_clzll(x);
}
int bsr(ull x){
return x == 0 ? -1 : 63 ^ __builtin_clzll(x);
}
/*
x 0 1 2 3 4 5 6 7 8 9
bsl(x) -1 0 1 0 2 0 1 0 3 0
最下位bit
*/
int bsl(int x){
if(x==0) return -1;
return __builtin_ctz(x);
}
int bsl(uint x){
if(x==0) return -1;
return __builtin_ctz(x);
}
int bsl(ll x){
if(x==0) return -1;
return __builtin_ctzll(x);
}
int bsl(ull x){
if(x==0) return -1;
return __builtin_ctzll(x);
}
template<class T>
T rnd(T l,T r){ //[l,r)
using D = uniform_int_distribution<T>;
static random_device rd;
static mt19937 gen(rd());
return D(l,r-1)(gen);
}
template<class T>
T rnd(T n){ //[0,n)
return rnd(T(0),n);
}
#line 5 "F.cpp"
using Int = __int128;
istream& operator>>(istream& i, Int& x){
x=0;
string s;
i>>s;
int N=s.size(),it=0;
if(s[0]=='-') it++;
for(;it<N;it++) x=(x*10+s[it]-'0');
if(s[0]=='-') x=-x;
return i;
}
ostream& operator<<(ostream& o, const Int& x){
Int tmp=x;
if(tmp==0) return o<<0;
if(tmp<0) o<<'-',tmp=-tmp;
vector<int> ds;
while(tmp) ds.pb(tmp%10),tmp/=10;
reverse(all(ds));
for(int d:ds) o<<d;
return o;
}
Int C(Int x,int i){
Int res = 1;
rep(j,i){
res *= x-j;
res /= j+1;
}
return res;
}
bool has_int_solution(vector<vector<Int>> A, vector<Int> b){
assert(si(A) == si(b));
int M = si(A);
if(M == 0) return true;
int N = si(A[0]);
auto Swap = [&](int i, int j){
rep(k,M) swap(A[k][i],A[k][j]);
};
auto sub = [&](int i, int j, Int c){
// A[*][i] -= A[*][j] * c
assert(i != j);
rep(k,M) A[k][i] -= A[k][j] * c;
};
auto flip = [&](int i){
// A[*][i] *= -1
rep(k,M) A[k][i] = -A[k][i];
};
{
int non0 = -1;
rep(i,N) if(A[0][i] != 0) non0 = i;
if(non0 == -1){
if(b[0] != 0) return false;
vector<vector<Int>> AA(M-1,vector<Int>(N));
rep(i,M-1) rep(j,N) AA[i][j] = A[i+1][j];
vector<Int> bb(M-1);
rep(i,M-1) bb[i] = b[i+1];
return has_int_solution(AA,bb);
}
Swap(0,non0);
assert(A[0][0] != 0);
}
rep(i,N) if(A[0][i] < 0) flip(i);
for(int i=1;i<N;i++){
while(A[0][i] != 0){
if(A[0][0] < A[0][i]){
Swap(0,i); continue;
}
Int q = A[0][0]/A[0][i];
sub(0,i,q);
}
}
if(b[0]%A[0][0] != 0) return false;
Int q = b[0]/A[0][0];
vector<vector<Int>> AA(M-1,vector<Int>(N-1));
rep(k,M-1) rep(i,N-1) AA[k][i] = A[k+1][i+1];
vector<Int> bb(M-1);
rep(k,M-1) bb[k] = b[k+1] - q * A[k+1][0];
return has_int_solution(AA,bb);
}
int solve(){
int M; cin >> M;
vector<Int> xs(M), ys(M);
rep(i,M) cin >> xs[i] >> ys[i];
for(int D=0;;D++){
show(D);
int N = D+1;
vector<vector<Int>> A(M,vector<Int>(N));
vector<Int> b = ys;
rep(i,M){
rep(j,N){
A[i][j] = C(xs[i],j);
}
}
if(has_int_solution(A,b)){
return D;
}
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false); //DON'T USE scanf/printf/puts !!
cout << fixed << setprecision(20);
int T; cin >> T;
while(T--) cout << solve() << endl;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3608kb
input:
2 2 1 0 4 1 3 1 1 4 4 6 6
output:
3 1
result:
ok 2 number(s): "3 1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3536kb
input:
2 2 1 0 4 1 3 1 0 3 0 5 4
output:
3 3
result:
ok 2 number(s): "3 3"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3608kb
input:
2 10 1 557 2 -172 3 -497 5 763 6 -149 7 -355 8 -29 9 -588 10 -171 11 -355 10 1 -461 2 -219 3 -45 4 -212 5 749 6 -294 9 -85 10 213 11 -412 12 125
output:
10 11
result:
ok 2 number(s): "10 11"
Test #4:
score: -100
Wrong Answer
time: 5ms
memory: 3912kb
input:
20 10 1 -193165761 4 426322868 5 -408198139 7 -455731045 9 -389028341 17 -590246653 18 119481348 21 809814532 23 47591392 26 -21020402 10 3 -715116939 5 -263142266 6 -426687860 10 342227448 14 141724722 15 576758779 18 123410194 19 256532828 20 -223524833 25 386574889 10 5 34943085 7 238431559 9 168...
output:
20 16 17 17 10 19 17 19 23 16 16 19 26 17 18 17 29 16 17 12
result:
wrong answer 1st numbers differ - expected: '25', found: '20'