QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#140717#5154. ETAGamal74#WA 10ms3592kbC++202.3kb2023-08-16 17:52:382023-08-16 17:52:42

Judging History

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

  • [2023-08-16 17:52:42]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:3592kb
  • [2023-08-16 17:52:38]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define fi first
#define se second
#define pp push_back
#define all(x) (x).begin(), (x).end()
#define Ones(n) __builtin_popcount(n)
#define endl '\n'
#define mem(arrr, xx) memset(arrr,xx,sizeof arrr)
#define PI acos(-1)
//#define int long long
#define debug(x) cout << (#x) << " = " << x << endl

void Gamal() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef Clion
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#endif
}

int dx[] = {+0, +0, -1, +1, +1, +1, -1, -1};
int dy[] = {-1, +1, +0, +0, +1, -1, +1, -1};

const double EPS = 1e-9;
const ll OO = 0X3F3F3F3F3F3F3F3F;
const int N = 1e6, INF = INT_MAX, MOD = 1e9 + 7, LOG = 20;


void solve() {
    char c;
    int a,b;cin >> a >> c >> b;
    for (int n = 2; n <= N; ++n) {
        ll tot = 1ll * n * a;
        if(tot % b)continue;
        tot /= b;
        int l = 1,r = n;
        while (l <= r){
            int mid = (l + r)/2;
            int rem = n - mid;
            ll dis = 1ll * mid * (mid - 1)/2;
            ll mn = rem, mx = 1ll * rem * mid;
            if(dis > tot){
                r = mid - 1;
                continue;
            }
            ll lft = tot - dis;
            if(lft < mn){
                r = mid - 1;
            }
            else if(lft > mx){
                l = mid + 1;
            }
            else{
                cout << n << ' ' << n - 1 << endl;
                for (int i = n; i >= n - mid + 2; --i) {
                    cout << i << ' ' << i - 1 << endl;
                }
                tot -= dis;
                int score = mid,cur = n - mid + 1;
                for (int i = n - mid; i >= 1; --i) {
                    int cnt = i - 1;
                    while (tot - score < cnt)score--,cur++;
                    cout << i << " " << cur << endl;
                    tot -= score;
                }
                return;
            }
        }
    }
    cout << "impossible";
}


signed main() {
    Gamal();
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3532kb

input:

1/2

output:

2 1
1 2

result:

ok 

Test #2:

score: 0
Accepted
time: 10ms
memory: 3592kb

input:

1/3

output:

impossible

result:

ok 

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3480kb

input:

7/4

output:

8 7
8 7
7 6
6 5
4 5
3 7
2 8
1 8

result:

FAIL Wrong average distance, got 20/8, wanted 7/4